summaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2021-01-19 12:36:44 -0500
committerDavid Goulet <dgoulet@torproject.org>2021-01-19 13:07:49 -0500
commit9321ddf3a1cae9e8f0e59b368ff3c57aed5ac1a8 (patch)
tree2b08faca0c3cb3e74f6d4907fd8d34425da57d75 /src/app
parent938623004b025c5c85745703d817e33a5308da5a (diff)
downloadtor-9321ddf3a1cae9e8f0e59b368ff3c57aed5ac1a8.tar.gz
tor-9321ddf3a1cae9e8f0e59b368ff3c57aed5ac1a8.zip
config: Prioritize port with explicit address
When selecting the first advertised port, we always prefer the one with an explicit address. Closes #40246 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/app')
-rw-r--r--src/app/config/config.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/app/config/config.c b/src/app/config/config.c
index d8bc5f6025..7db5e5cfa8 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -6651,20 +6651,28 @@ get_first_listener_addrport_string(int listener_type)
static const port_cfg_t *
portconf_get_first_advertised(int listener_type, int address_family)
{
+ const port_cfg_t *first_port = NULL;
+ const port_cfg_t *first_port_explicit_addr = NULL;
+
if (address_family == AF_UNSPEC)
return NULL;
const smartlist_t *conf_ports = get_configured_ports();
SMARTLIST_FOREACH_BEGIN(conf_ports, const port_cfg_t *, cfg) {
- if (cfg->type == listener_type &&
- !cfg->server_cfg.no_advertise) {
+ if (cfg->type == listener_type && !cfg->server_cfg.no_advertise) {
if ((address_family == AF_INET && port_binds_ipv4(cfg)) ||
(address_family == AF_INET6 && port_binds_ipv6(cfg))) {
- return cfg;
+ if (cfg->explicit_addr && !first_port_explicit_addr) {
+ first_port_explicit_addr = cfg;
+ } else if (!first_port) {
+ first_port = cfg;
+ }
}
}
} SMARTLIST_FOREACH_END(cfg);
- return NULL;
+
+ /* Prefer the port with the explicit address if any. */
+ return (first_port_explicit_addr) ? first_port_explicit_addr : first_port;
}
/** Return the first advertised port of type <b>listener_type</b> in