[tor-commits] [tor/master] Check IPv6 subnets as well as IPv4 subnets where possible when choosing client paths

nickm at torproject.org nickm at torproject.org
Wed Oct 31 15:07:20 UTC 2018


commit 067b16eae2b7d37c7ec1595226bc7bf26aac1ff5
Author: Neel Chauhan <neel at neelc.org>
Date:   Wed Sep 5 10:12:35 2018 -0400

    Check IPv6 subnets as well as IPv4 subnets where possible when choosing client paths
---
 changes/bug24393                |  6 ++++++
 src/feature/nodelist/nodelist.c | 18 ++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/changes/bug24393 b/changes/bug24393
new file mode 100644
index 000000000..e19019231
--- /dev/null
+++ b/changes/bug24393
@@ -0,0 +1,6 @@
+  o Minor features (ipv6):
+    - When using addrs_in_same_network_family(), check IPv6 subnets as well as
+      IPv4 ones where possible when a client chooses circuit paths. Previously,
+      we used this function only for IPv4 subnets. Closes ticket 24393. Patch
+      by Neel Chauhan.
+
diff --git a/src/feature/nodelist/nodelist.c b/src/feature/nodelist/nodelist.c
index a98a5c865..a1a1b0ea3 100644
--- a/src/feature/nodelist/nodelist.c
+++ b/src/feature/nodelist/nodelist.c
@@ -1867,6 +1867,9 @@ int
 addrs_in_same_network_family(const tor_addr_t *a1,
                              const tor_addr_t *a2)
 {
+  if (tor_addr_is_null(a1) || tor_addr_is_null(a2))
+    return 0;
+
   switch (tor_addr_family(a1)) {
     case AF_INET:
       return 0 == tor_addr_compare_masked(a1, a2, 16, CMP_SEMANTIC);
@@ -1917,7 +1920,13 @@ nodes_in_same_family(const node_t *node1, const node_t *node2)
     tor_addr_t a1, a2;
     node_get_addr(node1, &a1);
     node_get_addr(node2, &a2);
-    if (addrs_in_same_network_family(&a1, &a2))
+
+    tor_addr_port_t ap6_1, ap6_2;
+    node_get_pref_ipv6_orport(node1, &ap6_1);
+    node_get_pref_ipv6_orport(node2, &ap6_2);
+
+    if (addrs_in_same_network_family(&a1, &a2) ||
+        addrs_in_same_network_family(&ap6_1.addr, &ap6_2.addr))
       return 1;
   }
 
@@ -1974,12 +1983,17 @@ nodelist_add_node_and_family(smartlist_t *sl, const node_t *node)
   /* First, add any nodes with similar network addresses. */
   if (options->EnforceDistinctSubnets) {
     tor_addr_t node_addr;
+    tor_addr_port_t node_ap6;
     node_get_addr(node, &node_addr);
+    node_get_pref_ipv6_orport(node, &node_ap6);
 
     SMARTLIST_FOREACH_BEGIN(all_nodes, const node_t *, node2) {
       tor_addr_t a;
+      tor_addr_port_t ap6;
       node_get_addr(node2, &a);
-      if (addrs_in_same_network_family(&a, &node_addr))
+      node_get_pref_ipv6_orport(node2, &ap6);
+      if (addrs_in_same_network_family(&a, &node_addr) ||
+          addrs_in_same_network_family(&ap6.addr, &node_ap6.addr))
         smartlist_add(sl, (void*)node2);
     } SMARTLIST_FOREACH_END(node2);
   }





More information about the tor-commits mailing list