node: Rename addrs_in_same_network_family()

New name reflects that the function is only used to compare router addresses
in order to learn if they are in the same network.

The network check is /16 and /32 respectively for IPv4 and IPv6.

Related to #40009

Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
David Goulet
2020-06-30 13:46:53 -04:00
parent 7a6e1f2491
commit 2ac2ba4e2c
4 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -1554,7 +1554,7 @@ guard_in_node_family(const entry_guard_t *guard, const node_t *node)
if (get_options()->EnforceDistinctSubnets && guard->bridge_addr) {
tor_addr_t node_addr;
node_get_addr(node, &node_addr);
if (addrs_in_same_network_family(&node_addr,
if (router_addrs_in_same_network(&node_addr,
&guard->bridge_addr->addr)) {
return 1;
}
+5 -5
View File
@@ -2034,7 +2034,7 @@ nodelist_refresh_countries(void)
/** Return true iff router1 and router2 have similar enough network addresses
* that we should treat them as being in the same family */
int
addrs_in_same_network_family(const tor_addr_t *a1,
router_addrs_in_same_network(const tor_addr_t *a1,
const tor_addr_t *a2)
{
if (tor_addr_is_null(a1) || tor_addr_is_null(a2))
@@ -2150,8 +2150,8 @@ nodes_in_same_family(const node_t *node1, const node_t *node2)
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))
if (router_addrs_in_same_network(&a1, &a2) ||
router_addrs_in_same_network(&ap6_1.addr, &ap6_2.addr))
return 1;
}
@@ -2209,8 +2209,8 @@ nodelist_add_node_and_family(smartlist_t *sl, const node_t *node)
tor_addr_port_t ap6;
node_get_addr(node2, &a);
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))
if (router_addrs_in_same_network(&a, &node_addr) ||
router_addrs_in_same_network(&ap6.addr, &node_ap6.addr))
smartlist_add(sl, (void*)node2);
} SMARTLIST_FOREACH_END(node2);
}
+1 -1
View File
@@ -128,7 +128,7 @@ int node_is_unreliable(const node_t *router, int need_uptime,
int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port,
int need_uptime);
void router_set_status(const char *digest, int up);
int addrs_in_same_network_family(const tor_addr_t *a1,
int router_addrs_in_same_network(const tor_addr_t *a1,
const tor_addr_t *a2);
/** router_have_minimum_dir_info tests to see if we have enough
+5 -5
View File
@@ -1152,23 +1152,23 @@ test_address_tor_addr_in_same_network_family(void *ignored)
tor_addr_parse(&a, "8.8.8.8");
tor_addr_parse(&b, "8.8.4.4");
tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 1);
tt_int_op(router_addrs_in_same_network(&a, &b), OP_EQ, 1);
tor_addr_parse(&a, "8.8.8.8");
tor_addr_parse(&b, "1.1.1.1");
tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 0);
tt_int_op(router_addrs_in_same_network(&a, &b), OP_EQ, 0);
tor_addr_parse(&a, "8.8.8.8");
tor_addr_parse(&b, "2001:4860:4860::8844");
tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 0);
tt_int_op(router_addrs_in_same_network(&a, &b), OP_EQ, 0);
tor_addr_parse(&a, "2001:4860:4860::8888");
tor_addr_parse(&b, "2001:4860:4860::8844");
tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 1);
tt_int_op(router_addrs_in_same_network(&a, &b), OP_EQ, 1);
tor_addr_parse(&a, "2001:4860:4860::8888");
tor_addr_parse(&b, "2001:470:20::2");
tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 0);
tt_int_op(router_addrs_in_same_network(&a, &b), OP_EQ, 0);
done:
return;