[Openvpn-devel,v2] multi_io: drop IOW_MBUF

Message ID 20261005132023.27464-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v2] multi_io: drop IOW_MBUF |

Commit Message

Gert Doering Oct. 5, 2026, 1:20 p.m. UTC
  From: Gianmarco De Gregori <gianmarco@mandelbit.com>

Before the UDP and TCP server loops were merged, each drained the
bcast/mcast/client-to-client queue its own way: UDP armed EVENT_WRITE
through IOW_MBUF, TCP used the flush loop at the end of
multi_io_process_io().  The merge kept both, leaving two consumers with
different disciplines.

The queue mixes instances of both protocols and neither consumer gets to
pick: mbuf_peek() and multi_get_queue() hand back whatever sits at the
head.  The TCP side is prepared for that, testing proto_is_dgram() and
tcp_link_out_deferred before writing.  The UDP side is not: it writes
straight to the instance's own socket, so a TCP instance reaching it
skips the deferred queue that carries backpressure.

Drain the queue from the flush loop alone and drop the UDP consumer.
IOW_MBUF only existed to arm the socket for it, so it goes as well.

This leaves the queue drained from one event-driven point: the timeout
branch of tunnel_server_loop() does not reach the flush loop, so what
multi_io_action(TA_TIMEOUT) manages to queue there waits for the next
pass that has events.  Acting on the queue only when there is an event
to act on is the simpler rule, and the delay is bounded by the next
event.

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

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

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

Patch

diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 1604224..b97fb7a 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -2122,14 +2122,6 @@ 
     }
 
     /*
-     * outgoing bcast buffer waiting to be sent?
-     */
-    if (flags & IOW_MBUF)
-    {
-        socket |= EVENT_WRITE;
-    }
-
-    /*
      * Force wait on TUN input, even if also waiting on TCP/UDP output
      */
     if (flags & IOW_READ_TUN_FORCE)
diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h
index 324c0b4..0309725 100644
--- a/src/openvpn/forward.h
+++ b/src/openvpn/forward.h
@@ -58,7 +58,6 @@ 
 #define IOW_SHAPER         (1 << 4)
 #define IOW_CHECK_RESIDUAL (1 << 5)
 #define IOW_FRAG           (1 << 6)
-#define IOW_MBUF           (1 << 7)
 #define IOW_READ_TUN_FORCE (1 << 8)
 #define IOW_WAIT_SIGNAL    (1 << 9)
 
diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c
index 2b08ada..94e03d6 100644
--- a/src/openvpn/mudp.c
+++ b/src/openvpn/mudp.c
@@ -451,10 +451,9 @@ 
 static inline void
 multi_process_outgoing_link(struct multi_context *m, const unsigned int mpp_flags)
 {
-    struct multi_instance *mi = multi_process_outgoing_link_pre(m);
-    if (mi)
+    if (m->pending)
     {
-        multi_process_outgoing_link_dowork(m, mi, mpp_flags);
+        multi_process_outgoing_link_dowork(m, m->pending, mpp_flags);
     }
 }
 
diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c
index 51c7d31..348e424 100644
--- a/src/openvpn/multi_io.c
+++ b/src/openvpn/multi_io.c
@@ -177,10 +177,6 @@ 
             flags |= IOW_TO_LINK;
         }
     }
-    else if (mbuf_defined(m->mbuf))
-    {
-        flags |= IOW_MBUF;
-    }
     else
     {
         flags |= IOW_READ;
@@ -565,7 +561,7 @@ 
     multi_io->n_esr = 0;
 
     /*
-     * Process queued mbuf packets destined for TCP socket
+     * Drain the queued mbuf packets, datagram and TCP instances alike
      */
     {
         struct multi_instance *mi;