aboutsummaryrefslogtreecommitdiff
path: root/src/feature
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2020-06-23 11:19:50 -0400
committerDavid Goulet <dgoulet@torproject.org>2020-06-24 13:51:37 -0400
commitb76325190b3fb2d01fb0c9f0d2ffe76a284d1766 (patch)
tree783d711aa801a6124bc4acecf0feca9bc82cc5c1 /src/feature
parent2f3b4e38888116f434297fb45ac093acd2d01e55 (diff)
downloadtor-b76325190b3fb2d01fb0c9f0d2ffe76a284d1766.tar.gz
tor-b76325190b3fb2d01fb0c9f0d2ffe76a284d1766.zip
addr: Remove resolve_my_address_v4()
Replace it by find_my_address() everywhere. This changes many parts of the code that uses it to use a tor_addr_t instead of a plain uint32_t for IPv4. Many changes to the unit test to also use the new interface. Part #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/dirauth/dirauth_config.c4
-rw-r--r--src/feature/dirauth/dirvote.c8
-rw-r--r--src/feature/nodelist/dirlist.c10
-rw-r--r--src/feature/relay/relay_find_addr.c17
-rw-r--r--src/feature/relay/router.c5
5 files changed, 24 insertions, 20 deletions
diff --git a/src/feature/dirauth/dirauth_config.c b/src/feature/dirauth/dirauth_config.c
index 888b8e7d94..1ffd33e5f1 100644
--- a/src/feature/dirauth/dirauth_config.c
+++ b/src/feature/dirauth/dirauth_config.c
@@ -77,8 +77,8 @@ options_validate_dirauth_mode(const or_options_t *old_options,
return 0;
/* confirm that our address isn't broken, so we can complain now */
- uint32_t tmp;
- if (resolve_my_address_v4(LOG_WARN, options, &tmp, NULL, NULL) < 0)
+ tor_addr_t tmp;
+ if (!find_my_address(options, AF_INET, LOG_WARN, &tmp, NULL, NULL))
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 3030955fd1..5fda842246 100644
--- a/src/feature/dirauth/dirvote.c
+++ b/src/feature/dirauth/dirvote.c
@@ -4463,7 +4463,7 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
const or_options_t *options = get_options();
const dirauth_options_t *d_options = dirauth_get_options();
networkstatus_t *v3_out = NULL;
- uint32_t addr;
+ tor_addr_t addr;
char *hostname = NULL, *client_versions = NULL, *server_versions = NULL;
const char *contact;
smartlist_t *routers, *routerstatuses;
@@ -4492,13 +4492,13 @@ 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_v4(LOG_WARN, options, &addr, NULL, &hostname)<0) {
+ if (!find_my_address(options, AF_INET, LOG_WARN, &addr, NULL, &hostname)) {
log_warn(LD_NET, "Couldn't resolve my hostname");
return NULL;
}
if (!hostname || !strchr(hostname, '.')) {
tor_free(hostname);
- hostname = tor_dup_ip(addr);
+ hostname = tor_addr_to_str_dup(&addr);
}
if (!hostname) {
@@ -4722,7 +4722,7 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
memcpy(voter->identity_digest, identity_digest, DIGEST_LEN);
voter->sigs = smartlist_new();
voter->address = hostname;
- voter->addr = addr;
+ voter->addr = tor_addr_to_ipv4h(&addr);
voter->dir_port = router_get_advertised_dir_port(options, 0);
voter->or_port = router_get_advertised_or_port(options);
voter->contact = tor_strdup(contact);
diff --git a/src/feature/nodelist/dirlist.c b/src/feature/nodelist/dirlist.c
index 4481daba6f..f49d991f9b 100644
--- a/src/feature/nodelist/dirlist.c
+++ b/src/feature/nodelist/dirlist.c
@@ -343,25 +343,25 @@ trusted_dir_server_new(const char *nickname, const char *address,
const char *digest, const char *v3_auth_digest,
dirinfo_type_t type, double weight)
{
- uint32_t a;
tor_addr_t addr;
char *hostname=NULL;
dir_server_t *result;
if (!address) { /* The address is us; we should guess. */
- if (resolve_my_address_v4(LOG_WARN, get_options(),
- &a, NULL, &hostname) < 0) {
+ if (!find_my_address(get_options(), AF_INET, LOG_WARN, &addr,
+ NULL, &hostname)) {
log_warn(LD_CONFIG,
"Couldn't find a suitable address when adding ourself as a "
"trusted directory server.");
return NULL;
}
if (!hostname)
- hostname = tor_dup_ip(a);
+ hostname = tor_addr_to_str_dup(&addr);
if (!hostname)
return NULL;
} else {
+ uint32_t a;
if (tor_lookup_hostname(address, &a)) {
log_warn(LD_CONFIG,
"Unable to lookup address for directory server at '%s'",
@@ -369,8 +369,8 @@ trusted_dir_server_new(const char *nickname, const char *address,
return NULL;
}
hostname = tor_strdup(address);
+ tor_addr_from_ipv4h(&addr, a);
}
- tor_addr_from_ipv4h(&addr, a);
result = dir_server_new(1, nickname, &addr, hostname,
dir_port, or_port,
diff --git a/src/feature/relay/relay_find_addr.c b/src/feature/relay/relay_find_addr.c
index 70cb77d4bf..a51457ddbb 100644
--- a/src/feature/relay/relay_find_addr.c
+++ b/src/feature/relay/relay_find_addr.c
@@ -45,8 +45,7 @@ void
router_new_address_suggestion(const char *suggestion,
const dir_connection_t *d_conn)
{
- tor_addr_t addr, last_resolved_addr;
- uint32_t cur = 0; /* Current IPv4 address. */
+ tor_addr_t addr, my_addr, last_resolved_addr;
const or_options_t *options = get_options();
/* first, learn what the IP address actually is */
@@ -72,10 +71,10 @@ router_new_address_suggestion(const char *suggestion,
}
/* Attempt to find our address. */
- if (resolve_my_address_v4(LOG_INFO, options, &cur, NULL, NULL) >= 0) {
+ if (find_my_address(options, AF_INET, LOG_INFO, &my_addr, NULL, NULL)) {
/* 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 */
+ tor_addr_copy(&last_guessed_ip, &my_addr); /* store it in case we
+ need it later */
return;
}
@@ -121,7 +120,7 @@ router_pick_published_address, (const or_options_t *options, uint32_t *addr,
{
tor_addr_t last_resolved_addr;
- /* First, check the cached output from resolve_my_address_v4(). */
+ /* First, check the cached output from find_my_address(). */
resolved_addr_get_last(AF_INET, &last_resolved_addr);
if (!tor_addr_is_null(&last_resolved_addr)) {
*addr = tor_addr_to_ipv4h(&last_resolved_addr);
@@ -130,8 +129,10 @@ 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_v4(LOG_INFO, options, addr, NULL, NULL) >= 0) {
- log_info(LD_CONFIG,"Success: chose address '%s'.", fmt_addr32(*addr));
+ tor_addr_t my_addr;
+ if (find_my_address(options, AF_INET, LOG_INFO, &my_addr, NULL, NULL)) {
+ log_info(LD_CONFIG,"Success: chose address '%s'.", fmt_addr(&my_addr));
+ *addr = tor_addr_to_ipv4h(&my_addr);
return 0;
}
}
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index 4d5ed3a3e1..fd62a3073a 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -2540,6 +2540,7 @@ void
check_descriptor_ipaddress_changed(time_t now)
{
uint32_t prev, cur;
+ tor_addr_t addr;
const or_options_t *options = get_options();
const char *method = NULL;
char *hostname = NULL;
@@ -2552,10 +2553,12 @@ check_descriptor_ipaddress_changed(time_t now)
/* XXXX ipv6 */
prev = my_ri->addr;
- if (resolve_my_address_v4(LOG_INFO, options, &cur, &method, &hostname) < 0) {
+ if (!find_my_address(options, AF_INET, LOG_INFO, &addr, &method,
+ &hostname)) {
log_info(LD_CONFIG,"options->Address didn't resolve into an IP.");
return;
}
+ cur = tor_addr_to_ipv4h(&addr);
if (prev != cur) {
char *source;