Skip to content

Commit 98060c0

Browse files
committed
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
1 parent 3764b85 commit 98060c0

File tree

7 files changed

+58
-4
lines changed

7 files changed

+58
-4
lines changed

etc/tinyproxy.conf.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,5 +321,11 @@ ViaProxyName "tinyproxy"
321321
#
322322
#ReverseBaseURL "http://localhost:8888/"
323323

324-
324+
#
325+
# IP version supported by Tinyproxy
326+
# ipv4 : ignore IPv6 addresses in DNS response
327+
# ipv6 : ignore IPv4 addresses in DNS response
328+
# any : accept both IPv4 and IPv6 addresses in DNS response
329+
#
330+
IPversion ipv4
325331

src/conf-tokens.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ config_directive_find (register const char *str, register size_t len)
5858
{"logfile", CD_logfile},
5959
{"basicauth", CD_basicauth},
6060
{"addheader", CD_addheader},
61-
{"maxrequestsperchild", CD_maxrequestsperchild}
61+
{"maxrequestsperchild", CD_maxrequestsperchild},
62+
{"ipversion", CD_ipversion},
6263
};
6364

6465
for(i=0;i<sizeof(wordlist)/sizeof(wordlist[0]);++i) {

src/conf-tokens.gperf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ reversemagic, CD_reversemagic
5858
reversepath, CD_reversepath
5959
upstream, CD_upstream
6060
loglevel, CD_loglevel
61+
ipversion, CD_ipversion
6162
%%
6263

src/conf-tokens.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ CD_reversemagic,
4343
CD_reversepath,
4444
CD_upstream,
4545
CD_loglevel,
46+
CD_ipversion
4647
};
4748

4849
struct config_directive_entry { const char* name; enum config_directive value; };

src/conf.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ static HANDLE_FUNC (handle_viaproxyname);
161161
static HANDLE_FUNC (handle_disableviaheader);
162162
static HANDLE_FUNC (handle_xtinyproxy);
163163

164+
static HANDLE_FUNC (handle_ipversion);
165+
164166
#ifdef UPSTREAM_SUPPORT
165167
static HANDLE_FUNC (handle_upstream);
166168
#endif
@@ -254,7 +256,8 @@ struct {
254256
#endif
255257
/* loglevel */
256258
STDCONF (loglevel, "(critical|error|warning|notice|connect|info)",
257-
handle_loglevel)
259+
handle_loglevel),
260+
STDCONF (ipversion, "(ipv4|ipv6|any)", handle_ipversion)
258261
};
259262

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

938+
struct ip_version_s {
939+
const char *string;
940+
enum ip_version_e ipversion;
941+
};
942+
static struct ip_version_s ip_version[] = {
943+
{"ipv4", IPv4_Only},
944+
{"ipv6", IPv6_Only},
945+
{"any", IP_Any}
946+
};
947+
static HANDLE_FUNC (handle_ipversion)
948+
{
949+
static const unsigned int nips =
950+
sizeof (ip_version) / sizeof (ip_version[0]);
951+
unsigned int i;
952+
char *arg = get_string_arg (line, &match[2]);
953+
for (i = 0; i != nips; ++i) {
954+
if (!strcasecmp (arg, ip_version[i].string)) {
955+
conf->ipversion = ip_version[i].ipversion;
956+
safefree (arg);
957+
return 0;
958+
}
959+
}
960+
961+
safefree (arg);
962+
963+
return -1;
964+
}
965+
935966
static HANDLE_FUNC (handle_basicauth)
936967
{
937968
char *user, *pass;

src/conf.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ typedef struct {
3434
char *value;
3535
} http_header_t;
3636

37+
enum ip_version_e {
38+
IPv4_Only = 0,
39+
IPv6_Only,
40+
IP_Any
41+
};
42+
3743
/*
3844
* Hold all the configuration time information.
3945
*/
@@ -68,6 +74,7 @@ struct config_s {
6874
unsigned int idletimeout;
6975
sblist *bind_addrs;
7076
unsigned int bindsame;
77+
enum ip_version_e ipversion;
7178

7279
/*
7380
* The configured name to use in the HTTP "Via" header field.

src/sock.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ int opensock (const char *host, int port, const char *bind_to)
146146
"opensock: opening connection to %s:%d", host, port);
147147

148148
memset (&hints, 0, sizeof (struct addrinfo));
149-
hints.ai_family = AF_UNSPEC;
149+
log_message(LOG_INFO, "opensock: ipversion: %d", config->ipversion);
150+
if (config->ipversion == IPv4_Only) {
151+
hints.ai_family = AF_INET;
152+
} else if (config->ipversion == IPv6_Only) {
153+
hints.ai_family = AF_INET6;
154+
} else {
155+
hints.ai_family = AF_UNSPEC;
156+
}
150157
hints.ai_socktype = SOCK_STREAM;
151158

152159
snprintf (portstr, sizeof (portstr), "%d", port);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy