commit 6da8c0b4fa9243158c860035c27d2d9bba17a832 Author: David Goulet dgoulet@torproject.org Date: Mon Jun 15 15:27:32 2020 -0400
addr: Rename resolve_my_address to be v4 specific
Part of #33233
Signed-off-by: David Goulet dgoulet@torproject.org --- scripts/maint/practracker/exceptions.txt | 2 +- src/app/config/resolve_addr.c | 6 ++-- src/app/config/resolve_addr.h | 6 ++-- src/feature/dirauth/dirauth_config.c | 2 +- src/feature/dirauth/dirvote.c | 2 +- src/feature/nodelist/dirlist.c | 4 +-- src/feature/relay/relay_find_addr.c | 4 +-- src/feature/relay/router.c | 2 +- src/test/test_config.c | 52 ++++++++++++++++---------------- 9 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/scripts/maint/practracker/exceptions.txt b/scripts/maint/practracker/exceptions.txt index 154f43ee1..a5b3ca724 100644 --- a/scripts/maint/practracker/exceptions.txt +++ b/scripts/maint/practracker/exceptions.txt @@ -46,7 +46,7 @@ problem function-size /src/app/config/config.c:parse_dir_authority_line() 150 problem function-size /src/app/config/config.c:parse_dir_fallback_line() 101 problem function-size /src/app/config/config.c:port_parse_config() 435 problem function-size /src/app/config/config.c:parse_ports() 132 -problem function-size /src/app/config/resolve_addr.c:resolve_my_address() 191 +problem function-size /src/app/config/resolve_addr.c:resolve_my_address_v4() 197 problem file-size /src/app/config/or_options_st.h 1050 problem include-count /src/app/main/main.c 68 problem function-size /src/app/main/main.c:dumpstats() 102 diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c index 5723a00fa..fe375848d 100644 --- a/src/app/config/resolve_addr.c +++ b/src/app/config/resolve_addr.c @@ -85,9 +85,9 @@ reset_last_resolved_addr(void) * XXXX ipv6 */ int -resolve_my_address(int warn_severity, const or_options_t *options, - uint32_t *addr_out, - const char **method_out, char **hostname_out) +resolve_my_address_v4(int warn_severity, const or_options_t *options, + uint32_t *addr_out, + const char **method_out, char **hostname_out) { struct in_addr in; uint32_t addr; /* host order */ diff --git a/src/app/config/resolve_addr.h b/src/app/config/resolve_addr.h index 374754640..2c8143df5 100644 --- a/src/app/config/resolve_addr.h +++ b/src/app/config/resolve_addr.h @@ -11,9 +11,9 @@
#include "app/config/or_options_st.h"
-int resolve_my_address(int warn_severity, const or_options_t *options, - uint32_t *addr_out, - const char **method_out, char **hostname_out); +int resolve_my_address_v4(int warn_severity, const or_options_t *options, + uint32_t *addr_out, + const char **method_out, char **hostname_out);
uint32_t get_last_resolved_addr(void); void reset_last_resolved_addr(void); diff --git a/src/feature/dirauth/dirauth_config.c b/src/feature/dirauth/dirauth_config.c index a0b6de7ec..888b8e7d9 100644 --- a/src/feature/dirauth/dirauth_config.c +++ b/src/feature/dirauth/dirauth_config.c @@ -78,7 +78,7 @@ options_validate_dirauth_mode(const or_options_t *old_options,
/* confirm that our address isn't broken, so we can complain now */ uint32_t tmp; - if (resolve_my_address(LOG_WARN, options, &tmp, NULL, NULL) < 0) + if (resolve_my_address_v4(LOG_WARN, options, &tmp, NULL, NULL) < 0) REJECT("Failed to resolve/guess local address. See logs for details.");
if (!options->ContactInfo && !options->TestingTorNetwork) diff --git a/src/feature/dirauth/dirvote.c b/src/feature/dirauth/dirvote.c index 79651563b..3030955fd 100644 --- a/src/feature/dirauth/dirvote.c +++ b/src/feature/dirauth/dirvote.c @@ -4492,7 +4492,7 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key, log_err(LD_BUG, "Error computing identity key digest"); return NULL; } - if (resolve_my_address(LOG_WARN, options, &addr, NULL, &hostname)<0) { + if (resolve_my_address_v4(LOG_WARN, options, &addr, NULL, &hostname)<0) { log_warn(LD_NET, "Couldn't resolve my hostname"); return NULL; } diff --git a/src/feature/nodelist/dirlist.c b/src/feature/nodelist/dirlist.c index 33d1bfc4d..4481daba6 100644 --- a/src/feature/nodelist/dirlist.c +++ b/src/feature/nodelist/dirlist.c @@ -349,8 +349,8 @@ trusted_dir_server_new(const char *nickname, const char *address, dir_server_t *result;
if (!address) { /* The address is us; we should guess. */ - if (resolve_my_address(LOG_WARN, get_options(), - &a, NULL, &hostname) < 0) { + if (resolve_my_address_v4(LOG_WARN, get_options(), + &a, NULL, &hostname) < 0) { log_warn(LD_CONFIG, "Couldn't find a suitable address when adding ourself as a " "trusted directory server."); diff --git a/src/feature/relay/relay_find_addr.c b/src/feature/relay/relay_find_addr.c index 86cd799d4..561ef1507 100644 --- a/src/feature/relay/relay_find_addr.c +++ b/src/feature/relay/relay_find_addr.c @@ -66,7 +66,7 @@ router_new_address_suggestion(const char *suggestion, /* XXXX ipv6 */ cur = get_last_resolved_addr(); if (cur || - resolve_my_address(LOG_INFO, options, &cur, NULL, NULL) >= 0) { + resolve_my_address_v4(LOG_INFO, options, &cur, NULL, NULL) >= 0) { /* We're all set -- we already know our address. Great. */ tor_addr_from_ipv4h(&last_guessed_ip, cur); /* store it in case we need it later */ @@ -118,7 +118,7 @@ router_pick_published_address, (const or_options_t *options, uint32_t *addr,
/* Second, consider doing a resolve attempt right here. */ if (!cache_only) { - if (resolve_my_address(LOG_INFO, options, addr, NULL, NULL) >= 0) { + if (resolve_my_address_v4(LOG_INFO, options, addr, NULL, NULL) >= 0) { log_info(LD_CONFIG,"Success: chose address '%s'.", fmt_addr32(*addr)); return 0; } diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c index 691494672..4d5ed3a3e 100644 --- a/src/feature/relay/router.c +++ b/src/feature/relay/router.c @@ -2552,7 +2552,7 @@ check_descriptor_ipaddress_changed(time_t now)
/* XXXX ipv6 */ prev = my_ri->addr; - if (resolve_my_address(LOG_INFO, options, &cur, &method, &hostname) < 0) { + if (resolve_my_address_v4(LOG_INFO, options, &cur, &method, &hostname) < 0) { log_info(LD_CONFIG,"options->Address didn't resolve into an IP."); return; } diff --git a/src/test/test_config.c b/src/test/test_config.c index 2b4450532..87104113b 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -1186,7 +1186,7 @@ get_interface_address6_failure(int severity, sa_family_t family, }
static void -test_config_resolve_my_address(void *arg) +test_config_resolve_my_address_v4(void *arg) { or_options_t *options; uint32_t resolved_addr; @@ -1219,7 +1219,7 @@ test_config_resolve_my_address(void *arg) strlcpy(buf, "Address 128.52.128.105\n", sizeof(buf)); config_get_lines(buf, &(options->Address), 0);
- retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, + retval = resolve_my_address_v4(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out);
tt_want(retval == 0); @@ -1231,7 +1231,7 @@ test_config_resolve_my_address(void *arg)
/* * CASE 2: - * If options->Address is a valid DNS address, we want resolve_my_address() + * If options->Address is a valid DNS address, we want resolve_my_address_v4() * function to ask tor_lookup_hostname() for help with resolving it * and return the address that was resolved (in host order). */ @@ -1243,7 +1243,7 @@ test_config_resolve_my_address(void *arg)
prev_n_hostname_01010101 = n_hostname_01010101;
- retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, + retval = resolve_my_address_v4(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out);
tt_want(retval == 0); @@ -1259,7 +1259,7 @@ test_config_resolve_my_address(void *arg)
/* * CASE 3: - * Given that options->Address is NULL, we want resolve_my_address() + * Given that options->Address is NULL, we want resolve_my_address_v4() * to try and use tor_gethostname() to get hostname AND use * tor_lookup_hostname() to get IP address. */ @@ -1273,7 +1273,7 @@ test_config_resolve_my_address(void *arg) prev_n_gethostname_replacement = n_gethostname_replacement; prev_n_hostname_01010101 = n_hostname_01010101;
- retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, + retval = resolve_my_address_v4(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out);
tt_want(retval == 0); @@ -1291,14 +1291,14 @@ test_config_resolve_my_address(void *arg) /* * CASE 4: * Given that options->Address is a local host address, we want - * resolve_my_address() function to fail. + * resolve_my_address_v4() function to fail. */
resolved_addr = 0; strlcpy(buf, "Address 127.0.0.1\n", sizeof(buf)); config_get_lines(buf, &(options->Address), 0);
- retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, + retval = resolve_my_address_v4(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out);
tt_want(resolved_addr == 0); @@ -1309,7 +1309,7 @@ test_config_resolve_my_address(void *arg)
/* * CASE 5: - * We want resolve_my_address() to fail if DNS address in options->Address + * We want resolve_my_address_v4() to fail if DNS address in options->Address * cannot be resolved. */
@@ -1320,7 +1320,7 @@ test_config_resolve_my_address(void *arg) strlcpy(buf, "Address www.tor-project.org\n", sizeof(buf)); config_get_lines(buf, &(options->Address), 0);
- retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, + retval = resolve_my_address_v4(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out);
tt_want(n_hostname_failure == prev_n_hostname_failure + 1); @@ -1335,14 +1335,14 @@ test_config_resolve_my_address(void *arg) /* * CASE 6: * If options->Address is NULL AND gettting local hostname fails, we want - * resolve_my_address() to fail as well. + * resolve_my_address_v4() to fail as well. */
MOCK(tor_gethostname,tor_gethostname_failure);
prev_n_gethostname_failure = n_gethostname_failure;
- retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, + retval = resolve_my_address_v4(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out);
tt_want(n_gethostname_failure == prev_n_gethostname_failure + 1); @@ -1353,7 +1353,7 @@ test_config_resolve_my_address(void *arg)
/* * CASE 7: - * We want resolve_my_address() to try and get network interface address via + * We want resolve_my_address_v4() to try and get network interface address via * get_interface_address() if hostname returned by tor_gethostname() cannot be * resolved into IP address. */ @@ -1365,7 +1365,7 @@ test_config_resolve_my_address(void *arg) prev_n_gethostname_replacement = n_gethostname_replacement; prev_n_get_interface_address = n_get_interface_address;
- retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, + retval = resolve_my_address_v4(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out);
tt_want(retval == 0); @@ -1383,7 +1383,7 @@ test_config_resolve_my_address(void *arg) /* * CASE 8: * Suppose options->Address is NULL AND hostname returned by tor_gethostname() - * is unresolvable. We want resolve_my_address to fail if + * is unresolvable. We want resolve_my_address_v4 to fail if * get_interface_address() fails. */
@@ -1392,7 +1392,7 @@ test_config_resolve_my_address(void *arg) prev_n_get_interface_address_failure = n_get_interface_address_failure; prev_n_gethostname_replacement = n_gethostname_replacement;
- retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, + retval = resolve_my_address_v4(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out);
tt_want(n_get_interface_address_failure == @@ -1408,7 +1408,7 @@ test_config_resolve_my_address(void *arg) * CASE 9: * Given that options->Address is NULL AND tor_lookup_hostname() * fails AND hostname returned by gethostname() resolves - * to local IP address, we want resolve_my_address() function to + * to local IP address, we want resolve_my_address_v4() function to * call get_interface_address6(.,AF_INET,.) and return IP address * the latter function has found. */ @@ -1421,7 +1421,7 @@ test_config_resolve_my_address(void *arg) prev_n_hostname_failure = n_hostname_failure; prev_n_get_interface_address6 = n_get_interface_address6;
- retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, + retval = resolve_my_address_v4(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out);
tt_want(last_address6_family == AF_INET); @@ -1439,7 +1439,7 @@ test_config_resolve_my_address(void *arg) tor_free(hostname_out);
/* - * CASE 10: We want resolve_my_address() to fail if all of the following + * CASE 10: We want resolve_my_address_v4() to fail if all of the following * are true: * 1. options->Address is not NULL * 2. ... but it cannot be converted to struct in_addr by @@ -1455,7 +1455,7 @@ test_config_resolve_my_address(void *arg) strlcpy(buf, "Address some_hostname\n", sizeof(buf)); config_get_lines(buf, &(options->Address), 0);
- retval = resolve_my_address(LOG_NOTICE, options, &resolved_addr, + retval = resolve_my_address_v4(LOG_NOTICE, options, &resolved_addr, &method_used,&hostname_out);
tt_want(n_hostname_failure == prev_n_hostname_failure + 1); @@ -1496,7 +1496,7 @@ test_config_resolve_my_address(void *arg) prev_n_hostname_localhost = n_hostname_localhost; prev_n_get_interface_address6 = n_get_interface_address6;
- retval = resolve_my_address(LOG_DEBUG, options, &resolved_addr, + retval = resolve_my_address_v4(LOG_DEBUG, options, &resolved_addr, &method_used,&hostname_out);
tt_want(n_gethostname_replacement == prev_n_gethostname_replacement + 1); @@ -1512,7 +1512,7 @@ test_config_resolve_my_address(void *arg) * 1-5 as above. * 6. get_interface_address6() fails. * - * In this subcase, we want resolve_my_address() to fail. + * In this subcase, we want resolve_my_address_v4() to fail. */
UNMOCK(get_interface_address6); @@ -1522,7 +1522,7 @@ test_config_resolve_my_address(void *arg) prev_n_hostname_localhost = n_hostname_localhost; prev_n_get_interface_address6_failure = n_get_interface_address6_failure;
- retval = resolve_my_address(LOG_DEBUG, options, &resolved_addr, + retval = resolve_my_address_v4(LOG_DEBUG, options, &resolved_addr, &method_used,&hostname_out);
tt_want(n_gethostname_replacement == prev_n_gethostname_replacement + 1); @@ -1544,7 +1544,7 @@ test_config_resolve_my_address(void *arg) * 4. into IPv4 address that tor_addr_is_inernal() considers to be * internal. * - * In this case, we want resolve_my_address() to fail. + * In this case, we want resolve_my_address_v4() to fail. */
tor_free(options->Address); @@ -1555,7 +1555,7 @@ test_config_resolve_my_address(void *arg)
prev_n_gethostname_localhost = n_gethostname_localhost;
- retval = resolve_my_address(LOG_DEBUG, options, &resolved_addr, + retval = resolve_my_address_v4(LOG_DEBUG, options, &resolved_addr, &method_used,&hostname_out);
tt_want(n_gethostname_localhost == prev_n_gethostname_localhost + 1); @@ -6257,7 +6257,7 @@ struct testcase_t config_tests[] = { CONFIG_TEST(adding_dir_servers, TT_FORK), CONFIG_TEST(default_dir_servers, TT_FORK), CONFIG_TEST(default_fallback_dirs, 0), - CONFIG_TEST(resolve_my_address, TT_FORK), + CONFIG_TEST(resolve_my_address_v4, TT_FORK), CONFIG_TEST(addressmap, 0), CONFIG_TEST(parse_bridge_line, 0), CONFIG_TEST(parse_transport_options_line, 0),
tor-commits@lists.torproject.org