diff options
author | Francisco Blas Izquierdo Riera (klondike) <klondike@gentoo.org> | 2014-12-23 10:51:33 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-12-23 10:51:33 -0500 |
commit | 39e71d8fa54afd906fdcaf2cd496c300362ebb9a (patch) | |
tree | 1b4ed9fff0c400eebd5d01f2d42cd022e34e3bea /src | |
parent | 808e2b856bd77fa9b431272a6f37596655fd5945 (diff) | |
download | tor-39e71d8fa54afd906fdcaf2cd496c300362ebb9a.tar.gz tor-39e71d8fa54afd906fdcaf2cd496c300362ebb9a.zip |
Use the appropriate call to getsockopt for IPv6 sockets
The original call to getsockopt to know the original address on transparently
proxyed sockets using REDIRECT in iptables failed with IPv6 addresses because
it assumed all sockets used IPv4.
This patch fixes this by using the appropriate options and adding the headers
containing the needed definitions for these.
This patch is released under the same license as the original file as
long as the author iscredited.
Signed-off-by: Francisco Blas Izquierdo Riera (klondike) <klondike@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/or/connection_edge.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index a90ca00883..09645d04b9 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -46,8 +46,20 @@ #ifdef HAVE_LINUX_NETFILTER_IPV4_H #include <linux/netfilter_ipv4.h> #define TRANS_NETFILTER +#define TRANS_NETFILTER_IPV4 #endif +#ifdef HAVE_LINUX_IF_H +#include <linux/if.h> +#endif + +#ifdef HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H +#include <linux/netfilter_ipv6/ip6_tables.h> +#define TRANS_NETFILTER +#define TRANS_NETFILTER_IPV6 +#endif + + #if defined(HAVE_NET_IF_H) && defined(HAVE_NET_PFVAR_H) #include <net/if.h> #include <net/pfvar.h> @@ -1401,10 +1413,27 @@ destination_from_socket(entry_connection_t *conn, socks_request_t *req) struct sockaddr_storage orig_dst; socklen_t orig_dst_len = sizeof(orig_dst); tor_addr_t addr; + int rv; #ifdef TRANS_NETFILTER - if (getsockopt(ENTRY_TO_CONN(conn)->s, SOL_IP, SO_ORIGINAL_DST, - (struct sockaddr*)&orig_dst, &orig_dst_len) < 0) { + switch (ENTRY_TO_CONN(conn)->socket_family) { +#ifdef TRANS_NETFILTER_IPV4 + case AF_INET: + rv = getsockopt(ENTRY_TO_CONN(conn)->s, SOL_IP, SO_ORIGINAL_DST, + (struct sockaddr*)&orig_dst, &orig_dst_len); + break; +#endif +#ifdef TRANS_NETFILTER_IPV6 + case AF_INET6: + rv = getsockopt(ENTRY_TO_CONN(conn)->s, SOL_IPV6, IP6T_SO_ORIGINAL_DST, + (struct sockaddr*)&orig_dst, &orig_dst_len); + break; +#endif + default: + log_warn(LD_BUG, "Received transparent data from an unsuported socket family."); + return -1; + } + if (rv < 0) { int e = tor_socket_errno(ENTRY_TO_CONN(conn)->s); log_warn(LD_NET, "getsockopt() failed: %s", tor_socket_strerror(e)); return -1; |