diff options
author | David Goulet <dgoulet@torproject.org> | 2020-11-12 11:22:02 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2020-11-13 08:38:22 -0500 |
commit | d425dbf04a6bbac7eae832bf51c2bfe061e2c426 (patch) | |
tree | 3f598f329955ff14d40e9dcb7d11ee39997d2e05 /src/feature/relay/relay_config.c | |
parent | 46ccde66a97d7985388eb54bc74a025402fb0a19 (diff) | |
download | tor-d425dbf04a6bbac7eae832bf51c2bfe061e2c426.tar.gz tor-d425dbf04a6bbac7eae832bf51c2bfe061e2c426.zip |
port: Don't ignore ports of a different family
Commit c3a0f757964de0e8a24911d72abff5df20bb323c added this feature for ORPort
that we ignore any port that is not the family of our default address when
parsing the port. So if port_parse_config() was called with an IPv4 default
address, all IPv6 address would be ignored.
That makes sense for ORPort since we call twice port_parse_config() for
0.0.0.0 and [::] but for the rest of the ports, it is not good since a
perfectly valid configuration can be:
SocksPort 9050
SocksPort [::1]:9050
Any non-ORPort only binds by default to an IPv4 except the ORPort that binds
to both IPv4 and IPv6 by default.
The fix here is to always parse all ports within port_parse_config() and then,
specifically for ORPort, remove the duplicates or superseding ones. The
warning is only emitted when a port supersedes another.
A unit tests is added to make sure SocksPort of different family always exists
together.
Fixes #40183
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/relay/relay_config.c')
-rw-r--r-- | src/feature/relay/relay_config.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/feature/relay/relay_config.c b/src/feature/relay/relay_config.c index 6504c680eb..ea03f43e13 100644 --- a/src/feature/relay/relay_config.c +++ b/src/feature/relay/relay_config.c @@ -228,15 +228,16 @@ remove_duplicate_orports(smartlist_t *ports) continue; } /* Same address family and same port number, we have a match. */ - if (!current->explicit_addr && next->explicit_addr && - tor_addr_family(¤t->addr) == tor_addr_family(&next->addr) && + if (tor_addr_family(¤t->addr) == tor_addr_family(&next->addr) && current->port == next->port) { /* Remove current because next is explicitly set. */ removing[i] = true; - char *next_str = tor_strdup(describe_relay_port(next)); - log_warn(LD_CONFIG, "Configuration port %s superseded by %s", - describe_relay_port(current), next_str); - tor_free(next_str); + if (!current->explicit_addr && next->explicit_addr) { + char *next_str = tor_strdup(describe_relay_port(next)); + log_warn(LD_CONFIG, "Configuration port %s superseded by %s", + describe_relay_port(current), next_str); + tor_free(next_str); + } } } } |