[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] routerinfo: Make router_get_orport() return an error status
commit c76f310fe724c3d93416b4e23a219feda8e6f217
Author: teor <teor@xxxxxxxxxx>
Date: Thu May 7 20:25:36 2020 +1000
routerinfo: Make router_get_orport() return an error status
Part of 33222.
---
src/feature/nodelist/routerinfo.c | 20 +++++++++++++-------
src/feature/nodelist/routerinfo.h | 2 +-
src/feature/relay/selftest.c | 3 +--
3 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/feature/nodelist/routerinfo.c b/src/feature/nodelist/routerinfo.c
index d2462a53d..55f21dfe6 100644
--- a/src/feature/nodelist/routerinfo.c
+++ b/src/feature/nodelist/routerinfo.c
@@ -21,9 +21,8 @@
* <b>family</b> into *<b>ap_out</b>.
*
* If the requested ORPort does not exist, sets *<b>ap_out</b> to the null
- * address and port. You can check the returned value using
- * tor_addr_port_is_valid_ap(ap_out, 0). */
-void
+ * address and port, and returns -1. Otherwise, returns 0. */
+int
router_get_orport(const routerinfo_t *router,
tor_addr_port_t *ap_out,
int family)
@@ -32,15 +31,22 @@ router_get_orport(const routerinfo_t *router,
if (family == AF_INET) {
tor_addr_from_ipv4h(&ap_out->addr, router->addr);
ap_out->port = router->or_port;
+ return 0;
} else if (family == AF_INET6) {
- /* If there is no IPv6 address, ipv6_addr will be the null address and
- * port. */
- tor_addr_copy(&ap_out->addr, &router->ipv6_addr);
- ap_out->port = router->ipv6_orport;
+ /* IPv6 addresses are optional, so check if it is valid. */
+ if (tor_addr_port_is_valid(&router->ipv6_addr, router->ipv6_orport, 0)) {
+ tor_addr_copy(&ap_out->addr, &router->ipv6_addr);
+ ap_out->port = router->ipv6_orport;
+ return 0;
+ } else {
+ tor_addr_port_make_null_ap(ap_out, AF_INET6);
+ return -1;
+ }
} else {
/* Unsupported address family */
tor_assert_nonfatal_unreached();
tor_addr_port_make_null_ap(ap_out, AF_UNSPEC);
+ return -1;
}
}
diff --git a/src/feature/nodelist/routerinfo.h b/src/feature/nodelist/routerinfo.h
index 47601a131..2e12cbeba 100644
--- a/src/feature/nodelist/routerinfo.h
+++ b/src/feature/nodelist/routerinfo.h
@@ -12,7 +12,7 @@
#ifndef TOR_ROUTERINFO_H
#define TOR_ROUTERINFO_H
-void router_get_orport(const routerinfo_t *router,
+int router_get_orport(const routerinfo_t *router,
tor_addr_port_t *addr_port_out,
int family);
int router_has_orport(const routerinfo_t *router,
diff --git a/src/feature/relay/selftest.c b/src/feature/relay/selftest.c
index 4093218fb..875bf7a9f 100644
--- a/src/feature/relay/selftest.c
+++ b/src/feature/relay/selftest.c
@@ -163,8 +163,7 @@ extend_info_from_router(const routerinfo_t *r, int family)
else
ed_id_key = NULL;
- router_get_orport(r, &ap, family);
- if (!tor_addr_port_is_valid_ap(&ap, 0)) {
+ if (router_get_orport(r, &ap, family) < 0) {
/* We don't have an ORPort for the requested family. */
return NULL;
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits