Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/2402?usp=email
to review the following change.
Change subject: socket: use an IPv4 data socket for SOCKS over UDP
......................................................................
socket: use an IPv4 data socket for SOCKS over UDP
SOCKS over UDP only handles IPv4: the relay address and the server
address in the UDP header. options.c already forces IPv4 for it, but
create_socket() then set info.af to the family of the proxy address.
With an IPv6 proxy the data socket was IPv6, so:
- the server was resolved as IPv6, and a hostname with only an A
record didn't resolve
- the relayed source was written into the in4 fields of an IPv6
address, so every reply was rejected
- sending to the IPv4 relay over the IPv6 socket fails on platforms
other than Linux
Create the data socket as IPv4. The control socket to the proxy keeps
the proxy's family, so bind_local() now gets the family of the socket
it binds.
Change-Id: I5b552e6bd00db911163f7a82a798271ff4bb94ee
Signed-off-by: Razvan Cojocaru <[email protected]>
---
M src/openvpn/socket.c
M src/openvpn/socket.h
2 files changed, 18 insertions(+), 11 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/02/2402/1
diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index 27b4236..d3411d8 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -174,7 +174,7 @@
*/
socket_descriptor_t
-create_socket_tcp(struct addrinfo *addrinfo)
+create_socket_tcp(const struct addrinfo *addrinfo)
{
socket_descriptor_t sd;
@@ -260,20 +260,21 @@
return sd;
}
+/* af is the family of the socket to bind, which for SOCKS over UDP is the
+ * control socket's */
static void
-bind_local(const struct link_socket *sock)
+bind_local(const struct link_socket *sock, const sa_family_t af)
{
/* bind to local address/port */
if (sock->bind_local)
{
if (sock->socks_proxy && sock->info.proto == PROTO_UDP)
{
- socket_bind(sock->ctrl_sd, sock->info.lsa->bind_local,
sock->info.af, "SOCKS", false,
- M_FATAL);
+ socket_bind(sock->ctrl_sd, sock->info.lsa->bind_local, af,
"SOCKS", false, M_FATAL);
}
else
{
- socket_bind(sock->sd, sock->info.lsa->bind_local, sock->info.af,
"TCP/UDP",
+ socket_bind(sock->sd, sock->info.lsa->bind_local, af, "TCP/UDP",
sock->info.bind_ipv6_only, M_FATAL);
}
}
@@ -330,7 +331,7 @@
}
static void
-create_socket(struct link_socket *sock, struct addrinfo *addr)
+create_socket(struct link_socket *sock, const struct addrinfo *addr)
{
/* Set af field of sock->info, so it always reflects the address family
* of the created socket */
@@ -338,6 +339,13 @@
if (addr->ai_protocol == IPPROTO_UDP || addr->ai_socktype == SOCK_DGRAM)
{
+ /* SOCKS over UDP only carries IPv4 (relay and server addresses), so
+ * the data socket is IPv4 whatever the proxy's family is */
+ if (sock->socks_proxy)
+ {
+ sock->info.af = AF_INET;
+ }
+
/* With a SOCKS proxy the local bind goes on the control socket instead
* (see bind_local()), so the UDP socket is created unbound then. */
struct addrinfo *bind_addr =
@@ -347,8 +355,7 @@
sock->info.bind_ipv6_only,
false);
sock->sockflags |= SF_GETADDRINFO_DGRAM;
- /* Assume that control socket and data socket to the socks proxy
- * are using the same IP family */
+ /* The control socket uses the proxy's family */
if (sock->socks_proxy)
{
/* Construct a temporary addrinfo to create the socket,
@@ -358,14 +365,14 @@
addrinfo_tmp.ai_socktype = SOCK_STREAM;
addrinfo_tmp.ai_protocol = IPPROTO_TCP;
sock->ctrl_sd = create_socket_tcp(&addrinfo_tmp);
- bind_local(sock);
+ bind_local(sock, (sa_family_t)addr->ai_family);
}
}
else if (addr->ai_protocol == IPPROTO_TCP || addr->ai_socktype ==
SOCK_STREAM)
{
sock->sd = create_socket_tcp(addr);
socket_apply_options(sock->sd, &sock->socket_buffer_sizes, sock->mark,
sock->bind_dev);
- bind_local(sock);
+ bind_local(sock, sock->info.af);
}
else
{
diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h
index cc9519b..84ad8b5 100644
--- a/src/openvpn/socket.h
+++ b/src/openvpn/socket.h
@@ -402,7 +402,7 @@
* Low-level functions
*/
-socket_descriptor_t create_socket_tcp(struct addrinfo *);
+socket_descriptor_t create_socket_tcp(const struct addrinfo *);
/**
* Create a UDP socket for @p af set up the way a link socket is:
--sndbuf/--rcvbuf,
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2402?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5b552e6bd00db911163f7a82a798271ff4bb94ee
Gerrit-Change-Number: 2402
Gerrit-PatchSet: 1
Gerrit-Owner: Răzvan Cojocaru <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel