relay: Skip address discovery if no ORPort is found

In other words, if we don't have an ORPort configured for a specific family
(IPv4/v6), we don't bother doing address discovery.

Related to #40254

Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
David Goulet 2021-01-22 10:23:07 -05:00 committed by Nick Mathewson
parent 5eef63aa71
commit b4f4af6ec5
2 changed files with 37 additions and 9 deletions

View File

@ -99,6 +99,13 @@ relay_address_new_suggestion(const tor_addr_t *suggested_addr,
* populated by the NETINFO cell content or HTTP header from a
* directory.
*
* The AddressDisableIPv6 is checked here for IPv6 address discovery and if
* set, false is returned and addr_out is UNSPEC.
*
* Before doing any discovery, the configuration is checked for an ORPort of
* the given family. If none can be found, false is returned and addr_out is
* UNSPEC.
*
* Return true on success and addr_out contains the address to use for the
* given family. On failure to find the address, false is returned and
* addr_out is set to an AF_UNSPEC address. */
@ -118,6 +125,12 @@ relay_find_addr_to_publish, (const or_options_t *options, int family,
return false;
}
/* There is no point on attempting an address discovery to publish if we
* don't have an ORPort for this family. */
if (!routerconf_find_or_port(options, family)) {
return false;
}
/* First, check our resolved address cache. It should contain the address
* we've discovered from the periodic relay event. */
resolved_addr_get_last(family, addr_out);

View File

@ -11,6 +11,7 @@
#include "feature/stats/bwhist.h"
#include "core/or/relay.h"
#include "lib/container/order.h"
#include "lib/encoding/confline.h"
/* For init/free stuff */
#include "core/or/scheduler.h"
@ -23,6 +24,8 @@
#include "feature/relay/routermode.h"
#include "feature/dirclient/dir_server_st.h"
#define CONFIG_PRIVATE
#include "app/config/config.h"
#include "app/config/resolve_addr.h"
/* Test suite stuff */
@ -298,11 +301,12 @@ test_find_addr_to_publish(void *arg)
int family;
bool ret;
tor_addr_t ipv4_addr, ipv6_addr, cache_addr;
or_options_t options;
or_options_t *options;
(void) arg;
memset(&options, 0, sizeof(options));
options = options_new();
options_init(options);
/* Populate our resolved cache with a valid IPv4 and IPv6. */
family = tor_addr_parse(&ipv4_addr, "1.2.3.4");
@ -317,13 +321,24 @@ test_find_addr_to_publish(void *arg)
resolved_addr_get_last(AF_INET6, &cache_addr);
tt_assert(tor_addr_eq(&ipv6_addr, &cache_addr));
/* Setup ORPort config. */
{
int n, w, r;
char *msg = NULL;
config_line_append(&options->ORPort_lines, "ORPort", "9001");
r = parse_ports(options, 0, &msg, &n, &w);
tt_int_op(r, OP_EQ, 0);
}
/* 1. Address located in the resolved cache. */
ret = relay_find_addr_to_publish(&options, AF_INET,
ret = relay_find_addr_to_publish(options, AF_INET,
RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
tt_assert(ret);
tt_assert(tor_addr_eq(&ipv4_addr, &cache_addr));
ret = relay_find_addr_to_publish(&options, AF_INET6,
ret = relay_find_addr_to_publish(options, AF_INET6,
RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
tt_assert(ret);
tt_assert(tor_addr_eq(&ipv6_addr, &cache_addr));
@ -334,13 +349,13 @@ test_find_addr_to_publish(void *arg)
* the find_my_address() code path because that is extensively tested in
* another unit tests. */
resolved_addr_set_suggested(&ipv4_addr);
ret = relay_find_addr_to_publish(&options, AF_INET,
ret = relay_find_addr_to_publish(options, AF_INET,
RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
tt_assert(ret);
tt_assert(tor_addr_eq(&ipv4_addr, &cache_addr));
resolved_addr_set_suggested(&ipv6_addr);
ret = relay_find_addr_to_publish(&options, AF_INET6,
ret = relay_find_addr_to_publish(options, AF_INET6,
RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
tt_assert(ret);
tt_assert(tor_addr_eq(&ipv6_addr, &cache_addr));
@ -348,15 +363,15 @@ test_find_addr_to_publish(void *arg)
resolve_addr_reset_suggested(AF_INET6);
/* 3. No IP anywhere. */
ret = relay_find_addr_to_publish(&options, AF_INET,
ret = relay_find_addr_to_publish(options, AF_INET,
RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
tt_assert(!ret);
ret = relay_find_addr_to_publish(&options, AF_INET6,
ret = relay_find_addr_to_publish(options, AF_INET6,
RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
tt_assert(!ret);
done:
;
or_options_free(options);
}
struct testcase_t relay_tests[] = {