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

[tor-commits] [tor/release-0.4.5] relay: Skip address discovery if no ORPort is found



commit b4f4af6ec5ba16e7ba5191dbd271c1754e0c21d4
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Fri Jan 22 10:23:07 2021 -0500

    relay: Skip address discovery if no ORPort is found
    
    In other words, if we don't have an ORPort configured for a specific family
    (IPv4/v6), we don't bother doing address discovery.
    
    Related to #40254
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/feature/relay/relay_find_addr.c | 13 +++++++++++++
 src/test/test_relay.c               | 33 ++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/src/feature/relay/relay_find_addr.c b/src/feature/relay/relay_find_addr.c
index 2da2328b14..e942a8fa77 100644
--- a/src/feature/relay/relay_find_addr.c
+++ b/src/feature/relay/relay_find_addr.c
@@ -99,6 +99,13 @@ relay_address_new_suggestion(const tor_addr_t *suggested_addr,
  *       populated by the NETINFO cell content or HTTP header from a
  *       directory.
  *
+ * The AddressDisableIPv6 is checked here for IPv6 address discovery and if
+ * set, false is returned and addr_out is UNSPEC.
+ *
+ * Before doing any discovery, the configuration is checked for an ORPort of
+ * the given family. If none can be found, false is returned and addr_out is
+ * UNSPEC.
+ *
  * Return true on success and addr_out contains the address to use for the
  * given family. On failure to find the address, false is returned and
  * addr_out is set to an AF_UNSPEC address. */
@@ -118,6 +125,12 @@ relay_find_addr_to_publish, (const or_options_t *options, int family,
     return false;
   }
 
+  /* There is no point on attempting an address discovery to publish if we
+   * don't have an ORPort for this family. */
+  if (!routerconf_find_or_port(options, family)) {
+    return false;
+  }
+
   /* First, check our resolved address cache. It should contain the address
    * we've discovered from the periodic relay event. */
   resolved_addr_get_last(family, addr_out);
diff --git a/src/test/test_relay.c b/src/test/test_relay.c
index 545cb4ac46..b287f0d38b 100644
--- a/src/test/test_relay.c
+++ b/src/test/test_relay.c
@@ -11,6 +11,7 @@
 #include "feature/stats/bwhist.h"
 #include "core/or/relay.h"
 #include "lib/container/order.h"
+#include "lib/encoding/confline.h"
 /* For init/free stuff */
 #include "core/or/scheduler.h"
 
@@ -23,6 +24,8 @@
 #include "feature/relay/routermode.h"
 #include "feature/dirclient/dir_server_st.h"
 
+#define CONFIG_PRIVATE
+#include "app/config/config.h"
 #include "app/config/resolve_addr.h"
 
 /* Test suite stuff */
@@ -298,11 +301,12 @@ test_find_addr_to_publish(void *arg)
   int family;
   bool ret;
   tor_addr_t ipv4_addr, ipv6_addr, cache_addr;
-  or_options_t options;
+  or_options_t *options;
 
   (void) arg;
 
-  memset(&options, 0, sizeof(options));
+  options = options_new();
+  options_init(options);
 
   /* Populate our resolved cache with a valid IPv4 and IPv6. */
   family = tor_addr_parse(&ipv4_addr, "1.2.3.4");
@@ -317,13 +321,24 @@ test_find_addr_to_publish(void *arg)
   resolved_addr_get_last(AF_INET6, &cache_addr);
   tt_assert(tor_addr_eq(&ipv6_addr, &cache_addr));
 
+  /* Setup ORPort config. */
+  {
+    int n, w, r;
+    char *msg = NULL;
+
+    config_line_append(&options->ORPort_lines, "ORPort", "9001");
+
+    r = parse_ports(options, 0, &msg, &n, &w);
+    tt_int_op(r, OP_EQ, 0);
+  }
+
   /* 1. Address located in the resolved cache. */
-  ret = relay_find_addr_to_publish(&options, AF_INET,
+  ret = relay_find_addr_to_publish(options, AF_INET,
                                    RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
   tt_assert(ret);
   tt_assert(tor_addr_eq(&ipv4_addr, &cache_addr));
 
-  ret = relay_find_addr_to_publish(&options, AF_INET6,
+  ret = relay_find_addr_to_publish(options, AF_INET6,
                                    RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
   tt_assert(ret);
   tt_assert(tor_addr_eq(&ipv6_addr, &cache_addr));
@@ -334,13 +349,13 @@ test_find_addr_to_publish(void *arg)
    *    the find_my_address() code path because that is extensively tested in
    *    another unit tests. */
   resolved_addr_set_suggested(&ipv4_addr);
-  ret = relay_find_addr_to_publish(&options, AF_INET,
+  ret = relay_find_addr_to_publish(options, AF_INET,
                                    RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
   tt_assert(ret);
   tt_assert(tor_addr_eq(&ipv4_addr, &cache_addr));
 
   resolved_addr_set_suggested(&ipv6_addr);
-  ret = relay_find_addr_to_publish(&options, AF_INET6,
+  ret = relay_find_addr_to_publish(options, AF_INET6,
                                    RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
   tt_assert(ret);
   tt_assert(tor_addr_eq(&ipv6_addr, &cache_addr));
@@ -348,15 +363,15 @@ test_find_addr_to_publish(void *arg)
   resolve_addr_reset_suggested(AF_INET6);
 
   /* 3. No IP anywhere. */
-  ret = relay_find_addr_to_publish(&options, AF_INET,
+  ret = relay_find_addr_to_publish(options, AF_INET,
                                    RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
   tt_assert(!ret);
-  ret = relay_find_addr_to_publish(&options, AF_INET6,
+  ret = relay_find_addr_to_publish(options, AF_INET6,
                                    RELAY_FIND_ADDR_CACHE_ONLY, &cache_addr);
   tt_assert(!ret);
 
  done:
-  ;
+  or_options_free(options);
 }
 
 struct testcase_t relay_tests[] = {



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