summaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2020-07-02 09:44:49 -0400
committerNick Mathewson <nickm@torproject.org>2020-07-02 11:00:42 -0400
commit45afb31e1ce7c8572342c4e444a178b590d9645d (patch)
tree67a7da1048eff0ba5f152b67b7282d79e154c71f /src/app
parent9b560ea71471b86a85c446f796b8934ea9c1bed8 (diff)
downloadtor-45afb31e1ce7c8572342c4e444a178b590d9645d.tar.gz
tor-45afb31e1ce7c8572342c4e444a178b590d9645d.zip
addr: Prioritize interface lookup over local hostname
The find_my_address() function now prioritize the local interface over the local hostname when guessing the IP address. See proposal 312, section 3.2.1, general case: https://gitweb.torproject.org/torspec.git/tree/proposals/312-relay-auto-ipv6-addr.txt#n359 The entire unit tests had to be refactored to make this possible. Instead of hot patching it, it has been rewritten to cover all possible cases and the test interface has been changed to accomodate both IPv4 and IPv6 in order for them to be tested identically. Closes #33238 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/app')
-rw-r--r--src/app/config/resolve_addr.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c
index 167a4aa4dd..8c08c6ec03 100644
--- a/src/app/config/resolve_addr.c
+++ b/src/app/config/resolve_addr.c
@@ -445,8 +445,8 @@ static fn_address_ret_t
{
/* These functions are in order for our find address algorithm. */
get_address_from_config,
- get_address_from_hostname,
get_address_from_interface,
+ get_address_from_hostname,
};
/** Length of address table as in how many functions. */
static const size_t fn_address_table_len = ARRAY_LENGTH(fn_address_table);
@@ -478,7 +478,17 @@ static const size_t fn_address_table_len = ARRAY_LENGTH(fn_address_table);
*
* If no given Address, fallback to the local hostname (see section 2).
*
- * 2. Look at the local hostname.
+ * 2. Look at the network interface.
+ *
+ * Attempt to find the first public usable address from the list of
+ * network interface returned by the OS.
+ *
+ * On failure, we attempt to look at the local hostname (3).
+ *
+ * On success, addr_out is set with it, method_out is set to "INTERFACE"
+ * and hostname_out is set to NULL.
+ *
+ * 3. Look at the local hostname.
*
* If the local hostname resolves to a non internal address, addr_out is
* set with it, method_out is set to "GETHOSTNAME" and hostname_out is set
@@ -489,20 +499,7 @@ static const size_t fn_address_table_len = ARRAY_LENGTH(fn_address_table);
* If the local hostname resolves to an internal address, an error is
* returned.
*
- * If the local hostname can NOT be resolved, fallback to the network
- * interface (see section 3).
- *
- * 3. Look at the network interface.
- *
- * Attempt to find the first public usable address from the list of
- * network interface returned by the OS.
- *
- * On failure, an error is returned. This error indicates that all
- * attempts have failed and thus the address for the given family can not
- * be found.
- *
- * On success, addr_out is set with it, method_out is set to "INTERFACE"
- * and hostname_out is set to NULL.
+ * If the local hostname can NOT be resolved, an error is returned.
*
* @param options Global configuration options.
* @param family IP address family. Only AF_INET and AF_INET6 are supported.