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

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

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>

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)");