commit 1720a2191d6b94e1847a2ad3a2c45c5e8de53bcd Author: teor teor@torproject.org Date: Wed Apr 1 09:56:00 2020 +1000
address: Simplify tor_addr_is_valid()
And rewrite the function comment.
Part of 33679. --- src/lib/net/address.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/lib/net/address.c b/src/lib/net/address.c index 7b24e406a..5dbef6a79 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -817,9 +817,12 @@ tor_addr_is_loopback(const tor_addr_t *addr)
/* Is addr valid? * Checks that addr is non-NULL and not tor_addr_is_null(). - * If for_listening is true, addr is allowed in either case if - * addr is 0.0.0.0 (for IPv4) or :: (for IPv6). - * It means "bind to all addresses on the local machine". */ + * If for_listening is true, all IPv4 and IPv6 addresses are valid, including + * 0.0.0.0 (for IPv4) and :: (for IPv6). When listening, these addresses mean + * "bind to all addresses on the local machine". + * Otherwise, 0.0.0.0 and :: are invalid, because they are null addresses. + * All unspecified and unix addresses are invalid, regardless of for_listening. + */ int tor_addr_is_valid(const tor_addr_t *addr, int for_listening) { @@ -828,14 +831,11 @@ tor_addr_is_valid(const tor_addr_t *addr, int for_listening) return 0; }
- /* Only allow IPv4 0.0.0.0 for_listening. */ - if (for_listening && addr->family == AF_INET - && tor_addr_to_ipv4h(addr) == 0) { - return 1; - } - - if (for_listening && addr->family == AF_INET6) { - return 1; + /* Allow all IPv4 and IPv6 addresses, when for_listening is true */ + if (for_listening) { + if (addr->family == AF_INET || addr->family == AF_INET6) { + return 1; + } }
/* Otherwise, the address is valid if it's not tor_addr_is_null() */
tor-commits@lists.torproject.org