[Openvpn-devel,v3] Multi-socket win: avoid repeated socket_set()

Message ID 20250912131207.42597-1-frank@lichtenheld.com
State New
Headers show
Series [Openvpn-devel,v3] Multi-socket win: avoid repeated socket_set() | expand

Commit Message

Frank Lichtenheld Sept. 12, 2025, 1:12 p.m. UTC
From: Gianmarco De Gregori <gianmarco@mandelbit.com>

On Windows, multi-socket support failed with
mixed protocols due to repeated socket_set()
calls, which caused accept() to be triggered
before having an event to process.
This fix skips socket_set() calls for
non-UDP sockets in MODE_SERVER inside
multi_io_process_flags().

Change-Id: Ia389fcec50fb2bbc0aa5ad41a2c23c17c04e6e9b
Signed-off-by: Gianmarco De Gregori <gianmarco@mandelbit.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
---

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

Acked-by according to Gerrit (reflected above):
Lev Stipakov <lstipakov@gmail.com>

Comments

Gert Doering Sept. 12, 2025, 3:23 p.m. UTC | #1
I can't claim I understand what exactly upsets what here, but since
Gianmarco is the "multi event expert" and Lev has confirmed that this
fixes the observed windows issues, *and* there is now a comment that
explains to casual readers what this is about, good enough for me :-)
(plus the CI infra agrees that things still work).

Again, mail-archive.org claims this was never sent to the list, so
linking to sf.net archive & our gerrit.

Your patch has been applied to the master branch.

commit 3b429925fb9b4a822facc6ea9f13b927b6021944
Author: Gianmarco De Gregori
Date:   Fri Sep 12 15:12:07 2025 +0200

     Multi-socket win: avoid repeated socket_set()

     Signed-off-by: Gianmarco De Gregori <gianmarco@mandelbit.com>
     Acked-by: Lev Stipakov <lstipakov@gmail.com>
     Message-Id: <20250912131207.42597-1-frank@lichtenheld.com>
     URL: https://sourceforge.net/p/openvpn/mailman/message/59232443/
     URL: https://gerrit.openvpn.net/c/openvpn/+/1174
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 03b6a0c..5d22fa3 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -2121,10 +2121,15 @@ 
 
     /*
      * Configure event wait based on socket, tuntap flags.
+     * (for TCP server sockets this happens in
+     *  socket_set_listen_persistent()).
      */
     for (int i = 0; i < c->c1.link_sockets_num; i++)
     {
-        socket_set(c->c2.link_sockets[i], es, socket, &c->c2.link_sockets[i]->ev_arg, NULL);
+        if ((c->options.mode != MODE_SERVER) || (proto_is_dgram(c->c2.link_sockets[i]->info.proto)))
+        {
+            socket_set(c->c2.link_sockets[i], es, socket, &c->c2.link_sockets[i]->ev_arg, NULL);
+        }
     }
 
     tun_set(c->c1.tuntap, es, tuntap, (void *)tun_shift, NULL);