From b76325190b3fb2d01fb0c9f0d2ffe76a284d1766 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 23 Jun 2020 11:19:50 -0400 Subject: 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 --- src/app/config/resolve_addr.c | 68 ++----------------------------------------- 1 file changed, 2 insertions(+), 66 deletions(-) (limited to 'src/app/config/resolve_addr.c') diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c index c73519f148..56548e6e70 100644 --- a/src/app/config/resolve_addr.c +++ b/src/app/config/resolve_addr.c @@ -528,70 +528,6 @@ find_my_address(const or_options_t *options, int family, int warn_severity, return true; } -/** - * Attempt getting our non-local (as judged by tor_addr_is_internal() - * function) IP address using following techniques, listed in - * order from best (most desirable, try first) to worst (least - * desirable, try if everything else fails). - * - * First, attempt using options-\>Address to get our - * non-local IP address. - * - * If options-\>Address represents a non-local IP address, - * consider it ours. - * - * If options-\>Address is a DNS name that resolves to - * a non-local IP address, consider this IP address ours. - * - * If options-\>Address is NULL, fall back to getting local - * hostname and using it in above-described ways to try and - * get our IP address. - * - * In case local hostname cannot be resolved to a non-local IP - * address, try getting an IP address of network interface - * in hopes it will be non-local one. - * - * Fail if one or more of the following is true: - * - DNS name in options-\>Address cannot be resolved. - * - options-\>Address is a local host address. - * - Attempt at getting local hostname fails. - * - Attempt at getting network interface address fails. - * - * Return 0 if all is well, or -1 if we can't find a suitable - * public IP address. - * - * If we are returning 0: - * - Put our public IP address (in host order) into *addr_out. - * - If method_out is non-NULL, set *method_out to a static - * string describing how we arrived at our answer. - * - "CONFIGURED" - parsed from IP address string in - * options-\>Address - * - "RESOLVED" - resolved from DNS name in options-\>Address - * - "GETHOSTNAME" - resolved from a local hostname. - * - "INTERFACE" - retrieved from a network interface. - * - If hostname_out is non-NULL, and we resolved a hostname to - * get our address, set *hostname_out to a newly allocated string - * holding that hostname. (If we didn't get our address by resolving a - * hostname, set *hostname_out to NULL.) - * - * XXXX ipv6 - */ -int -resolve_my_address_v4(int warn_severity, const or_options_t *options, - uint32_t *addr_out, - const char **method_out, char **hostname_out) -{ - tor_addr_t my_addr; - bool ret = find_my_address(options, AF_INET, warn_severity, &my_addr, - method_out, hostname_out); - if (!ret) { - return -1; - } - - *addr_out = tor_addr_to_ipv4h(&my_addr); - return 0; -} - /** Return true iff addr is judged to be on the same network as us, or * on a private network. */ @@ -618,8 +554,8 @@ resolved_addr_is_local, (const tor_addr_t *addr)) * can't use addrs_in_same_network_family(). */ /* It's possible that this next check will hit before the first time - * resolve_my_address_v4 actually succeeds. For clients, it is likely that - * resolve_my_address_v4 will never be called at all. In those cases, + * find_my_address actually succeeds. For clients, it is likely that + * find_my_address will never be called at all. In those cases, * last_resolved_addr_v4 will be 0, and so checking to see whether ip is * on the same /24 as last_resolved_addrs[AF_INET] will be the same as * checking whether it was on net 0, which is already done by -- cgit v1.2.3-54-g00ecf