aboutsummaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2020-07-24 09:19:49 -0400
committerDavid Goulet <dgoulet@torproject.org>2020-07-24 11:32:49 -0400
commitfda0fa02bfcf2faef4a973d24877dc7966f6d428 (patch)
tree665985bed84cabacba184495f5dc3d771c51b150 /src/app
parentbf2b1e7a6f7d0410515468d0b5440d45c0745c5a (diff)
downloadtor-fda0fa02bfcf2faef4a973d24877dc7966f6d428.tar.gz
tor-fda0fa02bfcf2faef4a973d24877dc7966f6d428.zip
relay: Add a cache that tracks which address was configured
Related to #33247 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/app')
-rw-r--r--src/app/config/resolve_addr.c24
-rw-r--r--src/app/config/resolve_addr.h2
2 files changed, 26 insertions, 0 deletions
diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c
index a9db2655c1..a153d63974 100644
--- 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
index f435f9f41f..96c86eeeea 100644
--- 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