Skip to contentSkip to conversation

Change in openvpn[master]: multiproto: move generic event handling code in dedicated files

Openvpn-devel ordex (Code Review) 1 participant 4 messages Nov 15, 2023 – Sep 24, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1700055887000.Id2d7957f5950115d9baade4c09fd9679b01f749b@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/441?usp=email

to review the following change.

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_protocol since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_protocol_init();
- multi_tcp_free() -> multi_protocol_free();
- multi_tcp_wait() -> multi_protocol_io_wait();
and so forth.

Change-Id Id2d7957f5950115d9baade4c09fd9679b01f749b

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

11 files changed, 821 insertions(+), 777 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/41/441/1

CMakeLists.txt +2 -0
index d21c9bd..ee27465 100644
@@ -402,6 +402,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.c
+    src/openvpn/multi_io.h
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index 52deef8..17fcb1b 100644
@@ -89,6 +89,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.c +9 -9
index ee18f8b..0e5b611 100644
@@ -2053,7 +2053,7 @@
  */
 
 void
-get_io_flags_dowork_udp(struct context *c, struct multi_tcp *mtcp, const unsigned int flags)
+get_io_flags_dowork_udp(struct context *c, struct multi_protocol *multi_io, const unsigned int flags)
 {
     unsigned int socket = 0;
     unsigned int tuntap = 0;
@@ -2064,7 +2064,7 @@
      */
     if (flags & IOW_WAIT_SIGNAL)
     {
-        wait_signal(mtcp->es, (void *)err_shift);
+        wait_signal(multi_io->es, (void *)err_shift);
     }
 
     if (flags & IOW_TO_LINK)
@@ -2156,17 +2156,17 @@
     {
         if (proto_is_dgram(c->c2.link_sockets[i]->info.proto))
         {
-            socket_set(c->c2.link_sockets[i], mtcp->es, socket,
+            socket_set(c->c2.link_sockets[i], multi_io->es, socket,
                        &c->c2.link_sockets[i]->ev_arg, NULL);
         }
     }
-    mtcp->udp_flags = socket | tuntap;
+    multi_io->udp_flags = socket | tuntap;
 }
 
 void
-get_io_flags_udp(struct context *c, struct multi_tcp *mtcp, const unsigned int flags)
+get_io_flags_udp(struct context *c, struct multi_protocol *multi_io, const unsigned int flags)
 {
-    mtcp->udp_flags = ES_ERROR;
+    multi_io->udp_flags = ES_ERROR;
     if (c->c2.fast_io && (flags & (IOW_TO_TUN | IOW_TO_LINK | IOW_MBUF)))
     {
         /* fast path -- only for TUN/TAP/UDP writes */
@@ -2179,7 +2179,7 @@
         {
             ret |= SOCKET_WRITE;
         }
-        mtcp->udp_flags = ret;
+        multi_io->udp_flags = ret;
     }
     else
     {
@@ -2205,13 +2205,13 @@
             {
                 ret |= TUN_READ;
             }
-            mtcp->udp_flags = ret;
+            multi_io->udp_flags = ret;
         }
         else
 #endif /* ifdef _WIN32 */
         {
             /* slow path - delegate to io_wait_dowork_udp to calculate flags */
-            get_io_flags_dowork_udp(c, mtcp, flags);
+            get_io_flags_dowork_udp(c, multi_io, flags);
         }
     }
 }
src/openvpn/forward.h +9 -3
index 39ac975..a251d04 100644
@@ -50,7 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
-#include "mtcp.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
@@ -65,13 +65,19 @@
 
 #define IOW_READ            (IOW_READ_TUN|IOW_READ_LINK)
 
+
+/* forward declaration */
+/*struct multi_context;
+ * struct multi_protocol;
+ * struct context;*/
+
 extern counter_type link_read_bytes_global;
 
 extern counter_type link_write_bytes_global;
 
-void get_io_flags_dowork_udp(struct context *c, struct multi_tcp *mtcp, const unsigned int flags);
+void get_io_flags_dowork_udp(struct context *c, struct multi_protocol *multi_io, const unsigned int flags);
 
-void get_io_flags_udp(struct context *c, struct multi_tcp *mtcp, const unsigned int flags);
+void get_io_flags_udp(struct context *c, struct multi_protocol *multi_io, const unsigned int flags);
 
 void io_wait_dowork(struct context *c, const unsigned int flags);
 
src/openvpn/mtcp.c +9 -740

791 lines not on this page · raw message

src/openvpn/mtcp.h +7 -13
index d55bdfd..b8a0191 100644
@@ -63,26 +63,23 @@
 
 struct multi_instance;
 struct context;
+struct multi_protocol;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
-int multi_tcp_wait(struct context *c, struct multi_tcp *mtcp);
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
 
-void multi_tcp_process_io(struct multi_context *m);
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
 
-void multi_tcp_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll);
-
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *ls);
 
 void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
 
+struct context *multi_tcp_context(struct multi_context *m, struct multi_instance *mi);
 
 /**************************************************************************/
 /**
@@ -91,9 +88,6 @@
  *
  * @param top - Top-level context structure.
  */
-void tunnel_server_tcp(struct context *top);
-
-
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+/*void tunnel_server_tcp(struct context *top); */
 
 #endif /* ifndef MTCP_H */
src/openvpn/mudp.c +1 -1
index 8945a55..d29f7a5 100644
@@ -379,7 +379,7 @@
 void
 multi_process_io_udp(struct multi_context *m)
 {
-    unsigned int status = m->mtcp->udp_flags;
+    unsigned int status = m->multi_io->udp_flags;
     const unsigned int mpp_flags = m->top.c2.fast_io
                                    ? (MPP_CONDITIONAL_PRE_SELECT | MPP_CLOSE_ON_SIGNAL)
                                    : (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);
src/openvpn/multi.c +16 -9
index 108a5a8..b29134e 100644
@@ -440,7 +440,7 @@
     /*
      * Initialize multi-socket TCP I/O wait object
      */
-    m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+    m->multi_io = multi_protocol_init(t->options.max_clients, &m->max_clients);
 
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -668,7 +668,7 @@
 
         if (!is_dgram)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -746,7 +746,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_protocol_free(m->multi_io);
     }
 }
 
@@ -3997,9 +3997,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_protocol_delete_event(m->multi_io, event);
     }
 }
 
@@ -4177,7 +4177,7 @@
     ASSERT(mi->context.c2.tls_multi->peer_id < m->max_clients);
 }
 
-
+/* Actual multi protocol event loop in server mode */
 void
 tunnel_server_loop(struct multi_context *multi)
 {
@@ -4189,7 +4189,7 @@
 
         /* wait on tun/socket list */
         multi_get_timeout(multi, &multi->top.c2.timeval);
-        status = multi_tcp_wait(&multi->top, multi->mtcp);
+        status = multi_protocol_io_wait(&multi->top, multi->multi_io);
         MULTI_CHECK_SIG(multi);
 
         /* check on status of coarse timers */
@@ -4199,18 +4199,25 @@
         if (status > 0)
         {
             /* process the I/O which triggered select */
-            multi_tcp_process_io(multi);
+            multi_protocol_process_io(multi);
             MULTI_CHECK_SIG(multi);
         }
         else if (status == 0)
         {
-            multi_tcp_action(multi, NULL, TA_TIMEOUT, false);
+            multi_protocol_action(multi, NULL, TA_TIMEOUT, false);
         }
 
         perf_pop();
     }
 }
 
+/**************************************************************************/
+/**
+ * Main event loop for OpenVPN in server mode.
+ * @ingroup eventloop
+ *
+ * @param top - Top-level context structure.
+ */
 void
 tunnel_server_init(struct context *top)
 {
src/openvpn/multi.h +3 -2
index 472c2a3..dd7a29c 100644
@@ -37,6 +37,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -169,8 +170,8 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_protocol *multi_io;     /**< State specific to OpenVPN using both TCP
+                                          *   and UDP as external transport. */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
src/openvpn/multi_io.c new file +687 -0

687 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/441?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id2d7957f5950115d9baade4c09fd9679b01f749b
Gerrit-Change-Number: 441
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

ordex has abandoned this change. ( http://gerrit.openvpn.net/c/openvpn/+/441?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Abandoned
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/441?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id2d7957f5950115d9baade4c09fd9679b01f749b
Gerrit-Change-Number: 441
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: abandon

#3 lore raw
In reply to a message not in the archive

ordex has restored this change. ( http://gerrit.openvpn.net/c/openvpn/+/441?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Restored
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/441?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id2d7957f5950115d9baade4c09fd9679b01f749b
Gerrit-Change-Number: 441
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: restore

#4 lore raw
In reply to a message not in the archive

ordex has abandoned this change. ( http://gerrit.openvpn.net/c/openvpn/+/441?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Abandoned
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/441?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id2d7957f5950115d9baade4c09fd9679b01f749b
Gerrit-Change-Number: 441
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: abandon