summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2020-04-14 15:08:42 +1000
committerteor <teor@torproject.org>2020-04-29 22:43:09 +1000
commitbd6ab90ad4b40a64c604c1a4b6b37da6991fad9e (patch)
tree832476a193af3ecb73d6858ed532f9127eb858c5 /src/lib
parent3253c357eeae3434da62bf720a451aa19f0ddd32 (diff)
downloadtor-bd6ab90ad4b40a64c604c1a4b6b37da6991fad9e.tar.gz
tor-bd6ab90ad4b40a64c604c1a4b6b37da6991fad9e.zip
core/or: Support IPv6 EXTEND2 cells
Allow clients and relays to send dual-stack and IPv6-only EXTEND2 cells. Parse dual-stack and IPv6-only EXTEND2 cells on relays. Relays do not make connections or extend circuits via IPv6: that's the next step. Closes ticket 33901.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/net/address.c14
-rw-r--r--src/lib/net/address.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/src/lib/net/address.c b/src/lib/net/address.c
index 5dbef6a79d..5fe9abca1b 100644
--- a/src/lib/net/address.c
+++ b/src/lib/net/address.c
@@ -903,6 +903,20 @@ tor_addr_from_in6(tor_addr_t *dest, const struct in6_addr *in6)
tor_addr_from_ipv6_bytes(dest, (const char*)in6->s6_addr);
}
+/** Set the 16 bytes at <b>dest</b> to equal the IPv6 address <b>src</b>.
+ * <b>src</b> must be an IPv6 address, if it is not, log a warning, and clear
+ * <b>dest</b>. */
+void
+tor_addr_get_ipv6_bytes(char *dest, const tor_addr_t *src)
+{
+ tor_assert(dest);
+ tor_assert(src);
+ memset(dest, 0, 16);
+ IF_BUG_ONCE(src->family != AF_INET6)
+ return;
+ memcpy(dest, src->addr.in6_addr.s6_addr, 16);
+}
+
/** Copy a tor_addr_t from <b>src</b> to <b>dest</b>.
*/
void
diff --git a/src/lib/net/address.h b/src/lib/net/address.h
index 4984494939..f1c2233103 100644
--- a/src/lib/net/address.h
+++ b/src/lib/net/address.h
@@ -303,6 +303,7 @@ void tor_addr_from_ipv6_bytes(tor_addr_t *dest, const char *bytes);
#define tor_addr_from_in(dest, in) \
tor_addr_from_ipv4n((dest), (in)->s_addr);
void tor_addr_from_in6(tor_addr_t *dest, const struct in6_addr *in6);
+void tor_addr_get_ipv6_bytes(char *dest, const tor_addr_t *src);
int tor_addr_is_null(const tor_addr_t *addr);
int tor_addr_is_loopback(const tor_addr_t *addr);