[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Fill in missing IPv6 addresses in extend cells



commit 48310a0e76b2d8d708190db62b3ee9fc290d33e4
Author: Neel Chauhan <neel@xxxxxxxxx>
Date:   Tue Jun 9 21:36:54 2020 -0700

    Fill in missing IPv6 addresses in extend cells
---
 src/feature/relay/circuitbuild_relay.c | 52 ++++++++++++++++++++++++++++++++++
 src/feature/relay/circuitbuild_relay.h |  2 ++
 2 files changed, 54 insertions(+)

diff --git a/src/feature/relay/circuitbuild_relay.c b/src/feature/relay/circuitbuild_relay.c
index b89866b47..9ecba05e8 100644
--- a/src/feature/relay/circuitbuild_relay.c
+++ b/src/feature/relay/circuitbuild_relay.c
@@ -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);
diff --git a/src/feature/relay/circuitbuild_relay.h b/src/feature/relay/circuitbuild_relay.h
index 078316153..dc0b886a3 100644
--- a/src/feature/relay/circuitbuild_relay.h
+++ b/src/feature/relay/circuitbuild_relay.h
@@ -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(



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits