Skip to content

Conversation

@Mario-Klebsch
Copy link
Contributor

This change allos to configure IPv6 addresses for upstream proxies,

Example: upstream http [fe80::1]:8888

"(" "(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. :-(

src/conf.c Outdated
#define IPV6 "(" \
"(([0-9a-f:]{2,39}))|" \
"(([0-9a-f:]{0,29}:" IP "))" \
"([0-9a-f:]{2,39})" IPV6_SCOPE "|" \
Copy link
Contributor

Choose a reason for hiding this comment

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

won't removal of the outer parens pair break other uses of the regex ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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})?)"
Copy link
Contributor

Choose a reason for hiding this comment

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

\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.

Copy link
Contributor

Choose a reason for hiding this comment

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

good catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems I did too much perl and my posix regex is a bit rusty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 15c64e7

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})?)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be named IPV6SCOPE without an underscore to follow the pattern of IPV6MASK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 29a0bf9

@rofl0r rofl0r merged commit 2bec15e into tinyproxy:master May 23, 2023
@rofl0r
Copy link
Contributor

rofl0r commented May 23, 2023

@Mario-Klebsch thanks, merged. would you mind opening a PR that also updates the documentation (explaining bracket syntax for ipv6 upstream and scoping) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants