[Openvpn-devel,v1] socket: use remote proto when creating client sockets

Message ID 20250325105724.1285-1-gert@greenie.muc.de
State Accepted
Headers show
Series [Openvpn-devel,v1] socket: use remote proto when creating client sockets | expand

Commit Message

Gert Doering March 25, 2025, 10:57 a.m. UTC
From: Antonio Quartulli <antonio@mandelbit.com>

When creating a socket to connect to a remote (this happens
in client mode) always use the protocol specified for the
remote.

The listening protocol in this case is just ignored as it
does not make any sense.

Change-Id: I6d2ec69ac7a9ef5900d8f1d8541d6a19c9cb7df9
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/911
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Arne Schwabe <arne-openvpn@rfc2549.org>

Comments

Gert Doering April 1, 2025, 2:07 p.m. UTC | #1
Yeah, too many protos around...  Arne and Lev confirm that this is what
is needed to un-confuse "--local <with proto>" and "--remote <with proto>"
and general "--<proto>" (--udp4 etc) for the client case...

Tested with standard and extended t_client test set (extended = one
stanza that has multiple --remote with different protos *and* --local
bound to a local IP).

There's a number of interesting ways to break things here 
("--local ipv4 --remote ipv6 --proto udp6") but that's all clear
misconfigs - these have never worked, it's just that the error messages
 are bit different with multisocket.  "--local $hostname" with something
that resolves to both an ipv4 and ipv6 address nicely binds to whatever
the "--remote" stanza tries to use (v4/v6).  Good.

Your patch has been applied to the master branch.

commit 39cd7f29cbccd37b07ddc27eb23b8ad270f43e77
Author: Antonio Quartulli
Date:   Tue Mar 25 11:57:24 2025 +0100

     socket: use remote proto when creating client sockets

     Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
     Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
     Message-Id: <20250325105724.1285-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31234.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index 6b32e30..ad97830 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -1886,6 +1886,11 @@ 
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
+    if (remote_host)
+    {
+        proto = o->ce.proto;
+    }
+
     if (c->mode == CM_CHILD_TCP || c->mode == CM_CHILD_UDP)
     {
         struct link_socket *tmp_sock = NULL;