[Openvpn-devel,v1] multi_io: move the tun write functions to multi_io.c

Message ID 20261027102325.19448-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] multi_io: move the tun write functions to multi_io.c |

Commit Message

Gert Doering Oct. 27, 2026, 10:23 a.m. UTC
  From: Gianmarco De Gregori <gianmarco@mandelbit.com>

multi_process_outgoing_tun() lived as a static inline in multi.h and
multi_process_drop_outgoing_tun() in multi.c, while their only caller
is multi_io_dispatch(). Move both next to it, as static functions named
multi_io_write_tun() and multi_io_drop_tun(), so that writing to the
tun device is found where the state machine decides to do it.

No functional change.

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

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/+/2042
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.c b/src/openvpn/multi.c
index e302a81..2e804ff 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -3766,27 +3766,6 @@ 
 }
 
 /*
- * Drop a TUN/TAP outgoing packet..
- */
-void
-multi_process_drop_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags)
-{
-    struct multi_instance *mi = m->pending;
-
-    ASSERT(mi);
-
-    set_prefix(mi);
-
-    msg(D_MULTI_ERRORS, "MULTI: Outgoing TUN queue full, dropped packet len=%d",
-        mi->context.c2.to_tun.len);
-
-    buf_reset(&mi->context.c2.to_tun);
-
-    multi_process_post(m, mi, mpp_flags);
-    clear_prefix();
-}
-
-/*
  * Per-client route quota management
  */
 
diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h
index 5db7147..2d4983c 100644
--- a/src/openvpn/multi.h
+++ b/src/openvpn/multi.h
@@ -295,7 +295,7 @@ 
  * function controls the necessary postprocessing.  It is called by many
  * other functions that handle VPN tunnel related activity, such as \c
  * multi_process_incoming_link(), \c multi_process_outgoing_link(), \c
- * multi_process_incoming_tun(), \c multi_process_outgoing_tun(), and \c
+ * multi_process_incoming_tun(), \c multi_io_write_tun(), and \c
  * multi_process_timeout(), among others.
  *
  * @param m            - The single \c multi_context structure.
@@ -364,8 +364,6 @@ 
 bool multi_process_incoming_tun(struct multi_context *m, const unsigned int mpp_flags);
 
 
-void multi_process_drop_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags);
-
 struct multi_instance *multi_get_queue(struct mbuf_set *ms);
 
 void multi_ifconfig_pool_persist(struct multi_context *m, bool force);
@@ -627,41 +625,6 @@ 
 }
 
 
-/**
- * Send a packet over the virtual tun/tap network interface to its locally
- * reachable destination.
- * @ingroup internal_multiplexer
- *
- * This function calls \c process_outgoing_tun() to perform the actual
- * sending of the packet.  Afterwards, it calls \c multi_process_post() to
- * perform server-mode postprocessing.
- *
- * @param m            - The single \c multi_context structure.
- * @param mpp_flags    - Fast I/O optimization flags.
- *
- * @return
- *  - True, if the \c multi_instance associated with the packet sent was
- *    not closed due to a signal during processing.
- *  - Falls, if the \c multi_instance was closed.
- */
-static inline bool
-multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags)
-{
-    struct multi_instance *mi = m->pending;
-    bool ret = true;
-
-    ASSERT(mi);
-#ifdef MULTI_DEBUG_EVENT_LOOP
-    printf("%s -> TUN len=%d\n", id(mi), mi->context.c2.to_tun.len);
-#endif
-    set_prefix(mi);
-    vlan_process_outgoing_tun(m, mi);
-    process_outgoing_tun(&mi->context, mi->context.c2.link_sockets[0]);
-    ret = multi_process_post(m, mi, mpp_flags);
-    clear_prefix();
-    return ret;
-}
-
 #define CLIENT_CONNECT_OPT_MASK                                                            \
     (OPT_P_INSTANCE | OPT_P_INHERIT | OPT_P_PUSH | OPT_P_TIMER | OPT_P_CONFIG | OPT_P_ECHO \
      | OPT_P_COMP | OPT_P_SOCKFLAGS)
diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c
index ebee86c..164b214 100644
--- a/src/openvpn/multi_io.c
+++ b/src/openvpn/multi_io.c
@@ -290,6 +290,62 @@ 
     }
 }
 
+/**
+ * Send a packet over the virtual tun/tap network interface to its locally
+ * reachable destination.
+ * @ingroup internal_multiplexer
+ *
+ * This function calls \c process_outgoing_tun() to perform the actual
+ * sending of the packet.  Afterwards, it calls \c multi_process_post() to
+ * perform server-mode postprocessing.
+ *
+ * @param m            - The single \c multi_context structure.
+ * @param mpp_flags    - Fast I/O optimization flags.
+ *
+ * @return
+ *  - True, if the \c multi_instance associated with the packet sent was
+ *    not closed due to a signal during processing.
+ *  - Falls, if the \c multi_instance was closed.
+ */
+static bool
+multi_io_write_tun(struct multi_context *m, const unsigned int mpp_flags)
+{
+    struct multi_instance *mi = m->pending;
+    bool ret = true;
+
+    ASSERT(mi);
+#ifdef MULTI_DEBUG_EVENT_LOOP
+    printf("%s -> TUN len=%d\n", id(mi), mi->context.c2.to_tun.len);
+#endif
+    set_prefix(mi);
+    vlan_process_outgoing_tun(m, mi);
+    process_outgoing_tun(&mi->context, mi->context.c2.link_sockets[0]);
+    ret = multi_process_post(m, mi, mpp_flags);
+    clear_prefix();
+    return ret;
+}
+
+/*
+ * Drop a TUN/TAP outgoing packet..
+ */
+static void
+multi_io_drop_tun(struct multi_context *m, const unsigned int mpp_flags)
+{
+    struct multi_instance *mi = m->pending;
+
+    ASSERT(mi);
+
+    set_prefix(mi);
+
+    msg(D_MULTI_ERRORS, "MULTI: Outgoing TUN queue full, dropped packet len=%d",
+        mi->context.c2.to_tun.len);
+
+    buf_reset(&mi->context.c2.to_tun);
+
+    multi_process_post(m, mi, mpp_flags);
+    clear_prefix();
+}
+
 static struct multi_instance *
 multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, const int action)
 {
@@ -334,11 +390,11 @@ 
             break;
 
         case TA_TUN_WRITE:
-            multi_process_outgoing_tun(m, mpp_flags);
+            multi_io_write_tun(m, mpp_flags);
             break;
 
         case TA_TUN_WRITE_TIMEOUT:
-            multi_process_drop_outgoing_tun(m, mpp_flags);
+            multi_io_drop_tun(m, mpp_flags);
             break;
 
         case TA_SOCKET_WRITE_READY: