aboutsummaryrefslogtreecommitdiff
path: root/src/or/bridges.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-01-11 08:31:25 -0500
committerNick Mathewson <nickm@torproject.org>2018-01-11 08:31:25 -0500
commit7a606004111d8d12d4d90b26697bc9bab02b0227 (patch)
treec290d9edb5b88dc1f764ea6321ddf672b8877f23 /src/or/bridges.c
parentc8c258a4333815e195097a59801397dd7a169828 (diff)
parent525c1c493ea2bcab724919c1f2b3117c5db870f6 (diff)
downloadtor-7a606004111d8d12d4d90b26697bc9bab02b0227.tar.gz
tor-7a606004111d8d12d4d90b26697bc9bab02b0227.zip
Merge remote-tracking branch 'ffmancera/github/bug24573'
Diffstat (limited to 'src/or/bridges.c')
-rw-r--r--src/or/bridges.c59
1 files changed, 50 insertions, 9 deletions
diff --git a/src/or/bridges.c b/src/or/bridges.c
index 19a23ea86b..383c33fa61 100644
--- a/src/or/bridges.c
+++ b/src/or/bridges.c
@@ -719,7 +719,6 @@ rewrite_node_address_for_bridge(const bridge_info_t *bridge, node_t *node)
if (node->ri) {
routerinfo_t *ri = node->ri;
tor_addr_from_ipv4h(&addr, ri->addr);
-
if ((!tor_addr_compare(&bridge->addr, &addr, CMP_EXACT) &&
bridge->port == ri->or_port) ||
(!tor_addr_compare(&bridge->addr, &ri->ipv6_addr, CMP_EXACT) &&
@@ -777,16 +776,58 @@ rewrite_node_address_for_bridge(const bridge_info_t *bridge, node_t *node)
routerstatus_t *rs = node->rs;
tor_addr_from_ipv4h(&addr, rs->addr);
- if (!tor_addr_compare(&bridge->addr, &addr, CMP_EXACT) &&
- bridge->port == rs->or_port) {
+ if ((!tor_addr_compare(&bridge->addr, &addr, CMP_EXACT) &&
+ bridge->port == rs->or_port) ||
+ (!tor_addr_compare(&bridge->addr, &rs->ipv6_addr, CMP_EXACT) &&
+ bridge->port == rs->ipv6_orport)) {
/* they match, so no need to do anything */
} else {
- rs->addr = tor_addr_to_ipv4h(&bridge->addr);
- rs->or_port = bridge->port;
- log_info(LD_DIR,
- "Adjusted bridge routerstatus for '%s' to match "
- "configured address %s.",
- rs->nickname, fmt_addrport(&bridge->addr, rs->or_port));
+ if (tor_addr_family(&bridge->addr) == AF_INET) {
+ rs->addr = tor_addr_to_ipv4h(&bridge->addr);
+ rs->or_port = bridge->port;
+ log_info(LD_DIR,
+ "Adjusted bridge routerstatus for '%s' to match "
+ "configured address %s.",
+ rs->nickname, fmt_addrport(&bridge->addr, rs->or_port));
+ /* set IPv6 preferences even if there is no ri */
+ } else if (tor_addr_family(&bridge->addr) == AF_INET6) {
+ tor_addr_copy(&rs->ipv6_addr, &bridge->addr);
+ rs->ipv6_orport = bridge->port;
+ log_info(LD_DIR,
+ "Adjusted bridge routerstatus for '%s' to match configured"
+ " address %s.",
+ rs->nickname, fmt_addrport(&rs->ipv6_addr, rs->ipv6_orport));
+ } else {
+ log_err(LD_BUG, "Address family not supported: %d.",
+ tor_addr_family(&bridge->addr));
+ return;
+ }
+ }
+
+ if (options->ClientPreferIPv6ORPort == -1) {
+ /* Mark which address to use based on which bridge_t we got. */
+ node->ipv6_preferred = (tor_addr_family(&bridge->addr) == AF_INET6 &&
+ !tor_addr_is_null(&node->rs->ipv6_addr));
+ } else {
+ /* Mark which address to use based on user preference */
+ node->ipv6_preferred = (fascist_firewall_prefer_ipv6_orport(options) &&
+ !tor_addr_is_null(&node->rs->ipv6_addr));
+ }
+
+ /* XXXipv6 we lack support for falling back to another address for
+ the same relay, warn the user */
+ if (!tor_addr_is_null(&rs->ipv6_addr)) {
+ tor_addr_port_t ap;
+ node_get_pref_orport(node, &ap);
+ log_notice(LD_CONFIG,
+ "Bridge '%s' has both an IPv4 and an IPv6 address. "
+ "Will prefer using its %s address (%s) based on %s.",
+ rs->nickname,
+ node->ipv6_preferred ? "IPv6" : "IPv4",
+ fmt_addrport(&ap.addr, ap.port),
+ options->ClientPreferIPv6ORPort == -1 ?
+ "the configured Bridge address" :
+ "ClientPreferIPv6ORPort");
}
}
}