Skip to content

Commit 2bec15e

Browse files
Allow configuring IPv6 address for upstream proxy (#492)
* Added support to configure IPv6 upstream proxy servers using bracket syntax. * Added regular expression for IPv6 scope identifier to re for IPv6 address.
1 parent ef60434 commit 2bec15e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/conf.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@
6666
#define PASSWORD "([^@]*)"
6767
#define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})"
6868
#define IPMASK "(" IP "(/" DIGIT "+)?)"
69+
#define IPV6SCOPE "((%[^ \t\\/]{1,16})?)"
6970
#define IPV6 "(" \
70-
"(([0-9a-f:]{2,39}))|" \
71-
"(([0-9a-f:]{0,29}:" IP "))" \
71+
"([0-9a-f:]{2,39})" IPV6SCOPE "|" \
72+
"([0-9a-f:]{0,29}:" IP ")" IPV6SCOPE \
7273
")"
7374

7475
#define IPV6MASK "(" IPV6 "(/" DIGIT "+)?)"
@@ -80,7 +81,7 @@
8081
* number. Given the usual structure of the configuration file, sixteen
8182
* substring matches should be plenty.
8283
*/
83-
#define RE_MAX_MATCHES 24
84+
#define RE_MAX_MATCHES 33
8485

8586
#define CP_WARN(FMT, ...) \
8687
log_message (LOG_WARNING, "line %lu: " FMT, lineno, __VA_ARGS__)
@@ -249,7 +250,7 @@ struct {
249250
"(" "(none)" WS STR ")|" \
250251
"(" "(http|socks4|socks5)" WS \
251252
"(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?"
252-
"(" IP "|" ALNUM ")"
253+
"(" IP "|" "\\[(" IPV6 ")\\]" "|" ALNUM ")"
253254
":" INT "(" WS STR ")?" ")", handle_upstream),
254255
#endif
255256
/* loglevel */
@@ -1114,10 +1115,13 @@ static HANDLE_FUNC (handle_upstream)
11141115
pass = get_string_arg (line, &match[mi]);
11151116
mi++;
11161117

1117-
ip = get_string_arg (line, &match[mi]);
1118+
if (match[mi+4].rm_so != -1) /* IPv6 address in square brackets */
1119+
ip = get_string_arg (line, &match[mi+4]);
1120+
else
1121+
ip = get_string_arg (line, &match[mi]);
11181122
if (!ip)
11191123
return -1;
1120-
mi += 5;
1124+
mi += 16;
11211125

11221126
port = (int) get_long_arg (line, &match[mi]);
11231127
mi += 3;

0 commit comments

Comments
 (0)