Skip to content
Merged
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
16 changes: 10 additions & 6 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@
#define PASSWORD "([^@]*)"
#define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})"
#define IPMASK "(" IP "(/" DIGIT "+)?)"
#define IPV6SCOPE "((%[^ \t\\/]{1,16})?)"
#define IPV6 "(" \
"(([0-9a-f:]{2,39}))|" \
"(([0-9a-f:]{0,29}:" IP "))" \
"([0-9a-f:]{2,39})" IPV6SCOPE "|" \
"([0-9a-f:]{0,29}:" IP ")" IPV6SCOPE \
")"

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

#define CP_WARN(FMT, ...) \
log_message (LOG_WARNING, "line %lu: " FMT, lineno, __VA_ARGS__)
Expand Down Expand Up @@ -249,7 +250,7 @@ struct {
"(" "(none)" WS STR ")|" \
"(" "(http|socks4|socks5)" WS \
"(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?"
"(" IP "|" ALNUM ")"
"(" IP "|" "\\[(" IPV6 ")\\]" "|" ALNUM ")"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other contexts where IPv6 is accepted, it is accepted without brackets around them; we should be consistent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i realized that the bracket syntax stems from the fact that the colon character used to separate ip from port can't properly be distinguished from the ones used inside the ipv6 literal. can you research whether upstream directive is the only spot where an ip:port pair is used ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPV6 addresses are accepted by listen, allow, deny, bind and upstream. upstream is the only direcdtive, that also allows to specify a port number.

The syntax using square brackes vor IPv6 adresses is taken from the URL syntax for numerical IPv6 adresses. I must admit, that it looks ugly to me, but I had no better idea. :-(

":" INT "(" WS STR ")?" ")", handle_upstream),
#endif
/* loglevel */
Expand Down Expand Up @@ -1114,10 +1115,13 @@ static HANDLE_FUNC (handle_upstream)
pass = get_string_arg (line, &match[mi]);
mi++;

ip = get_string_arg (line, &match[mi]);
if (match[mi+4].rm_so != -1) /* IPv6 address in square brackets */
ip = get_string_arg (line, &match[mi+4]);
else
ip = get_string_arg (line, &match[mi]);
if (!ip)
return -1;
mi += 5;
mi += 16;

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