8000 Support IP version by KeCheng2022 · Pull Request #460 · tinyproxy/tinyproxy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support IP version #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion etc/tinyproxy.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,11 @@ ViaProxyName "tinyproxy"
#
#ReverseBaseURL "http://localhost:8888/"


#
# IP version supported by Tinyproxy
# ipv4 : ignore IPv6 addresses in DNS response
# ipv6 : ignore IPv4 addresses in DNS response
# any : accept both IPv4 and IPv6 addresses in DNS response
#
IPversion any

3 changes: 2 additions & 1 deletion src/conf-tokens.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ config_directive_find (register const char *str, register size_t len)
{"logfile", CD_logfile},
{"basicauth", CD_basicauth},
{"addheader", CD_addheader},
{"maxrequestsperchild", CD_maxrequestsperchild}
{"maxrequestsperchild", CD_maxrequestsperchild},
{"ipversion", CD_ipversion},
};

for(i=0;i<sizeof(wordlist)/sizeof(wordlist[0]);++i) {
Expand Down
1 change: 1 addition & 0 deletions src/conf-tokens.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ reversemagic, CD_reversemagic
reversepath, CD_reversepath
upstream, CD_upstream
loglevel, CD_loglevel
ipversion, CD_ipversion
%%

1 change: 1 addition & 0 deletions src/conf-tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ CD_reversemagic,
CD_reversepath,
CD_upstream,
CD_loglevel,
CD_ipversion
};

struct config_directive_entry { const char* name; enum config_directive value; };
Expand Down
33 changes: 32 additions & 1 deletion src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ static HANDLE_FUNC (handle_viaproxyname);
static HANDLE_FUNC (handle_disableviaheader);
static HANDLE_FUNC (handle_xtinyproxy);

static HANDLE_FUNC (handle_ipversion);

#ifdef UPSTREAM_SUPPORT
static HANDLE_FUNC (handle_upstream);
#endif
Expand Down Expand Up @@ -254,7 +256,8 @@ struct {
#endif
/* loglevel */
STDCONF (loglevel, "(critical|error|warning|notice|connect|info)",
handle_loglevel)
handle_loglevel),
STDCONF (ipversion, "(ipv4|ipv6|any)", handle_ipversion)
};

const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]);
Expand Down Expand Up @@ -932,6 +935,34 @@ static HANDLE_FUNC (handle_loglevel)
return -1;
}

struct ip_version_s {
const char *string;
enum ip_version_e ipversion;
};
static struct ip_version_s ip_version[] = {
{"ipv4", IPv4_Only},
{"ipv6", IPv6_Only},
{"any", IP_Any}
};
static HANDLE_FUNC (handle_ipversion)
{
static const unsigned int nips =
sizeof (ip_version) / sizeof (ip_version[0]);
unsigned int i;
char *arg = get_string_arg (line, &match[2]);
for (i = 0; i != nips; ++i) {
if (!strcasecmp (arg, ip_version[i].string)) {
conf->ipversion = ip_version[i].ipversion;
safefree (arg);
return 0;
}
}

safefree (arg);

return -1;
}

static HANDLE_FUNC (handle_basicauth)
{
char *user, *pass;
Expand Down
7 changes: 7 additions & 0 deletions src/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ typedef struct {
char *value;
} http_header_t;

enum ip_version_e {
IPv4_Only = 0,
IPv6_Only,
IP_Any
};

/*
* Hold all the configuration time information.
*/
Expand Down Expand Up @@ -68,6 +74,7 @@ struct config_s {
unsigned int idletimeout;
sblist *bind_addrs;
unsigned int bindsame;
enum ip_version_e ipversion;

/*
* The configured name to use in the HTTP "Via" header field.
Expand Down
9 changes: 8 additions & 1 deletion src/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ int opensock (const char *host, int port, const char *bind_to)
"opensock: opening connection to %s:%d", host, port);

memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC;
log_message(LOG_INFO, "opensock: ipversion: %d", config->ipversion);
if (config->ipversion == IPv4_Only) {
hints.ai_family = AF_INET;
} else if (config->ipversion == IPv6_Only) {
hints.ai_family = AF_INET6;
} else {
hints.ai_family = AF_UNSPEC;
}
hints.ai_socktype = SOCK_STREAM;

snprintf (portstr, sizeof (portstr), "%d", port);
Expand Down
0