From 7640a95602020fb6355d5db1a3cd8bb1c5c2acb5 Mon Sep 17 00:00:00 2001 From: c Date: Mon, 1 Jun 2020 13:02:21 +0000 Subject: [PATCH 1/3] config: Add IPv4 Address config debug logging Per ticket #32888 this should address logging "the Address torrc option", "and whether it is an IP address, or a DNS name"; or the detected "local hostname", "and whether it is an IP address, or a DNS name". Some of these details already seem to be logged, so just add what's missing. --- src/app/config/resolve_addr.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c index b551615c02..52f4efc992 100644 --- a/src/app/config/resolve_addr.c +++ b/src/app/config/resolve_addr.c @@ -110,6 +110,8 @@ resolve_my_address(int warn_severity, const or_options_t *options, if (address && *address) { strlcpy(hostname, address, sizeof(hostname)); + log_debug(LD_CONFIG, "Trying configured Address '%s' as local hostname", + hostname); } else { /* then we need to guess our address */ explicit_ip = 0; /* it's implicit */ explicit_hostname = 0; /* it's implicit */ @@ -129,6 +131,8 @@ resolve_my_address(int warn_severity, const or_options_t *options, if (tor_inet_aton(hostname, &in) == 0) { /* then we have to resolve it */ + log_debug(LD_CONFIG, "Local hostname '%s' is DNS address. " + "Trying to resolve to IP address.", hostname); explicit_ip = 0; if (tor_lookup_hostname(hostname, &addr)) { /* failed to resolve */ uint32_t interface_ip; /* host order */ @@ -180,6 +184,8 @@ resolve_my_address(int warn_severity, const or_options_t *options, } } } else { + log_debug(LD_CONFIG, "Local hostname '%s' is already IP address, " + "skipping DNS resolution", hostname); addr = ntohl(in.s_addr); /* set addr so that addr_string is not * illformed */ } From 1934e399afecea0859b7ea6b205be96d0f73380b Mon Sep 17 00:00:00 2001 From: c Date: Wed, 3 Jun 2020 14:42:53 +0000 Subject: [PATCH 2/3] config: Add interface address debug logging Add logging for "the local network interface addresses" as requested by ticket #32888. --- src/lib/net/address.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/net/address.c b/src/lib/net/address.c index b8f5f37747..0571f48a30 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -1693,12 +1693,20 @@ get_interface_address6,(int severity, sa_family_t family, tor_addr_t *addr)) /* Find the first non-internal address, or the last internal address * Ideally, we want the default route, see #12377 for details */ SMARTLIST_FOREACH_BEGIN(addrs, tor_addr_t *, a) { + char *addr_str; + int is_internal; tor_addr_copy(addr, a); + is_internal = tor_addr_is_internal(a, 0); rv = 0; + addr_str = tor_addr_to_str_dup(addr); + log_debug(LD_NET, "Found %s interface address '%s'", + (is_internal ? "internal" : "external"), addr_str); + tor_free(addr_str); + /* If we found a non-internal address, declare success. Otherwise, * keep looking. */ - if (!tor_addr_is_internal(a, 0)) + if (!is_internal) break; } SMARTLIST_FOREACH_END(a); From 8b568b50a5054f5e94d7085682e717b4eab58ce5 Mon Sep 17 00:00:00 2001 From: c Date: Thu, 4 Jun 2020 13:15:27 +0000 Subject: [PATCH 3/3] config: Styling fix + use fmt_addr() Conform to C99 as suggested by nickm on #32888 and use fmt_addr() rather than tor_addr_to_str_dup() --- src/lib/net/address.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/lib/net/address.c b/src/lib/net/address.c index 0571f48a30..b09c9115c4 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -1693,16 +1693,12 @@ get_interface_address6,(int severity, sa_family_t family, tor_addr_t *addr)) /* Find the first non-internal address, or the last internal address * Ideally, we want the default route, see #12377 for details */ SMARTLIST_FOREACH_BEGIN(addrs, tor_addr_t *, a) { - char *addr_str; - int is_internal; tor_addr_copy(addr, a); - is_internal = tor_addr_is_internal(a, 0); + const bool is_internal = tor_addr_is_internal(a, 0); rv = 0; - addr_str = tor_addr_to_str_dup(addr); log_debug(LD_NET, "Found %s interface address '%s'", - (is_internal ? "internal" : "external"), addr_str); - tor_free(addr_str); + (is_internal ? "internal" : "external"), fmt_addr(addr)); /* If we found a non-internal address, declare success. Otherwise, * keep looking. */