aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_address.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2020-07-13 14:07:37 -0400
committerDavid Goulet <dgoulet@torproject.org>2020-07-14 10:36:08 -0400
commit15860c8846a8ebbdecd51e920f983afc49c30c8f (patch)
tree882c2f2435720e358a2ea08ca1aafc99fe5f0966 /src/test/test_address.c
parent8ebbf629404a97b6110c1916d554009dc8f42c5a (diff)
downloadtor-15860c8846a8ebbdecd51e920f983afc49c30c8f.tar.gz
tor-15860c8846a8ebbdecd51e920f983afc49c30c8f.zip
addr: Use tor_addr_t instead of uint32_t for IPv4
This changes a LOT of code but in the end, behavior is the same. Unfortunately, many functions had to be changed to accomodate but in majority of cases, to become simpler. Functions are also removed specifically those that were there to convert an IPv4 as a host format to a tor_addr_t. Those are not needed anymore. The IPv4 address field has been standardized to "ipv4_addr", the ORPort to "ipv4_orport" (currently IPv6 uses ipv6_orport) and DirPort to "ipv4_dirport". This is related to Sponsor 55 work that adds IPv6 support for relays and this work is needed in order to have a common interface between IPv4 and IPv6. Closes #40043. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_address.c')
-rw-r--r--src/test/test_address.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/test/test_address.c b/src/test/test_address.c
index 8a46630088..17479d69c2 100644
--- a/src/test/test_address.c
+++ b/src/test/test_address.c
@@ -1194,16 +1194,14 @@ helper_free_mock_node(node_t *node)
tor_free(node);
}
-#define NODE_SET_IPV4(node, ipv4_addr, ipv4_port) { \
- tor_addr_t addr; \
- tor_addr_parse(&addr, ipv4_addr); \
- node->ri->addr = tor_addr_to_ipv4h(&addr); \
- node->ri->or_port = ipv4_port; \
+#define NODE_SET_IPV4(node, ipv4_addr_str, ipv4_port) { \
+ tor_addr_parse(&(node)->ri->ipv4_addr, ipv4_addr_str); \
+ node->ri->ipv4_orport = ipv4_port; \
}
#define NODE_CLEAR_IPV4(node) { \
- node->ri->addr = 0; \
- node->ri->or_port = 0; \
+ tor_addr_make_unspec(&node->ri->ipv4_addr); \
+ node->ri->ipv4_orport = 0; \
}
#define NODE_SET_IPV6(node, ipv6_addr_str, ipv6_port) { \
@@ -1260,9 +1258,7 @@ mock_get_options(void)
#define TEST_ROUTER_VALID_ADDRESS_HELPER(ipv4_addr_str, ipv6_addr_str, rv) \
STMT_BEGIN \
ri = tor_malloc_zero(sizeof(routerinfo_t)); \
- tor_addr_t addr; \
- tor_addr_parse(&addr, (ipv4_addr_str)); \
- ri->addr = tor_addr_to_ipv4h(&addr); \
+ tor_addr_parse(&ri->ipv4_addr, (ipv4_addr_str)); \
tor_addr_parse(&ri->ipv6_addr, (ipv6_addr_str)); \
tt_int_op(dirserv_router_has_valid_address(ri), OP_EQ, (rv)); \
tor_free(ri); \
@@ -1320,7 +1316,7 @@ test_address_dirserv_router_addr_private(void *opt_dir_allow_private)
/* IPv6 null succeeds, because IPv4 is not internal */
{
ri = tor_malloc_zero(sizeof(routerinfo_t));
- ri->addr = 16777217; /* 1.0.0.1 */
+ tor_addr_parse(&ri->ipv4_addr, "1.0.0.1");
tt_int_op(dirserv_router_has_valid_address(ri), OP_EQ, 0);
tor_free(ri);
}