Merge branch 'tor-gitlab/mr/74'

This commit is contained in:
David Goulet 2020-07-22 16:09:11 -04:00
commit 492625badf
2 changed files with 37 additions and 28 deletions

View File

@ -651,6 +651,7 @@ find_my_address(const or_options_t *options, int family, int warn_severity,
tor_assert(addr_out); tor_assert(addr_out);
/* Set them to NULL for safety reasons. */ /* Set them to NULL for safety reasons. */
tor_addr_make_unspec(addr_out);
if (method_out) *method_out = NULL; if (method_out) *method_out = NULL;
if (hostname_out) *hostname_out = NULL; if (hostname_out) *hostname_out = NULL;

View File

@ -2589,51 +2589,59 @@ log_addr_has_changed(int severity,
addrbuf_cur, source); addrbuf_cur, source);
} }
/** Check whether our own address as defined by the Address configuration /** Check whether our own address has changed versus the one we have in our
* has changed. This is for routers that get their address from a service * current descriptor.
* like dyndns. If our address has changed, mark our descriptor dirty. */ *
* If our address has changed, call ip_address_changed() which takes
* appropriate actions. */
void void
check_descriptor_ipaddress_changed(time_t now) check_descriptor_ipaddress_changed(time_t now)
{ {
uint32_t prev, cur; const routerinfo_t *my_ri = router_get_my_routerinfo();
tor_addr_t addr;
const or_options_t *options = get_options();
const char *method = NULL; const char *method = NULL;
char *hostname = 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; (void) now;
if (my_ri == NULL) /* make sure routerinfo exists */ /* We can't learn our descriptor address without one. */
return; if (my_ri == NULL) {
/* 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.");
return; return;
} }
cur = tor_addr_to_ipv4h(&addr);
if (prev != cur) { for (size_t i = 0; i < ARRAY_LENGTH(families); i++) {
tor_addr_t current;
const tor_addr_t *previous;
int family = families[i];
/* 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;
}
/* 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, &current, &method,
&hostname);
if (!tor_addr_eq(previous, &current)) {
char *source; char *source;
tor_addr_t tmp_prev, tmp_cur; tor_asprintf(&source, "METHOD=%s%s%s",
method ? method : "UNKNOWN",
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=" : "",
hostname ? hostname : ""); hostname ? hostname : "");
log_addr_has_changed(LOG_NOTICE, previous, &current, source);
log_addr_has_changed(LOG_NOTICE, &tmp_prev, &tmp_cur, source);
tor_free(source); tor_free(source);
has_changed = true;
ip_address_changed(0); }
tor_free(hostname);
} }
tor_free(hostname); if (has_changed) {
ip_address_changed(0);
}
} }
/** Set <b>platform</b> (max length <b>len</b>) to a NUL-terminated short /** Set <b>platform</b> (max length <b>len</b>) to a NUL-terminated short