diff --git a/etc/tinyproxy.conf.in b/etc/tinyproxy.conf.in index d268709..b807b16 100644 --- a/etc/tinyproxy.conf.in +++ b/etc/tinyproxy.conf.in @@ -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 diff --git a/src/conf-tokens.c b/src/conf-tokens.c index 2a1ddbe..2b8befe 100644 --- a/src/conf-tokens.c +++ b/src/conf-tokens.c @@ -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;iipversion = ip_version[i].ipversion; + safefree (arg); + return 0; + } + } + + safefree (arg); + + return -1; +} + static HANDLE_FUNC (handle_basicauth) { char *user, *pass; diff --git a/src/conf.h b/src/conf.h index 0a0f06f..9d37afd 100644 --- a/src/conf.h +++ b/src/conf.h @@ -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. */ @@ -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. diff --git a/src/sock.c b/src/sock.c index b3b0920..e2628b9 100644 --- a/src/sock.c +++ b/src/sock.c @@ -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);