[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] relay: Support IPv6 when checking if our address changed
commit 65c7d33d33aaee8f3f9e4ac2c8ab08c9cdf54927
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date: Wed Jul 22 10:52:48 2020 -0400
relay: Support IPv6 when checking if our address changed
Now support IPv4 _and_ IPv6.
This also cleans up nicely the function that was moving IPv4 addresses from
uint32_t to tor_addr_t.
Fixes #40058
Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
src/feature/relay/router.c | 66 ++++++++++++++++++++++++++--------------------
1 file changed, 37 insertions(+), 29 deletions(-)
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index 97a77f9578..4a0a4203aa 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -2589,51 +2589,59 @@ log_addr_has_changed(int severity,
addrbuf_cur, source);
}
-/** Check whether our own address as defined by the Address configuration
- * has changed. This is for routers that get their address from a service
- * like dyndns. If our address has changed, mark our descriptor dirty. */
+/** Check whether our own address has changed versus the one we have in our
+ * current descriptor.
+ *
+ * If our address has changed, call ip_address_changed() which takes
+ * appropriate actions. */
void
check_descriptor_ipaddress_changed(time_t now)
{
- uint32_t prev, cur;
- tor_addr_t addr;
- const or_options_t *options = get_options();
+ const routerinfo_t *my_ri = router_get_my_routerinfo();
const char *method = NULL;
char *hostname = NULL;
- const routerinfo_t *my_ri = router_get_my_routerinfo();
+ int families[2] = { AF_INET, AF_INET6 };
+ bool has_changed = false;
(void) now;
- if (my_ri == NULL) /* make sure routerinfo exists */
- return;
-
- /* XXXX ipv6 */
- prev = tor_addr_to_ipv4h(&my_ri->ipv4_addr);
- if (!find_my_address(options, AF_INET, LOG_INFO, &addr, &method,
- &hostname)) {
- log_info(LD_CONFIG,"options->Address didn't resolve into an IP.");
+ /* We can't learn our descriptor address without one. */
+ if (my_ri == NULL) {
return;
}
- cur = tor_addr_to_ipv4h(&addr);
- if (prev != cur) {
- char *source;
- tor_addr_t tmp_prev, tmp_cur;
+ for (size_t i = 0; i < ARRAY_LENGTH(families); i++) {
+ tor_addr_t current;
+ const tor_addr_t *previous;
+ int family = families[i];
- tor_addr_from_ipv4h(&tmp_prev, prev);
- tor_addr_from_ipv4h(&tmp_cur, cur);
-
- tor_asprintf(&source, "METHOD=%s%s%s", method,
- hostname ? " HOSTNAME=" : "",
- hostname ? hostname : "");
+ /* Get the descriptor address from the family we are looking up. */
+ previous = &my_ri->ipv4_addr;
+ if (family == AF_INET6) {
+ previous = &my_ri->ipv6_addr;
+ }
- log_addr_has_changed(LOG_NOTICE, &tmp_prev, &tmp_cur, source);
- tor_free(source);
+ /* Ignore returned value because we want to notice not only an address
+ * change but also if an address is lost (current == UNSPEC). */
+ find_my_address(get_options(), family, LOG_INFO, ¤t, &method,
+ &hostname);
+
+ if (!tor_addr_eq(previous, ¤t)) {
+ char *source;
+ tor_asprintf(&source, "METHOD=%s%s%s",
+ method ? method : "UNKNOWN",
+ hostname ? " HOSTNAME=" : "",
+ hostname ? hostname : "");
+ log_addr_has_changed(LOG_NOTICE, previous, ¤t, source);
+ tor_free(source);
+ has_changed = true;
+ }
+ tor_free(hostname);
+ }
+ if (has_changed) {
ip_address_changed(0);
}
-
- tor_free(hostname);
}
/** Set <b>platform</b> (max length <b>len</b>) to a NUL-terminated short
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits