Allow configureing IPv6 address for upstream proxy#492
Allow configureing IPv6 address for upstream proxy#492rofl0r merged 6 commits intotinyproxy:masterfrom
Conversation
| "(" "(http|socks4|socks5)" WS \ | ||
| "(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?" | ||
| "(" IP "|" ALNUM ")" | ||
| "(" IP "|" "\\[(" IPV6 ")\\]" "|" ALNUM ")" |
There was a problem hiding this comment.
in other contexts where IPv6 is accepted, it is accepted without brackets around them; we should be consistent
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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. :-(
src/conf.c
Outdated
| #define IPV6 "(" \ | ||
| "(([0-9a-f:]{2,39}))|" \ | ||
| "(([0-9a-f:]{0,29}:" IP "))" \ | ||
| "([0-9a-f:]{2,39})" IPV6_SCOPE "|" \ |
There was a problem hiding this comment.
won't removal of the outer parens pair break other uses of the regex ?
There was a problem hiding this comment.
The definition von IPV6 is used for listen, allow, deny, bind and upstream. handle_listen(), handle_allow(), handle_deny() and handle_bind() all use match[2], so the additional capture groups do not break these handlers.
Only handle_upstream() had to be changed, because the additional capture grups requred skipping more captures to get the port number.
I wish, standard regex would support non-capturing groups like perl.
src/conf.c
Outdated
| #define PASSWORD "([^@]*)" | ||
| #define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})" | ||
| #define IPMASK "(" IP "(/" DIGIT "+)?)" | ||
| #define IPV6_SCOPE "((%[^ \\t\\/]{1,16})?)" |
There was a problem hiding this comment.
\t does not need another backslash escape.
This is just a POSIX regular expression so it excludes a literal \ and t. A scope like %eth1 fails because of the t.
There was a problem hiding this comment.
Seems I did too much perl and my posix regex is a bit rusty.
src/conf.c
Outdated
| #define PASSWORD "([^@]*)" | ||
| #define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})" | ||
| #define IPMASK "(" IP "(/" DIGIT "+)?)" | ||
| #define IPV6_SCOPE "((%[^ \\t\\/]{1,16})?)" |
There was a problem hiding this comment.
Should this be named IPV6SCOPE without an underscore to follow the pattern of IPV6MASK?
|
@Mario-Klebsch thanks, merged. would you mind opening a PR that also updates the documentation (explaining bracket syntax for ipv6 upstream and scoping) ? |
This change allos to configure IPv6 addresses for upstream proxies,
Example:
upstream http [fe80::1]:8888