Fill in missing IPv6 addresses in extend cells

This commit is contained in:
Neel Chauhan 2020-06-09 21:36:54 -07:00 committed by Nick Mathewson
parent 3cb77a9cca
commit 48310a0e76
2 changed files with 54 additions and 0 deletions

View File

@ -122,6 +122,52 @@ circuit_extend_add_ed25519_helper(struct extend_cell_t *ec)
return 0;
}
/* Make sure the extend cell <b>ec</b> has an IPv4 address if the relay
* supports in, and if not, fill it in. */
STATIC int
circuit_extend_add_ipv4_helper(struct extend_cell_t *ec)
{
IF_BUG_ONCE(!ec) {
return -1;
}
const node_t *node = node_get_by_id((const char *) ec->node_id);
if (node) {
tor_addr_port_t node_ipv4;
node_get_prim_orport(node, &node_ipv4);
if (tor_addr_is_null(&ec->orport_ipv4.addr) &&
!tor_addr_is_null(&node_ipv4.addr)) {
tor_addr_copy(&ec->orport_ipv4.addr, &node_ipv4.addr);
ec->orport_ipv4.port = node_ipv4.port;
}
}
return 0;
}
/* Make sure the extend cell <b>ec</b> has an IPv6 address if the relay
* supports in, and if not, fill it in. */
STATIC int
circuit_extend_add_ipv6_helper(struct extend_cell_t *ec)
{
IF_BUG_ONCE(!ec) {
return -1;
}
const node_t *node = node_get_by_id((const char *) ec->node_id);
if (node) {
tor_addr_port_t node_ipv6;
node_get_pref_ipv6_orport(node, &node_ipv6);
if (tor_addr_is_null(&ec->orport_ipv6.addr) &&
!tor_addr_is_null(&node_ipv6.addr)) {
tor_addr_copy(&ec->orport_ipv6.addr, &node_ipv6.addr);
ec->orport_ipv6.port = node_ipv6.port;
}
}
return 0;
}
/* Check if the address and port in the tor_addr_port_t <b>ap</b> are valid,
* and are allowed by the current ExtendAllowPrivateAddresses config.
*
@ -412,6 +458,12 @@ circuit_extend(struct cell_t *cell, struct circuit_t *circ)
if (circuit_extend_lspec_valid_helper(&ec, circ) < 0)
return -1;
if (circuit_extend_add_ipv4_helper(&ec) < 0)
return -1;
if (circuit_extend_add_ipv6_helper(&ec) < 0)
return -1;
/* Check the addresses, without logging */
const int ipv4_valid = circuit_extend_addr_port_is_valid(&ec.orport_ipv4,
false, false, 0);

View File

@ -73,6 +73,8 @@ onionskin_answer(struct or_circuit_t *circ,
STATIC int circuit_extend_state_valid_helper(const struct circuit_t *circ);
STATIC int circuit_extend_add_ed25519_helper(struct extend_cell_t *ec);
STATIC int circuit_extend_add_ipv4_helper(struct extend_cell_t *ec);
STATIC int circuit_extend_add_ipv6_helper(struct extend_cell_t *ec);
STATIC int circuit_extend_lspec_valid_helper(const struct extend_cell_t *ec,
const struct circuit_t *circ);
STATIC const tor_addr_port_t * circuit_choose_ip_ap_for_extend(