summaryrefslogtreecommitdiff
path: root/src/feature/relay
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/feature/relay
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/feature/relay')
-rw-r--r--src/feature/relay/relay_periodic.c32
-rw-r--r--src/feature/relay/router.c17
-rw-r--r--src/feature/relay/selftest.c10
3 files changed, 29 insertions, 30 deletions
diff --git a/src/feature/relay/relay_periodic.c b/src/feature/relay/relay_periodic.c
index 0c056bdeb1..cc346bc3fc 100644
--- a/src/feature/relay/relay_periodic.c
+++ b/src/feature/relay/relay_periodic.c
@@ -208,14 +208,14 @@ reachability_warnings_callback(time_t now, const or_options_t *options)
if (me && !(v4_ok && v6_ok)) {
/* We need to warn that one or more of our ORPorts isn't reachable.
* Determine which, and give a reasonable warning. */
- char *address4 = tor_dup_ip(me->addr);
+ char *address4 = tor_addr_to_str_dup(&me->ipv4_addr);
char *address6 = tor_addr_to_str_dup(&me->ipv6_addr);
if (address4 || address6) {
char *where4=NULL, *where6=NULL;
if (!v4_ok)
- tor_asprintf(&where4, "%s:%d", address4, me->or_port);
+ tor_asprintf(&where4, "%s:%d", address4, me->ipv4_orport);
if (!v6_ok)
- tor_asprintf(&where6, "[%s]:%d", address6, me->or_port);
+ tor_asprintf(&where6, "[%s]:%d", address6, me->ipv6_orport);
const char *opt_and = (!v4_ok && !v6_ok) ? "and" : "";
log_warn(LD_CONFIG,
@@ -231,7 +231,7 @@ reachability_warnings_callback(time_t now, const or_options_t *options)
if (!v4_ok) {
control_event_server_status(LOG_WARN,
"REACHABILITY_FAILED ORADDRESS=%s:%d",
- address4, me->or_port);
+ address4, me->ipv4_orport);
}
if (!v6_ok) {
control_event_server_status(LOG_WARN,
@@ -244,19 +244,17 @@ reachability_warnings_callback(time_t now, const or_options_t *options)
}
if (me && !router_dirport_seems_reachable(options)) {
- char *address = tor_dup_ip(me->addr);
- if (address) {
- log_warn(LD_CONFIG,
- "Your server (%s:%d) has not managed to confirm that its "
- "DirPort is reachable. Relays do not publish descriptors "
- "until their ORPort and DirPort are reachable. Please check "
- "your firewalls, ports, address, /etc/hosts file, etc.",
- address, me->dir_port);
- control_event_server_status(LOG_WARN,
- "REACHABILITY_FAILED DIRADDRESS=%s:%d",
- address, me->dir_port);
- tor_free(address);
- }
+ char *address4 = tor_addr_to_str_dup(&me->ipv4_addr);
+ log_warn(LD_CONFIG,
+ "Your server (%s:%d) has not managed to confirm that its "
+ "DirPort is reachable. Relays do not publish descriptors "
+ "until their ORPort and DirPort are reachable. Please check "
+ "your firewalls, ports, address, /etc/hosts file, etc.",
+ address4, me->ipv4_dirport);
+ control_event_server_status(LOG_WARN,
+ "REACHABILITY_FAILED DIRADDRESS=%s:%d",
+ address4, me->ipv4_dirport);
+ tor_free(address4);
}
}
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index b63950ea13..4f4ba8559b 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -2057,9 +2057,9 @@ router_build_fresh_unsigned_routerinfo,(routerinfo_t **ri_out))
ri = tor_malloc_zero(sizeof(routerinfo_t));
ri->cache_info.routerlist_index = -1;
ri->nickname = tor_strdup(options->Nickname);
- ri->addr = addr;
- ri->or_port = router_get_advertised_or_port(options);
- ri->dir_port = router_get_advertised_dir_port(options, 0);
+ tor_addr_from_ipv4h(&ri->ipv4_addr, addr);
+ ri->ipv4_orport = router_get_advertised_or_port(options);
+ ri->ipv4_dirport = router_get_advertised_dir_port(options, 0);
ri->supports_tunnelled_dir_requests =
directory_permits_begindir_requests(options);
ri->cache_info.published_on = time(NULL);
@@ -2105,7 +2105,8 @@ router_build_fresh_unsigned_routerinfo,(routerinfo_t **ri_out))
/* DNS is screwed up; don't claim to be an exit. */
policies_exit_policy_append_reject_star(&ri->exit_policy);
} else {
- policies_parse_exit_policy_from_options(options,ri->addr,&ri->ipv6_addr,
+ policies_parse_exit_policy_from_options(options, &ri->ipv4_addr,
+ &ri->ipv6_addr,
&ri->exit_policy);
}
ri->policy_is_reject_star =
@@ -2608,7 +2609,7 @@ check_descriptor_ipaddress_changed(time_t now)
return;
/* XXXX ipv6 */
- prev = my_ri->addr;
+ prev = tor_addr_to_ipv4h(&my_ri->ipv4_addr);
if (!find_my_address(options, AF_INET, LOG_INFO, &addr, &method,
&hostname)) {
log_info(LD_CONFIG,"options->Address didn't resolve into an IP.");
@@ -2857,7 +2858,7 @@ router_dump_router_to_string(routerinfo_t *router,
proto_line = tor_strdup("");
}
- address = tor_dup_ip(router->addr);
+ address = tor_addr_to_str_dup(&router->ipv4_addr);
if (!address)
goto err;
@@ -2881,8 +2882,8 @@ router_dump_router_to_string(routerinfo_t *router,
"%s%s%s",
router->nickname,
address,
- router->or_port,
- router_should_advertise_dirport(options, router->dir_port),
+ router->ipv4_orport,
+ router_should_advertise_dirport(options, router->ipv4_dirport),
ed_cert_line ? ed_cert_line : "",
extra_or_address ? extra_or_address : "",
router->platform,
diff --git a/src/feature/relay/selftest.c b/src/feature/relay/selftest.c
index 77c04abdd7..d24748b297 100644
--- a/src/feature/relay/selftest.c
+++ b/src/feature/relay/selftest.c
@@ -284,8 +284,8 @@ static void
router_do_dirport_reachability_checks(const routerinfo_t *me)
{
tor_addr_port_t my_dirport;
- tor_addr_from_ipv4h(&my_dirport.addr, me->addr);
- my_dirport.port = me->dir_port;
+ tor_addr_copy(&my_dirport.addr, &me->ipv4_addr);
+ my_dirport.port = me->ipv4_dirport;
/* If there is already a pending connection, don't open another one. */
if (!connection_get_by_type_addr_port_purpose(
@@ -443,7 +443,7 @@ router_dirport_found_reachable(void)
const or_options_t *options = get_options();
if (!can_reach_dir_port && me) {
- char *address = tor_dup_ip(me->addr);
+ char *address = tor_addr_to_str_dup(&me->ipv4_addr);
if (!address)
return;
@@ -454,7 +454,7 @@ router_dirport_found_reachable(void)
ready_to_publish(options) ?
" Publishing server descriptor." : "");
- if (router_should_advertise_dirport(options, me->dir_port)) {
+ if (router_should_advertise_dirport(options, me->ipv4_dirport)) {
mark_my_descriptor_dirty("DirPort found reachable");
/* This is a significant enough change to upload immediately,
* at least in a test network */
@@ -464,7 +464,7 @@ router_dirport_found_reachable(void)
}
control_event_server_status(LOG_NOTICE,
"REACHABILITY_SUCCEEDED DIRADDRESS=%s:%d",
- address, me->dir_port);
+ address, me->ipv4_dirport);
tor_free(address);
}
}