routerinfo: Make router_get_orport() return an error status

Part of 33222.
This commit is contained in:
teor 2020-05-07 20:25:36 +10:00
parent 24099680f1
commit c76f310fe7
3 changed files with 15 additions and 10 deletions

View file

@ -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. */
/* 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;
}
}

View file

@ -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,

View file

@ -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;
}