tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

commit fda0fa02bfcf2faef4a973d24877dc7966f6d428
parent bf2b1e7a6f7d0410515468d0b5440d45c0745c5a
Author: David Goulet <dgoulet@torproject.org>
Date:   Fri, 24 Jul 2020 09:19:49 -0400

relay: Add a cache that tracks which address was configured

Related to #33247

Signed-off-by: David Goulet <dgoulet@torproject.org>

Diffstat:
Msrc/app/config/resolve_addr.c | 24++++++++++++++++++++++++
Msrc/app/config/resolve_addr.h | 2++
2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c @@ -55,6 +55,11 @@ static tor_addr_t last_suggested_addrs[] = { TOR_ADDR_NULL, TOR_ADDR_NULL, TOR_ADDR_NULL }; CTASSERT(ARRAY_LENGTH(last_suggested_addrs) == IDX_SIZE); +/** True iff the address was found to be configured that is from the + * configuration file either using Address or ORPort. */ +static bool last_addrs_configured[] = { false, false, false }; +CTASSERT(ARRAY_LENGTH(last_addrs_configured) == IDX_SIZE); + static inline int af_to_idx(const int family) { @@ -94,6 +99,18 @@ resolved_addr_method_to_str(const resolved_addr_method_t method) } } +/** Return true if the last address of family was configured or not. An + * address is considered configured if it was found in the Address or ORPort + * statement. + * + * This applies to the address returned by the function + * resolved_addr_get_last() which is the cache of discovered addresses. */ +bool +resolved_addr_is_configured(int family) +{ + return last_addrs_configured[af_to_idx(family)]; +} + /** Copy the last suggested address of family into addr_out. * * If no last suggested address exists, the addr_out is a null address (use @@ -565,6 +582,13 @@ resolved_addr_set_last(const tor_addr_t *addr, /* Copy address to cache. */ tor_addr_copy(last_resolved, addr); *done_one_resolve = true; + + /* Flag true if the address was configured. Else, indicate it was not. */ + last_addrs_configured[idx] = false; + if (method_used == RESOLVED_ADDR_CONFIGURED || + method_used == RESOLVED_ADDR_CONFIGURED_ORPORT) { + last_addrs_configured[idx] = true; + } } /** Ease our lives. Typedef to the address discovery function signature. */ diff --git a/src/app/config/resolve_addr.h b/src/app/config/resolve_addr.h @@ -49,6 +49,8 @@ void resolved_addr_set_last(const tor_addr_t *addr, void resolved_addr_get_suggested(int family, tor_addr_t *addr_out); void resolved_addr_set_suggested(const tor_addr_t *addr); +bool resolved_addr_is_configured(int family); + MOCK_DECL(bool, is_local_to_resolve_addr, (const tor_addr_t *addr)); #ifdef RESOLVE_ADDR_PRIVATE