[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] relay: Turn find address "method_used" into enum
commit bf2b1e7a6f7d0410515468d0b5440d45c0745c5a
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date: Fri Jul 24 09:19:19 2020 -0400
relay: Turn find address "method_used" into enum
Enum allows us to easily compare what is being returned but also better
semantic to the code.
Related #33247
Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
src/app/config/resolve_addr.c | 111 +++++++++++++++++++++++++++---------------
src/app/config/resolve_addr.h | 24 ++++++++-
src/feature/relay/router.c | 4 +-
src/test/test_config.c | 55 +++++++++++----------
src/test/test_relay.c | 4 +-
5 files changed, 126 insertions(+), 72 deletions(-)
diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c
index 798c703f0a..a9db2655c1 100644
--- a/src/app/config/resolve_addr.c
+++ b/src/app/config/resolve_addr.c
@@ -71,6 +71,29 @@ af_to_idx(const int family)
}
}
+/** Return string representation of the given method. */
+const char *
+resolved_addr_method_to_str(const resolved_addr_method_t method)
+{
+ switch (method) {
+ case RESOLVED_ADDR_NONE:
+ return "NONE";
+ case RESOLVED_ADDR_CONFIGURED:
+ return "CONFIGURED";
+ case RESOLVED_ADDR_CONFIGURED_ORPORT:
+ return "CONFIGURED_ORPORT";
+ case RESOLVED_ADDR_GETHOSTNAME:
+ return "GETHOSTNAME";
+ case RESOLVED_ADDR_INTERFACE:
+ return "INTERFACE";
+ case RESOLVED_ADDR_RESOLVED:
+ return "RESOLVED";
+ default:
+ tor_assert_nonfatal_unreached();
+ return "???";
+ }
+}
+
/** Copy the last suggested address of family into addr_out.
*
* If no last suggested address exists, the addr_out is a null address (use
@@ -178,8 +201,8 @@ address_can_be_used(const tor_addr_t *addr, const or_options_t *options,
* @param options Global configuration options.
* @param warn_severity Log level that should be used on error.
* @param family IP address family. Only AF_INET and AF_INET6 are supported.
- * @param method_out OUT: String denoting by which method the address was
- * found. This is described in the control-spec.txt as
+ * @param method_out OUT: Method denoting how the address was found.
+ * This is described in the control-spec.txt as
* actions for "STATUS_SERVER".
* @param hostname_out OUT: String containing the hostname gotten from the
* Address value if any.
@@ -191,7 +214,7 @@ address_can_be_used(const tor_addr_t *addr, const or_options_t *options,
*/
static fn_address_ret_t
get_address_from_config(const or_options_t *options, int warn_severity,
- int family, const char **method_out,
+ int family, resolved_addr_method_t *method_out,
char **hostname_out, tor_addr_t *addr_out)
{
int ret;
@@ -205,7 +228,7 @@ get_address_from_config(const or_options_t *options, int warn_severity,
/* Set them to NULL for safety reasons. */
*hostname_out = NULL;
- *method_out = NULL;
+ *method_out = RESOLVED_ADDR_NONE;
log_debug(LD_CONFIG, "Attempting to get address from configuration");
@@ -223,7 +246,7 @@ get_address_from_config(const or_options_t *options, int warn_severity,
af = tor_addr_parse(&addr, cfg->value);
if (af == family) {
tor_addr_copy(addr_out, &addr);
- *method_out = "CONFIGURED";
+ *method_out = RESOLVED_ADDR_CONFIGURED;
explicit_ip = true;
num_valid_addr++;
continue;
@@ -237,7 +260,7 @@ get_address_from_config(const or_options_t *options, int warn_severity,
* do a DNS lookup. */
if (!tor_addr_lookup(cfg->value, family, &addr)) {
tor_addr_copy(addr_out, &addr);
- *method_out = "RESOLVED";
+ *method_out = RESOLVED_ADDR_RESOLVED;
if (*hostname_out) {
tor_free(*hostname_out);
}
@@ -299,8 +322,8 @@ get_address_from_config(const or_options_t *options, int warn_severity,
* @param options Global configuration options.
* @param warn_severity Log level that should be used on error.
* @param family IP address family. Only AF_INET and AF_INET6 are supported.
- * @param method_out OUT: String denoting by which method the address was
- * found. This is described in the control-spec.txt as
+ * @param method_out OUT: Method denoting how the address was found.
+ * This is described in the control-spec.txt as
* actions for "STATUS_SERVER".
* @param hostname_out OUT: String containing the local hostname.
* @param addr_out OUT: Tor address resolved from the local hostname.
@@ -310,7 +333,7 @@ get_address_from_config(const or_options_t *options, int warn_severity,
*/
static fn_address_ret_t
get_address_from_hostname(const or_options_t *options, int warn_severity,
- int family, const char **method_out,
+ int family, resolved_addr_method_t *method_out,
char **hostname_out, tor_addr_t *addr_out)
{
int ret;
@@ -321,7 +344,7 @@ get_address_from_hostname(const or_options_t *options, int warn_severity,
/* Set them to NULL for safety reasons. */
*hostname_out = NULL;
- *method_out = NULL;
+ *method_out = RESOLVED_ADDR_NONE;
log_debug(LD_CONFIG, "Attempting to get address from local hostname");
@@ -347,7 +370,7 @@ get_address_from_hostname(const or_options_t *options, int warn_severity,
}
/* addr_out contains the address of the local hostname. */
- *method_out = "GETHOSTNAME";
+ *method_out = RESOLVED_ADDR_GETHOSTNAME;
*hostname_out = tor_strdup(hostname);
/* Found it! */
@@ -361,8 +384,9 @@ get_address_from_hostname(const or_options_t *options, int warn_severity,
* @param options Global configuration options.
* @param warn_severity Log level that should be used on error.
* @param family IP address family. Only AF_INET and AF_INET6 are supported.
- * @param method_out OUT: Always "INTERFACE" on success which is detailed in
- * the control-spec.txt as actions for "STATUS_SERVER".
+ * @param method_out OUT: Always RESOLVED_ADDR_INTERFACE on success which
+ * is detailed in the control-spec.txt as actions
+ * for "STATUS_SERVER".
* @param hostname_out OUT: String containing the local hostname. For this
* function, it is always set to NULL.
* @param addr_out OUT: Tor address found attached to the interface.
@@ -372,7 +396,7 @@ get_address_from_hostname(const or_options_t *options, int warn_severity,
*/
static fn_address_ret_t
get_address_from_interface(const or_options_t *options, int warn_severity,
- int family, const char **method_out,
+ int family, resolved_addr_method_t *method_out,
char **hostname_out, tor_addr_t *addr_out)
{
int ret;
@@ -382,7 +406,7 @@ get_address_from_interface(const or_options_t *options, int warn_severity,
tor_assert(addr_out);
/* Set them to NULL for safety reasons. */
- *method_out = NULL;
+ *method_out = RESOLVED_ADDR_NONE;
*hostname_out = NULL;
log_debug(LD_CONFIG, "Attempting to get address from network interface");
@@ -400,7 +424,7 @@ get_address_from_interface(const or_options_t *options, int warn_severity,
return FN_RET_NEXT;
}
- *method_out = "INTERFACE";
+ *method_out = RESOLVED_ADDR_INTERFACE;
/* Found it! */
log_info(LD_CONFIG, "Address found from interface: %s", fmt_addr(addr_out));
@@ -412,8 +436,8 @@ get_address_from_interface(const or_options_t *options, int warn_severity,
* @param options Global configuration options.
* @param warn_severity Log level that should be used on error.
* @param family IP address family. Only AF_INET and AF_INET6 are supported.
- * @param method_out OUT: Always "CONFIGURED_ORPORT" on success which is
- * detailed in the control-spec.txt as actions
+ * @param method_out OUT: Always RESOLVED_ADDR_CONFIGURED_ORPORT on success
+ * which is detailed in the control-spec.txt as actions
* for "STATUS_SERVER".
* @param hostname_out OUT: String containing the ORPort hostname if any.
* @param addr_out OUT: Tor address found if any.
@@ -423,7 +447,7 @@ get_address_from_interface(const or_options_t *options, int warn_severity,
*/
static fn_address_ret_t
get_address_from_orport(const or_options_t *options, int warn_severity,
- int family, const char **method_out,
+ int family, resolved_addr_method_t *method_out,
char **hostname_out, tor_addr_t *addr_out)
{
int ret;
@@ -433,6 +457,10 @@ get_address_from_orport(const or_options_t *options, int warn_severity,
tor_assert(hostname_out);
tor_assert(addr_out);
+ /* Set them to NULL for safety reasons. */
+ *method_out = RESOLVED_ADDR_NONE;
+ *hostname_out = NULL;
+
log_debug(LD_CONFIG, "Attempting to get address from ORPort");
if (!options->ORPort_set) {
@@ -456,7 +484,7 @@ get_address_from_orport(const or_options_t *options, int warn_severity,
}
/* Found it! */
- *method_out = "CONFIGURED_ORPORT";
+ *method_out = RESOLVED_ADDR_CONFIGURED_ORPORT;
tor_addr_copy(addr_out, addr);
log_fn(warn_severity, LD_CONFIG, "Address found from ORPort: %s",
@@ -481,7 +509,8 @@ get_address_from_orport(const or_options_t *options, int warn_severity,
* NULL. (for logging and control port).
*/
void
-resolved_addr_set_last(const tor_addr_t *addr, const char *method_used,
+resolved_addr_set_last(const tor_addr_t *addr,
+ const resolved_addr_method_t method_used,
const char *hostname_used)
{
/** Have we done a first resolve. This is used to control logging. */
@@ -493,7 +522,6 @@ resolved_addr_set_last(const tor_addr_t *addr, const char *method_used,
tor_addr_t *last_resolved;
tor_assert(addr);
- tor_assert(method_used);
/* Do we have an hostname. */
have_hostname = (hostname_used != NULL);
@@ -520,7 +548,8 @@ resolved_addr_set_last(const tor_addr_t *addr, const char *method_used,
log_notice(LD_NET,
"Your IP address seems to have changed to %s "
"(METHOD=%s%s%s). Updating.",
- fmt_addr(addr), method_used,
+ fmt_addr(addr),
+ resolved_addr_method_to_str(method_used),
have_hostname ? " HOSTNAME=" : "",
have_hostname ? hostname_used : "");
ip_address_changed(0);
@@ -529,7 +558,8 @@ resolved_addr_set_last(const tor_addr_t *addr, const char *method_used,
/* Notify control port. */
control_event_server_status(LOG_NOTICE,
"EXTERNAL_ADDRESS ADDRESS=%s METHOD=%s%s%s",
- fmt_addr(addr), method_used,
+ fmt_addr(addr),
+ resolved_addr_method_to_str(method_used),
have_hostname ? " HOSTNAME=" : "",
have_hostname ? hostname_used : "");
/* Copy address to cache. */
@@ -541,7 +571,8 @@ resolved_addr_set_last(const tor_addr_t *addr, const char *method_used,
typedef fn_address_ret_t
(*fn_address_t)(
const or_options_t *options, int warn_severity, int family,
- const char **method_out, char **hostname_out, tor_addr_t *addr_out);
+ resolved_addr_method_t *method_out, char **hostname_out,
+ tor_addr_t *addr_out);
/** Address discovery function table. The order matters as in the first one is
* executed first and so on. */
@@ -586,16 +617,16 @@ static const size_t fn_address_table_auth_len =
* 1. Look at the configuration Address option.
* If Address is a public address, True is returned and addr_out is set
- * with it, the method_out is set to "CONFIGURED" and hostname_out is set
- * to NULL.
+ * with it, the method_out is set to RESOLVED_ADDR_CONFIGURED and
+ * hostname_out is set to NULL.
*
* If Address is an internal address but NO custom authorities are used,
* an error is returned.
*
* If Address is a hostname, that is it can't be converted to an address,
* it is resolved. On success, addr_out is set with the address,
- * method_out is set to "RESOLVED" and hostname_out is set to the resolved
- * hostname. On failure to resolve, an error is returned.
+ * method_out is set to RESOLVED_ADDR_RESOLVED and hostname_out is set
+ * to the resolved hostname. On failure to resolve, an error is returned.
*
* If no given Address, fallback to the local hostname (see section 2).
*
@@ -606,14 +637,14 @@ static const size_t fn_address_table_auth_len =
*
* On failure, we attempt to look at the local hostname (3).
*
- * On success, addr_out is set with it, method_out is set to "INTERFACE"
- * and hostname_out is set to NULL.
+ * On success, addr_out is set with it, method_out is set to
+ * RESOLVED_ADDR_INTERFACE and hostname_out is set to NULL.
*
* 3. Look at the local hostname.
*
* If the local hostname resolves to a non internal address, addr_out is
- * set with it, method_out is set to "GETHOSTNAME" and hostname_out is set
- * to the resolved hostname.
+ * set with it, method_out is set to RESOLVED_ADDR_GETHOSTNAME and
+ * hostname_out is set to the resolved hostname.
*
* If a local hostname can NOT be found, an error is returned.
*
@@ -626,11 +657,11 @@ static const size_t fn_address_table_auth_len =
* @param family IP address family. Only AF_INET and AF_INET6 are supported.
* @param warn_severity Logging level.
* @param addr_out OUT: Set with the IP address found if any.
- * @param method_out OUT: (optional) String denoting by which method the
- * address was found. This is described in the
- * control-spec.txt as actions for "STATUS_SERVER".
+ * @param method_out OUT: (optional) Method denoting how the address wa
+ * found. This is described in the control-spec.txt as
+ * actions for "STATUS_SERVER".
* @param hostname_out OUT: String containing the hostname if any was used.
- * Only be set for "RESOLVED" and "GETHOSTNAME" methods.
+ * Only be set for RESOLVED and GETHOSTNAME methods.
* Else it is set to NULL.
*
* @return True if the address was found for the given family. False if not or
@@ -638,10 +669,10 @@ static const size_t fn_address_table_auth_len =
*/
bool
find_my_address(const or_options_t *options, int family, int warn_severity,
- tor_addr_t *addr_out, const char **method_out,
+ tor_addr_t *addr_out, resolved_addr_method_t *method_out,
char **hostname_out)
{
- const char *method_used = NULL;
+ resolved_addr_method_t method_used = RESOLVED_ADDR_NONE;
char *hostname_used = NULL;
tor_addr_t my_addr;
const fn_address_t *table = fn_address_table;
@@ -652,7 +683,7 @@ find_my_address(const or_options_t *options, int family, int warn_severity,
/* Set them to NULL for safety reasons. */
tor_addr_make_unspec(addr_out);
- if (method_out) *method_out = NULL;
+ if (method_out) *method_out = RESOLVED_ADDR_NONE;
if (hostname_out) *hostname_out = NULL;
/* If an IPv6 is requested, check if IPv6 address discovery is disabled and
diff --git a/src/app/config/resolve_addr.h b/src/app/config/resolve_addr.h
index c279d19f6e..f435f9f41f 100644
--- a/src/app/config/resolve_addr.h
+++ b/src/app/config/resolve_addr.h
@@ -14,16 +14,36 @@
#include "app/config/or_options_st.h"
+/** Method used to resolved an address. In other words, how was the address
+ * discovered by tor. */
+typedef enum {
+ /* Default value. Indiate that no method found the address. */
+ RESOLVED_ADDR_NONE = 0,
+ /* Found from the "Address" configuration option. */
+ RESOLVED_ADDR_CONFIGURED = 1,
+ /* Found from the "ORPort" configuration option. */
+ RESOLVED_ADDR_CONFIGURED_ORPORT = 2,
+ /* Found by resolving the local hostname. */
+ RESOLVED_ADDR_GETHOSTNAME = 3,
+ /* Found by querying the local interface(s). */
+ RESOLVED_ADDR_INTERFACE = 4,
+ /* Found by resolving the hostname from the Address configuration option. */
+ RESOLVED_ADDR_RESOLVED = 5,
+} resolved_addr_method_t;
+
+const char *resolved_addr_method_to_str(const resolved_addr_method_t method);
+
#define get_orport_addr(family) \
(portconf_get_first_advertised_addr(CONN_TYPE_OR_LISTENER, family))
bool find_my_address(const or_options_t *options, int family,
int warn_severity, tor_addr_t *addr_out,
- const char **method_out, char **hostname_out);
+ resolved_addr_method_t *method_out, char **hostname_out);
void resolved_addr_get_last(int family, tor_addr_t *addr_out);
void resolved_addr_reset_last(int family);
-void resolved_addr_set_last(const tor_addr_t *addr, const char *method_used,
+void resolved_addr_set_last(const tor_addr_t *addr,
+ const resolved_addr_method_t method_used,
const char *hostname_used);
void resolved_addr_get_suggested(int family, tor_addr_t *addr_out);
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index 206545bdec..01d8bdcc87 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -2598,7 +2598,7 @@ void
check_descriptor_ipaddress_changed(time_t now)
{
const routerinfo_t *my_ri = router_get_my_routerinfo();
- const char *method = NULL;
+ resolved_addr_method_t method = RESOLVED_ADDR_NONE;
char *hostname = NULL;
int families[2] = { AF_INET, AF_INET6 };
bool has_changed = false;
@@ -2629,7 +2629,7 @@ check_descriptor_ipaddress_changed(time_t now)
if (!tor_addr_eq(previous, ¤t)) {
char *source;
tor_asprintf(&source, "METHOD=%s%s%s",
- method ? method : "UNKNOWN",
+ resolved_addr_method_to_str(method),
hostname ? " HOSTNAME=" : "",
hostname ? hostname : "");
log_addr_has_changed(LOG_NOTICE, previous, ¤t, source);
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 121b51e925..9eadfeed33 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -1244,8 +1244,7 @@ get_interface_address6_failure(int severity, sa_family_t family,
#define VALIDATE_FOUND_ADDRESS(ret, method, hostname) \
do { \
tt_int_op(retval, OP_EQ, ret); \
- if (method == NULL) tt_assert(!method_used); \
- else tt_str_op(method_used, OP_EQ, method); \
+ tt_int_op(method, OP_EQ, method_used); \
if (hostname == NULL) tt_assert(!hostname_out); \
else tt_str_op(hostname_out, OP_EQ, hostname); \
if (ret == true) { \
@@ -1274,7 +1273,7 @@ test_config_find_my_address_mixed(void *arg)
{
or_options_t *options;
tor_addr_t resolved_addr, test_addr;
- const char *method_used;
+ resolved_addr_method_t method_used;
char *hostname_out = NULL;
bool retval;
@@ -1294,7 +1293,7 @@ test_config_find_my_address_mixed(void *arg)
/* IPv6 address should be found and considered configured. */
retval = find_my_address(options, AF_INET6, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "CONFIGURED", NULL);
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_CONFIGURED, NULL);
CLEANUP_FOUND_ADDRESS;
@@ -1309,13 +1308,13 @@ test_config_find_my_address_mixed(void *arg)
/* IPv4 address should be found and considered configured. */
retval = find_my_address(options, AF_INET, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "CONFIGURED", NULL);
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_CONFIGURED, NULL);
/* IPv6 address should be found and considered configured. */
tor_addr_parse(&test_addr, "2a01:4f8:fff0:4f:266:37ff:fe2c:5d19");
retval = find_my_address(options, AF_INET6, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "CONFIGURED", NULL);
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_CONFIGURED, NULL);
CLEANUP_FOUND_ADDRESS;
@@ -1332,14 +1331,16 @@ test_config_find_my_address_mixed(void *arg)
tor_addr_parse(&test_addr, "1.1.1.1");
retval = find_my_address(options, AF_INET, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "RESOLVED", "www.torproject.org.v4");
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_RESOLVED,
+ "www.torproject.org.v4");
tor_free(hostname_out);
/* IPv6 address should be found and considered resolved. */
tor_addr_parse(&test_addr, "0101::0101");
retval = find_my_address(options, AF_INET6, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "RESOLVED", "www.torproject.org.v6");
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_RESOLVED,
+ "www.torproject.org.v6");
CLEANUP_FOUND_ADDRESS;
UNMOCK(tor_addr_lookup);
@@ -1357,13 +1358,14 @@ test_config_find_my_address_mixed(void *arg)
tor_addr_parse(&test_addr, "1.1.1.1");
retval = find_my_address(options, AF_INET, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "CONFIGURED", NULL);
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_CONFIGURED, NULL);
/* IPv6 address should be found and considered resolved. */
tor_addr_parse(&test_addr, "0101::0101");
retval = find_my_address(options, AF_INET6, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "RESOLVED", "www.torproject.org.v6");
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_RESOLVED,
+ "www.torproject.org.v6");
CLEANUP_FOUND_ADDRESS;
UNMOCK(tor_addr_lookup);
@@ -1381,14 +1383,15 @@ test_config_find_my_address_mixed(void *arg)
tor_addr_parse(&test_addr, "1.1.1.1");
retval = find_my_address(options, AF_INET, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "RESOLVED", "www.torproject.org.v4");
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_RESOLVED,
+ "www.torproject.org.v4");
tor_free(hostname_out);
/* IPv6 address should be found and considered resolved. */
tor_addr_parse(&test_addr, "0101::0101");
retval = find_my_address(options, AF_INET6, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "CONFIGURED", NULL);
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_CONFIGURED, NULL);
CLEANUP_FOUND_ADDRESS;
UNMOCK(tor_addr_lookup);
@@ -1439,7 +1442,7 @@ test_config_find_my_address(void *arg)
{
or_options_t *options;
tor_addr_t resolved_addr, test_addr;
- const char *method_used;
+ resolved_addr_method_t method_used;
char *hostname_out = NULL;
bool retval;
int prev_n_hostname_01010101;
@@ -1470,7 +1473,7 @@ test_config_find_my_address(void *arg)
retval = find_my_address(options, p->family, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(false, NULL, NULL);
+ VALIDATE_FOUND_ADDRESS(false, RESOLVED_ADDR_NONE, NULL);
CLEANUP_FOUND_ADDRESS;
}
@@ -1486,7 +1489,7 @@ test_config_find_my_address(void *arg)
retval = find_my_address(options, p->family, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "CONFIGURED", NULL);
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_CONFIGURED, NULL);
CLEANUP_FOUND_ADDRESS;
/*
@@ -1503,7 +1506,7 @@ test_config_find_my_address(void *arg)
&method_used, &hostname_out);
tt_int_op(n_hostname_01010101, OP_EQ, ++prev_n_hostname_01010101);
- VALIDATE_FOUND_ADDRESS(true, "RESOLVED", "www.torproject.org");
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_RESOLVED, "www.torproject.org");
CLEANUP_FOUND_ADDRESS;
UNMOCK(tor_addr_lookup);
@@ -1523,7 +1526,7 @@ test_config_find_my_address(void *arg)
"public IP addresses.");
teardown_capture_of_logs();
- VALIDATE_FOUND_ADDRESS(false, NULL, NULL);
+ VALIDATE_FOUND_ADDRESS(false, RESOLVED_ADDR_NONE, NULL);
CLEANUP_FOUND_ADDRESS;
/*
@@ -1537,7 +1540,7 @@ test_config_find_my_address(void *arg)
retval = find_my_address(options, p->family, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "CONFIGURED", NULL);
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_CONFIGURED, NULL);
CLEANUP_FOUND_ADDRESS;
/*
@@ -1554,7 +1557,7 @@ test_config_find_my_address(void *arg)
expect_log_msg_containing("Found 2 Address statement of address family");
teardown_capture_of_logs();
- VALIDATE_FOUND_ADDRESS(false, NULL, NULL);
+ VALIDATE_FOUND_ADDRESS(false, RESOLVED_ADDR_NONE, NULL);
CLEANUP_FOUND_ADDRESS;
/*
@@ -1575,7 +1578,7 @@ test_config_find_my_address(void *arg)
&method_used, &hostname_out);
tt_int_op(n_get_interface_address6, OP_EQ, ++prev_n_get_interface_address6);
- VALIDATE_FOUND_ADDRESS(true, "INTERFACE", NULL);
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_INTERFACE, NULL);
CLEANUP_FOUND_ADDRESS;
UNMOCK(get_interface_address6);
@@ -1608,7 +1611,7 @@ test_config_find_my_address(void *arg)
++prev_n_hostname_01010101);
tt_int_op(n_gethostname_replacement, OP_EQ,
++prev_n_gethostname_replacement);
- VALIDATE_FOUND_ADDRESS(true, "GETHOSTNAME", "onionrouter!");
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_GETHOSTNAME, "onionrouter!");
CLEANUP_FOUND_ADDRESS;
UNMOCK(get_interface_address6);
@@ -1642,7 +1645,7 @@ test_config_find_my_address(void *arg)
++prev_n_hostname_localhost);
tt_int_op(n_gethostname_localhost, OP_EQ,
++prev_n_gethostname_localhost);
- VALIDATE_FOUND_ADDRESS(false, NULL, NULL);
+ VALIDATE_FOUND_ADDRESS(false, RESOLVED_ADDR_NONE, NULL);
CLEANUP_FOUND_ADDRESS;
UNMOCK(get_interface_address6);
@@ -1672,7 +1675,7 @@ test_config_find_my_address(void *arg)
++prev_n_get_interface_address6_failure);
tt_int_op(n_gethostname_failure, OP_EQ,
++prev_n_gethostname_failure);
- VALIDATE_FOUND_ADDRESS(false, NULL, NULL);
+ VALIDATE_FOUND_ADDRESS(false, RESOLVED_ADDR_NONE, NULL);
CLEANUP_FOUND_ADDRESS;
UNMOCK(get_interface_address6);
@@ -1705,7 +1708,7 @@ test_config_find_my_address(void *arg)
++prev_n_gethostname_replacement);
tt_int_op(n_hostname_failure, OP_EQ,
++prev_n_hostname_failure);
- VALIDATE_FOUND_ADDRESS(false, NULL, NULL);
+ VALIDATE_FOUND_ADDRESS(false, RESOLVED_ADDR_NONE, NULL);
CLEANUP_FOUND_ADDRESS;
/*
@@ -1736,7 +1739,7 @@ test_config_find_my_address(void *arg)
retval = find_my_address(options, p->family, LOG_NOTICE, &resolved_addr,
&method_used, &hostname_out);
- VALIDATE_FOUND_ADDRESS(true, "CONFIGURED_ORPORT", NULL);
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_CONFIGURED_ORPORT, NULL);
CLEANUP_FOUND_ADDRESS;
/*
@@ -1774,7 +1777,7 @@ test_config_find_my_address(void *arg)
&method_used, &hostname_out);
tt_int_op(n_get_interface_address6, OP_EQ, ++prev_n_get_interface_address6);
- VALIDATE_FOUND_ADDRESS(true, "INTERFACE", NULL);
+ VALIDATE_FOUND_ADDRESS(true, RESOLVED_ADDR_INTERFACE, NULL);
CLEANUP_FOUND_ADDRESS;
UNMOCK(get_interface_address6);
diff --git a/src/test/test_relay.c b/src/test/test_relay.c
index ee704ceb8c..545cb4ac46 100644
--- a/src/test/test_relay.c
+++ b/src/test/test_relay.c
@@ -307,13 +307,13 @@ test_find_addr_to_publish(void *arg)
/* Populate our resolved cache with a valid IPv4 and IPv6. */
family = tor_addr_parse(&ipv4_addr, "1.2.3.4");
tt_int_op(family, OP_EQ, AF_INET);
- resolved_addr_set_last(&ipv4_addr, "NA", NULL);
+ resolved_addr_set_last(&ipv4_addr, RESOLVED_ADDR_CONFIGURED, NULL);
resolved_addr_get_last(AF_INET, &cache_addr);
tt_assert(tor_addr_eq(&ipv4_addr, &cache_addr));
family = tor_addr_parse(&ipv6_addr, "[4242::4242]");
tt_int_op(family, OP_EQ, AF_INET6);
- resolved_addr_set_last(&ipv6_addr, "NA", NULL);
+ resolved_addr_set_last(&ipv6_addr, RESOLVED_ADDR_CONFIGURED, NULL);
resolved_addr_get_last(AF_INET6, &cache_addr);
tt_assert(tor_addr_eq(&ipv6_addr, &cache_addr));
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits