diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-04-24 08:14:59 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-04-24 08:14:59 -0400 |
commit | 7f9eaec538b7d01e0d1b130dc4cf2ec634252d46 (patch) | |
tree | aac52f6a3fae510c8692acd6c1eb42bcfa1d7143 /src/core/or/connection_or.c | |
parent | b2849f449b2efa4d6826166a92f35c7627d65f91 (diff) | |
parent | 8c55d34e0adfd9585befd7ce1f71fb219ed63146 (diff) | |
download | tor-7f9eaec538b7d01e0d1b130dc4cf2ec634252d46.tar.gz tor-7f9eaec538b7d01e0d1b130dc4cf2ec634252d46.zip |
Merge remote-tracking branch 'tor-github/pr/1862/head'
Diffstat (limited to 'src/core/or/connection_or.c')
-rw-r--r-- | src/core/or/connection_or.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/core/or/connection_or.c b/src/core/or/connection_or.c index af73e295a3..53a093e138 100644 --- a/src/core/or/connection_or.c +++ b/src/core/or/connection_or.c @@ -902,12 +902,21 @@ connection_or_check_canonicity(or_connection_t *conn, int started_here) } if (r) { - tor_addr_port_t node_ap; - node_get_pref_orport(r, &node_ap); - /* XXXX proposal 186 is making this more complex. For now, a conn - is canonical when it uses the _preferred_ address. */ - if (tor_addr_eq(&conn->base_.addr, &node_ap.addr)) + tor_addr_port_t node_ipv4_ap; + tor_addr_port_t node_ipv6_ap; + node_get_prim_orport(r, &node_ipv4_ap); + node_get_pref_ipv6_orport(r, &node_ipv6_ap); + if (tor_addr_eq(&conn->base_.addr, &node_ipv4_ap.addr) || + tor_addr_eq(&conn->base_.addr, &node_ipv6_ap.addr)) { connection_or_set_canonical(conn, 1); + } + /* Choose the correct canonical address and port. */ + tor_addr_port_t *node_ap; + if (tor_addr_family(&conn->base_.addr) == AF_INET) { + node_ap = &node_ipv4_ap; + } else { + node_ap = &node_ipv6_ap; + } if (!started_here) { /* Override the addr/port, so our log messages will make sense. * This is dangerous, since if we ever try looking up a conn by @@ -919,13 +928,14 @@ connection_or_check_canonicity(or_connection_t *conn, int started_here) * right IP address and port 56244, that wouldn't be as helpful. now we * log the "right" port too, so we know if it's moria1 or moria2. */ - tor_addr_copy(&conn->base_.addr, &node_ap.addr); - conn->base_.port = node_ap.port; + /* See #33898 for a ticket that resolves this technical debt. */ + tor_addr_copy(&conn->base_.addr, &node_ap->addr); + conn->base_.port = node_ap->port; } tor_free(conn->nickname); conn->nickname = tor_strdup(node_get_nickname(r)); tor_free(conn->base_.address); - conn->base_.address = tor_addr_to_str_dup(&node_ap.addr); + conn->base_.address = tor_addr_to_str_dup(&node_ap->addr); } else { tor_free(conn->nickname); conn->nickname = tor_malloc(HEX_DIGEST_LEN+2); |