[Openvpn-devel,v1] Fix: port-share and multi-socket interaction

Message ID 20260520101152.17453-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] Fix: port-share and multi-socket interaction |

Commit Message

Gert Doering May 20, 2026, 10:11 a.m. UTC
  From: Gianmarco De Gregori <gianmarco@mandelbit.com>

When port-share is used, enforce the presence
of a TCP listener by checking the local_list
entries insted of rely on the global
connection_entry proto field.

Github: #1027

Change-Id: Id4e21efebbe64b963cf7847ad77bc41339af7a37
Signed-off-by: Gianmarco De Gregori <gianmarco@mandelbit.com>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1680
---

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/+/1680
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>
  

Comments

Gert Doering June 9, 2026, 8:44 a.m. UTC | #1
Tested this on master without the patch.  A config with two "local"
statements, one UDP, one TCP, and "port-share" will always fail with

   Jun  9 10:26:19 gentoo tun-tcp-p2mp[19994]: Options error: --port-share only works in TCP server mode (--proto values of tcp-server, tcp4-server, or tcp6-server)

(the order of "local" statements does not matter).  With the patch, it
will happily bind both ports and portshare works...

   2026-06-09 10:36:17 us=623614 tcp6-server:[2001:608:4:0:62e9:965e:fba9:3fef]:50046 Non-OpenVPN client protocol detected

The code change is also quite straightforward - instead of checking only
"ce->proto" (which might be anything here), we need to walk list of
sockets and see if there is "any tcp socket".  I also tested "2 TCP 
sockets", and port-share works on either of them.  Good :-)


Your patch has been applied to the master and release/2.7 branch (bugfix).

commit 0d7ea983e4c92d4c2caf5077ed8e868744c72512 (master)
commit 06e71f0c5fb3e8bc5980ca10e062b0c571b9b071 (release/2.7)
Author: Gianmarco De Gregori
Date:   Wed May 20 12:11:44 2026 +0200

     Fix: port-share and multi-socket interaction

     Signed-off-by: Gianmarco De Gregori <gianmarco@mandelbit.com>
     Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1680
     Message-Id: <20260520101152.17453-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36986.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering
  

Patch

diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 0c2866c..0ecb59c 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -2490,8 +2490,13 @@ 
             msg(M_USAGE, USAGE_VALID_SERVER_PROTOS);
         }
 #if PORT_SHARE
+        bool has_tcp = false;
+        for (int i = 0; i < ce->local_list->len && !has_tcp; i++)
+        {
+            has_tcp = (ce->local_list->array[i]->proto == PROTO_TCP_SERVER);
+        }
         if ((options->port_share_host || options->port_share_port)
-            && (ce->proto != PROTO_TCP_SERVER))
+            && !has_tcp)
         {
             msg(M_USAGE, "--port-share only works in TCP server mode "
                          "(--proto values of tcp-server, tcp4-server, or tcp6-server)");