[Openvpn-devel,v1] multi_io: walk the link sockets once in multi_io_wait()

Message ID 20261027124501.682-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] multi_io: walk the link sockets once in multi_io_wait() |

Commit Message

Gert Doering Oct. 27, 2026, 12:44 p.m. UTC
  From: Gianmarco De Gregori <gianmarco@mandelbit.com>

multi_io_wait() went over the link sockets twice: first to register
every socket as a listening socket, then, if a UDP socket is configured,
again to arm the UDP ones. The UDP sockets were thus registered twice,
and on Windows the first pass created an FD_ACCEPT event for them.

Walk the sockets once, arming the UDP sockets and registering only the
TCP ones as listening sockets. Drop the mode check as well, since
multi_io_wait() only runs in server mode.

Change-Id: I2f49f40e49af8503f5c08c5575ffc9a8b4c9aa20
Signed-off-by: Gianmarco De Gregori <gianmarco@mandelbit.com>
Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2045
---

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

Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <razvanc@mailbox.org>
  

Patch

diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c
index 56216d4..fb4810b 100644
--- a/src/openvpn/multi_io.c
+++ b/src/openvpn/multi_io.c
@@ -168,27 +168,17 @@ 
     int status;
     unsigned int *persistent = &m->multi_io->tun_rwflags;
 
-    if (!tuntap_is_dco_win(m->top.c1.tuntap))
+    for (int i = 0; i < m->top.c1.link_sockets_num; i++)
     {
-        for (int i = 0; i < m->top.c1.link_sockets_num; i++)
+        struct link_socket *sock = m->top.c2.link_sockets[i];
+
+        if (proto_is_dgram(sock->info.proto))
         {
-            socket_set_listen_persistent(m->top.c2.link_sockets[i], m->multi_io->es,
-                                         &m->top.c2.link_sockets[i]->ev_arg);
+            multi_io_process_flags(&m->top, m->multi_io->es, sock, p2mp_iow_flags(m, sock));
         }
-    }
-
-    if (has_udp_in_local_list(&m->top.options))
-    {
-        for (int i = 0; i < m->top.c1.link_sockets_num; i++)
+        else if (!tuntap_is_dco_win(m->top.c1.tuntap))
         {
-            struct link_socket *sock = m->top.c2.link_sockets[i];
-
-            if ((m->top.options.mode == MODE_SERVER) && proto_is_dgram(sock->info.proto))
-            {
-                unsigned int flags = p2mp_iow_flags(m, sock);
-
-                multi_io_process_flags(&m->top, m->multi_io->es, sock, flags);
-            }
+            socket_set_listen_persistent(sock, m->multi_io->es, &sock->ev_arg);
         }
     }