]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
relay: Avoid a directory early fetch
authorDavid Goulet <dgoulet@torproject.org>
Tue, 23 Feb 2021 14:37:17 +0000 (09:37 -0500)
committerDavid Goulet <dgoulet@torproject.org>
Tue, 23 Feb 2021 14:49:45 +0000 (09:49 -0500)
The directory_fetches_from_authorities() is used to know if a client or relay
should fetch data from an authority early in the boot process.

We had a condition in that function that made a relay trigger that fetch if it
didn't know its address (so we can learn it). However, when this is called,
the address discovery has not been done yet so it would always return true for
a relay.

Furthermore, it would always trigger a log notice that the IPv4 couldn't be
found which was inevitable because the address discovery process has not been
done yet (done when building our first descriptor).

It is also important to point out that starting in 0.4.5.1-alpha, asking an
authority for an address is done during address discovery time using a one-hop
circuit thus independent from the relay deciding to fetch or not documents
from an authority.

Small fix also is to reverse the "IPv(4|6)Only" flag in the notice so that if
we can't find IPv6 it would output to use IPv4Only.

Fixes #40300

Signed-off-by: David Goulet <dgoulet@torproject.org>
changes/ticket40300
src/feature/dirclient/dirclient_modes.c
src/feature/relay/relay_find_addr.c
src/feature/relay/relay_find_addr.h
src/test/test_config.c

index aef01b4c64de0a6b45bace3d96774bc77455d989..b772ff60a4d8b722c1b3aad9bc49ab149a57d69b 100644 (file)
@@ -2,4 +2,7 @@
     - Remove a spammy log notice that should not have been indicating the
       operator that its IPv4/v6 was missing but it was not. Fixes bug 40300;
       bugfix on 0.4.5.1-alpha.
-
+    - Do not query the address cache early in the boot process when deciding
+      if we a relay needs to fetch early directory information from an
+      authority. This resulted in a relay falsely believing it didn't have an
+      address and thus triggering an authority fetch at each boot.
index 62cdad6c36622386d68ba60d78e7719d43ad11e5..db251962139dd280e7b49cb169d4cbeeed17f711 100644 (file)
@@ -45,14 +45,6 @@ dirclient_fetches_from_authorities(const or_options_t *options)
     return 1;
   if (options->BridgeRelay == 1)
     return 0;
-  /* We don't know our IP address; ask an authority. IPv4 is still mandatory
-   * to have thus if we don't have it, we ought to learn it from an authority
-   * through the NETINFO cell or the HTTP header it sends us back.
-   *
-   * Note that at the moment, relay do a direct connection so no NETINFO cell
-   * for now. */
-  if (server_mode(options) && !relay_has_address_set(AF_INET))
-    return 1;
   refuseunknown = ! router_my_exit_policy_is_reject_star() &&
     should_refuse_unknown_exits(options);
   if (!dir_server_mode(options) && !refuseunknown)
index 2a3f602438e36fd74fab8efa6c73bfdf89c60c0b..c43885af51eeb50e4f777d156a629d8406d40d8d 100644 (file)
@@ -162,7 +162,8 @@ relay_find_addr_to_publish, (const or_options_t *options, int family,
                  "explicit address or set Address.",
                  fmt_af_family(family),
                  routerconf_find_or_port(options, family),
-                 fmt_af_family(family));
+                 (family == AF_INET) ? fmt_af_family(AF_INET6) :
+                                       fmt_af_family(AF_INET));
 
   /* Not found. */
   return false;
@@ -171,18 +172,6 @@ relay_find_addr_to_publish, (const or_options_t *options, int family,
   return true;
 }
 
-/** Return true iff this relay has an address set for the given family.
- *
- * This only checks the caches so it will not trigger a full discovery of the
- * address. */
-bool
-relay_has_address_set(int family)
-{
-  tor_addr_t addr;
-  return relay_find_addr_to_publish(get_options(), family,
-                                    RELAY_FIND_ADDR_CACHE_ONLY, &addr);
-}
-
 /** How often should we launch a circuit to an authority to be sure of getting
  * a guess for our IP? */
 #define DUMMY_DOWNLOAD_INTERVAL (20*60)
index 34890cd34ec78f7957c84cdf6217982e5483e7a1..f049d1bd200071a05fcfb014959aa29dfc965a23 100644 (file)
@@ -22,8 +22,6 @@ MOCK_DECL(bool, relay_find_addr_to_publish,
           (const or_options_t *options, int family, int flags,
            tor_addr_t *addr_out));
 
-bool relay_has_address_set(int family);
-
 void relay_addr_learn_from_dirauth(void);
 
 #ifdef RELAY_FIND_ADDR_PRIVATE
index 73c8ca054969463b069489b2d18b9e004da27064..655535f704915f805d4c1df79d1bb0aed8d9ef08 100644 (file)
@@ -3982,27 +3982,6 @@ test_config_directory_fetch(void *arg)
   tt_int_op(networkstatus_consensus_can_use_multiple_directories(options),
             OP_EQ, 1);
 
-  /* OR servers only fetch the consensus from the authorities when they don't
-   * know their own address, but never use multiple directories for bootstrap
-   */
-  or_options_free(options);
-  options = options_new();
-  options->ORPort_set = 1;
-
-  mock_relay_find_addr_to_publish_result = false;
-  tt_assert(server_mode(options) == 1);
-  tt_assert(public_server_mode(options) == 1);
-  tt_int_op(dirclient_fetches_from_authorities(options), OP_EQ, 1);
-  tt_int_op(networkstatus_consensus_can_use_multiple_directories(options),
-            OP_EQ, 0);
-
-  mock_relay_find_addr_to_publish_result = true;
-  tt_assert(server_mode(options) == 1);
-  tt_assert(public_server_mode(options) == 1);
-  tt_int_op(dirclient_fetches_from_authorities(options), OP_EQ, 0);
-  tt_int_op(networkstatus_consensus_can_use_multiple_directories(options),
-            OP_EQ, 0);
-
   /* Exit OR servers only fetch the consensus from the authorities when they
    * refuse unknown exits, but never use multiple directories for bootstrap
    */