From: "ordex (Code Review)" Date: Wed, 15 Nov 2023 13:45:20 +0000 References: Reply-To: a@...2181..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="/+HJ+sN5qjY="; charset=UTF-8 Subject: [Openvpn-devel] [XL] Change in openvpn[master]: multiproto: move generic event handling code in dedicated files List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --/+HJ+sN5qjY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=3Demail to review the following change. Change subject: multiproto: move generic event handling code in dedicated f= iles ...................................................................... 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 Signed-off-by: Gianmarco De Gregori --- 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index d21c9bd..ee27465 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/openvpn/Makefile.am b/src/openvpn/Makefile.am index 52deef8..17fcb1b 100644 --- a/src/openvpn/Makefile.am +++ b/src/openvpn/Makefile.am @@ -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 \ diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index ee18f8b..0e5b611 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -2053,7 +2053,7 @@ */ void -get_io_flags_dowork_udp(struct context *c, struct multi_tcp *mtcp, const u= nsigned int flags) +get_io_flags_dowork_udp(struct context *c, struct multi_protocol *multi_io= , const unsigned int flags) { unsigned int socket =3D 0; unsigned int tuntap =3D 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 =3D socket | tuntap; + multi_io->udp_flags =3D 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 =3D ES_ERROR; + multi_io->udp_flags =3D 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 |=3D SOCKET_WRITE; } - mtcp->udp_flags =3D ret; + multi_io->udp_flags =3D ret; } else { @@ -2205,13 +2205,13 @@ { ret |=3D TUN_READ; } - mtcp->udp_flags =3D ret; + multi_io->udp_flags =3D ret; } else #endif /* ifdef _WIN32 */ { /* slow path - delegate to io_wait_dowork_udp to calculate fla= gs */ - get_io_flags_dowork_udp(c, mtcp, flags); + get_io_flags_dowork_udp(c, multi_io, flags); } } } diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h index 39ac975..a251d04 100644 --- a/src/openvpn/forward.h +++ b/src/openvpn/forward.h @@ -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, co= nst unsigned int flags); +void get_io_flags_dowork_udp(struct context *c, struct multi_protocol *mul= ti_io, const unsigned int flags); -void get_io_flags_udp(struct context *c, struct multi_tcp *mtcp, const uns= igned 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); diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c index 128a375..4efce35 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -29,6 +29,8 @@ #include "multi.h" #include "forward.h" +#include "mtcp.h" +#include "multi_io.h" #include "memdbg.h" @@ -36,70 +38,7 @@ #include #endif -/* - * Special tags passed to event.[ch] functions - */ -#define MTCP_SOCKET ((void *)1) -#define MTCP_TUN ((void *)2) -#define MTCP_SIG ((void *)3) /* Only on Windows */ -#define MTCP_MANAGEMENT ((void *)4) -#define MTCP_FILE_CLOSE_WRITE ((void *)5) -#define MTCP_DCO ((void *)6) - -struct ta_iow_flags -{ - unsigned int flags; - unsigned int ret; - unsigned int tun; - unsigned int sock; -}; - -#ifdef ENABLE_DEBUG -static const char * -pract(int action) -{ - switch (action) - { - case TA_UNDEF: - return "TA_UNDEF"; - - case TA_SOCKET_READ: - return "TA_SOCKET_READ"; - - case TA_SOCKET_READ_RESIDUAL: - return "TA_SOCKET_READ_RESIDUAL"; - - case TA_SOCKET_WRITE: - return "TA_SOCKET_WRITE"; - - case TA_SOCKET_WRITE_READY: - return "TA_SOCKET_WRITE_READY"; - - case TA_SOCKET_WRITE_DEFERRED: - return "TA_SOCKET_WRITE_DEFERRED"; - - case TA_TUN_READ: - return "TA_TUN_READ"; - - case TA_TUN_WRITE: - return "TA_TUN_WRITE"; - - case TA_INITIAL: - return "TA_INITIAL"; - - case TA_TIMEOUT: - return "TA_TIMEOUT"; - - case TA_TUN_WRITE_TIMEOUT: - return "TA_TUN_WRITE_TIMEOUT"; - - default: - return "?"; - } -} -#endif /* ENABLE_DEBUG */ - -static struct multi_instance * +struct multi_instance * multi_create_instance_tcp(struct multi_context *m, struct link_socket *ls) { struct gc_arena gc =3D gc_new(); @@ -180,126 +119,19 @@ mbuf_free(mi->tcp_link_out_deferred); } -struct multi_tcp * -multi_tcp_init(int maxevents, int *maxclients) -{ - struct multi_tcp *mtcp; - const int extra_events =3D BASE_N_EVENTS; - - ASSERT(maxevents >=3D 1); - ASSERT(maxclients); - - ALLOC_OBJ_CLEAR(mtcp, struct multi_tcp); - mtcp->maxevents =3D maxevents + extra_events; - mtcp->es =3D event_set_init(&mtcp->maxevents, 0); - wait_signal(mtcp->es, MTCP_SIG); - ALLOC_ARRAY(mtcp->esr, struct event_set_return, mtcp->maxevents); - *maxclients =3D max_int(min_int(mtcp->maxevents - extra_events, *maxcl= ients), 1); - msg(D_MULTI_LOW, "MULTI: TCP INIT maxclients=3D%d maxevents=3D%d", *ma= xclients, mtcp->maxevents); - return mtcp; -} - void -multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event) -{ - if (mtcp && mtcp->es) - { - event_del(mtcp->es, event); - } -} - -void -multi_tcp_free(struct multi_tcp *mtcp) -{ - if (mtcp) - { - event_free(mtcp->es); - free(mtcp->esr); - free(mtcp); - } -} - -void -multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instan= ce *mi) +multi_tcp_dereference_instance(struct multi_protocol *multi_io, struct mul= ti_instance *mi) { struct link_socket *ls =3D mi->context.c2.link_sockets[0]; if (ls && mi->socket_set_called) { - event_del(mtcp->es, socket_event_handle(ls)); + event_del(multi_io->es, socket_event_handle(ls)); mi->socket_set_called =3D false; } - mtcp->n_esr =3D 0; + multi_io->n_esr =3D 0; } -static inline void -multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instan= ce *mi) -{ - if (mi) - { - mi->socket_set_called =3D true; - socket_set(mi->context.c2.link_sockets[0], - m->mtcp->es, - mbuf_defined(mi->tcp_link_out_deferred) ? EVENT_WRITE := EVENT_READ, - &mi->ev_arg, - &mi->tcp_rwflags); - } -} - -int -multi_tcp_wait(struct context *c, - struct multi_tcp *mtcp) -{ - int status, i; - unsigned int *persistent =3D &mtcp->tun_rwflags; - - for (i =3D 0; i < c->c1.link_sockets_num; i++) - { - socket_set_listen_persistent(c->c2.link_sockets[i], mtcp->es, - &c->c2.link_sockets[i]->ev_arg); - } - -#ifdef _WIN32 - if (tuntap_is_wintun(c->c1.tuntap)) - { - if (!tuntap_ring_empty(c->c1.tuntap)) - { - /* there is data in wintun ring buffer, read it immediately */ - mtcp->esr[0].arg =3D MTCP_TUN; - mtcp->esr[0].rwflags =3D EVENT_READ; - mtcp->n_esr =3D 1; - return 1; - } - persistent =3D NULL; - } -#endif - tun_set(c->c1.tuntap, mtcp->es, EVENT_READ, MTCP_TUN, persistent); -#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) - dco_event_set(&c->c1.tuntap->dco, mtcp->es, MTCP_DCO); -#endif - -#ifdef ENABLE_MANAGEMENT - if (management) - { - management_socket_set(management, mtcp->es, MTCP_MANAGEMENT, &mtcp= ->management_persist_flags); - } -#endif - -#ifdef ENABLE_ASYNC_PUSH - /* arm inotify watcher */ - event_ctl(mtcp->es, c->c2.inotify_fd, EVENT_READ, MTCP_FILE_CLOSE_WRIT= E); -#endif - - status =3D event_wait(mtcp->es, &c->c2.timeval, mtcp->esr, mtcp->maxev= ents); - update_time(); - mtcp->n_esr =3D 0; - if (status > 0) - { - mtcp->n_esr =3D status; - } - return status; -} - -static inline struct context * +struct context * multi_tcp_context(struct multi_context *m, struct multi_instance *mi) { if (mi) @@ -312,7 +144,7 @@ } } -static bool +bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct mult= i_instance *mi, const unsigned int mpp_flags) { struct mbuf_item item; @@ -336,7 +168,7 @@ return ret; } -static bool +bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const= unsigned int mpp_flags) { struct multi_instance *mi =3D multi_process_outgoing_link_pre(m); @@ -379,566 +211,3 @@ } return ret; } - -static int -multi_tcp_wait_lite(struct multi_context *m, struct multi_instance *mi, co= nst int action, bool *tun_input_pending) -{ - struct context *c =3D multi_tcp_context(m, mi); - unsigned int looking_for =3D 0; - - dmsg(D_MULTI_DEBUG, "MULTI TCP: multi_tcp_wait_lite a=3D%s mi=3D" ptr_= format, - pract(action), - (ptr_type)mi); - - tv_clear(&c->c2.timeval); /* ZERO-TIMEOUT */ - - switch (action) - { - case TA_TUN_READ: - looking_for =3D TUN_READ; - tun_input_pending =3D NULL; - io_wait(c, IOW_READ_TUN); - break; - - case TA_SOCKET_READ: - looking_for =3D SOCKET_READ; - tun_input_pending =3D NULL; - io_wait(c, IOW_READ_LINK); - break; - - case TA_TUN_WRITE: - looking_for =3D TUN_WRITE; - tun_input_pending =3D NULL; - c->c2.timeval.tv_sec =3D 1; /* For some reason, the Linux 2.2 = TUN/TAP driver hits this timeout */ - perf_push(PERF_PROC_OUT_TUN_MTCP); - io_wait(c, IOW_TO_TUN); - perf_pop(); - break; - - case TA_SOCKET_WRITE: - looking_for =3D SOCKET_WRITE; - io_wait(c, IOW_TO_LINK|IOW_READ_TUN_FORCE); - break; - - default: - msg(M_FATAL, "MULTI TCP: multi_tcp_wait_lite, unhandled action= =3D%d", action); - } - - if (tun_input_pending && (c->c2.event_set_status & TUN_READ)) - { - *tun_input_pending =3D true; - } - - if (c->c2.event_set_status & looking_for) - { - return action; - } - else - { - switch (action) - { - /* TCP socket output buffer is full */ - case TA_SOCKET_WRITE: - return TA_SOCKET_WRITE_DEFERRED; - - /* TUN device timed out on accepting write */ - case TA_TUN_WRITE: - return TA_TUN_WRITE_TIMEOUT; - } - - return TA_UNDEF; - } -} - -static struct multi_instance * -multi_tcp_dispatch(struct multi_context *m, struct multi_instance *mi, con= st int action) -{ - const unsigned int mpp_flags =3D MPP_PRE_SELECT|MPP_RECORD_TOUCH; - struct multi_instance *touched =3D mi; - m->mpp_touched =3D &touched; - - dmsg(D_MULTI_DEBUG, "MULTI TCP: multi_tcp_dispatch a=3D%s mi=3D" ptr_f= ormat, - pract(action), - (ptr_type)mi); - - switch (action) - { - case TA_TUN_READ: - read_incoming_tun(&m->top); - if (!IS_SIG(&m->top)) - { - multi_process_incoming_tun(m, mpp_flags); - } - break; - - case TA_SOCKET_READ: - case TA_SOCKET_READ_RESIDUAL: - ASSERT(mi); - ASSERT(mi->context.c2.link_sockets); - ASSERT(mi->context.c2.link_sockets[0]); - set_prefix(mi); - read_incoming_link(&mi->context, mi->context.c2.link_sockets[0= ]); - clear_prefix(); - if (!IS_SIG(&mi->context)) - { - multi_process_incoming_link(m, mi, mpp_flags, - mi->context.c2.link_sockets[0]= ); - if (!IS_SIG(&mi->context)) - { - stream_buf_read_setup(mi->context.c2.link_sockets[0]); - } - } - break; - - case TA_TIMEOUT: - multi_process_timeout(m, mpp_flags); - break; - - case TA_TUN_WRITE: - multi_process_outgoing_tun(m, mpp_flags); - break; - - case TA_TUN_WRITE_TIMEOUT: - multi_process_drop_outgoing_tun(m, mpp_flags); - break; - - case TA_SOCKET_WRITE_READY: - ASSERT(mi); - multi_tcp_process_outgoing_link_ready(m, mi, mpp_flags); - break; - - case TA_SOCKET_WRITE: - multi_tcp_process_outgoing_link(m, false, mpp_flags); - break; - - case TA_SOCKET_WRITE_DEFERRED: - multi_tcp_process_outgoing_link(m, true, mpp_flags); - break; - - case TA_INITIAL: - ASSERT(mi); - multi_tcp_set_global_rw_flags(m, mi); - multi_process_post(m, mi, mpp_flags); - break; - - default: - msg(M_FATAL, "MULTI TCP: multi_tcp_dispatch, unhandled action= =3D%d", action); - } - - m->mpp_touched =3D NULL; - return touched; -} - -static int -multi_tcp_post(struct multi_context *m, struct multi_instance *mi, const i= nt action) -{ - struct context *c =3D multi_tcp_context(m, mi); - int newaction =3D TA_UNDEF; - -#define MTP_NONE 0 -#define MTP_TUN_OUT (1<<0) -#define MTP_LINK_OUT (1<<1) - unsigned int flags =3D MTP_NONE; - - if (TUN_OUT(c)) - { - flags |=3D MTP_TUN_OUT; - } - if (LINK_OUT(c)) - { - flags |=3D MTP_LINK_OUT; - } - - switch (flags) - { - case MTP_TUN_OUT|MTP_LINK_OUT: - case MTP_TUN_OUT: - newaction =3D TA_TUN_WRITE; - break; - - case MTP_LINK_OUT: - newaction =3D TA_SOCKET_WRITE; - break; - - case MTP_NONE: - if (mi && sockets_read_residual(c)) - { - newaction =3D TA_SOCKET_READ_RESIDUAL; - } - else - { - multi_tcp_set_global_rw_flags(m, mi); - } - break; - - default: - { - struct gc_arena gc =3D gc_new(); - msg(M_FATAL, "MULTI TCP: multi_tcp_post bad state, mi=3D%s fla= gs=3D%d", - multi_instance_string(mi, false, &gc), - flags); - gc_free(&gc); - break; - } - } - - dmsg(D_MULTI_DEBUG, "MULTI TCP: multi_tcp_post %s -> %s", - pract(action), - pract(newaction)); - - return newaction; -} - -void -multi_tcp_action(struct multi_context *m, struct multi_instance *mi, int a= ction, bool poll) -{ - bool tun_input_pending =3D false; - - do - { - dmsg(D_MULTI_DEBUG, "MULTI TCP: multi_tcp_action a=3D%s p=3D%d", - pract(action), - poll); - - /* - * If TA_SOCKET_READ_RESIDUAL, it means we still have pending - * input packets which were read by a prior TCP recv. - * - * Otherwise do a "lite" wait, which means we wait with 0 timeout - * on I/O events only related to the current instance, not - * the big list of events. - * - * On our first pass, poll will be false because we already know - * that input is available, and to call io_wait would be redundant. - */ - if (poll && action !=3D TA_SOCKET_READ_RESIDUAL) - { - const int orig_action =3D action; - action =3D multi_tcp_wait_lite(m, mi, action, &tun_input_pendi= ng); - if (action =3D=3D TA_UNDEF) - { - msg(M_FATAL, "MULTI TCP: I/O wait required blocking in mul= ti_tcp_action, action=3D%d", orig_action); - } - } - - /* - * Dispatch the action - */ - struct multi_instance *touched =3D multi_tcp_dispatch(m, mi, actio= n); - - /* - * Signal received or TCP connection - * reset by peer? - */ - if (touched && IS_SIG(&touched->context)) - { - if (mi =3D=3D touched) - { - mi =3D NULL; - } - multi_close_instance_on_signal(m, touched); - } - - - /* - * If dispatch produced any pending output - * for a particular instance, point to - * that instance. - */ - if (m->pending) - { - mi =3D m->pending; - } - - /* - * Based on the effects of the action, - * such as generating pending output, - * possibly transition to a new action state. - */ - action =3D multi_tcp_post(m, mi, action); - - /* - * If we are finished processing the original action, - * check if we have any TUN input. If so, transition - * our action state to processing this input. - */ - if (tun_input_pending && action =3D=3D TA_UNDEF) - { - action =3D TA_TUN_READ; - mi =3D NULL; - tun_input_pending =3D false; - poll =3D false; - } - else - { - poll =3D true; - } - - } while (action !=3D TA_UNDEF); -} - -void -multi_tcp_process_io(struct multi_context *m) -{ - struct multi_tcp *mtcp =3D m->mtcp; - const unsigned int udp_status =3D mtcp->udp_flags; - const unsigned int mpp_flags =3D m->top.c2.fast_io - ? (MPP_CONDITIONAL_PRE_SELECT | MPP_CLO= SE_ON_SIGNAL) - : (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL= ); - int i; - - for (i =3D 0; i < mtcp->n_esr; ++i) - { - struct event_set_return *e =3D &mtcp->esr[i]; - struct event_arg *ev_arg =3D (struct event_arg *)e->arg; - - /* incoming data for instance or listening socket? */ - if (e->arg >=3D MULTI_N) - { - switch (ev_arg->type) - { - struct multi_instance *mi; - - /* react to event on child instance */ - case EVENT_ARG_MULTI_INSTANCE: - if (!ev_arg->u.mi) - { - msg(D_MULTI_ERRORS, "MULTI: mtcp_proc_io: null min= stance"); - break; - } - - mi =3D ev_arg->u.mi; - if (e->rwflags & EVENT_WRITE) - { - multi_tcp_action(m, mi, TA_SOCKET_WRITE_READY, fal= se); - } - else if (e->rwflags & EVENT_READ) - { - multi_tcp_action(m, mi, TA_SOCKET_READ, false); - } - break; - - /* new incoming TCP client attempting to connect? */ - case EVENT_ARG_LINK_SOCKET: - if (!ev_arg->u.ls) - { - msg(D_MULTI_ERRORS, "MULTI: mtcp_proc_io: null soc= ket"); - break; - } - - if (!proto_is_dgram(ev_arg->u.ls->info.proto)) - { - socket_reset_listen_persistent(ev_arg->u.ls); - mi =3D multi_create_instance_tcp(m, ev_arg->u.ls); - if (mi) - { - multi_tcp_action(m, mi, TA_INITIAL, false); - } - break; - } - else - { - if (e->arg >=3D MULTI_N) - { - struct event_arg *ev_arg =3D (struct event_arg= *)e->arg; - if (ev_arg->type !=3D EVENT_ARG_LINK_SOCKET) - { - mtcp->udp_flags =3D ES_ERROR; - msg(D_LINK_ERRORS, - "io_work: non socket event delivered"); - break; - } - } - else - { - ev_arg->pending =3D true; - } - - if (udp_status & SOCKET_READ) - { - read_incoming_link(&m->top, ev_arg->u.ls); - if (!IS_SIG(&m->top)) - { - multi_process_incoming_link(m, NULL, mpp_f= lags, - ev_arg->u.ls); - } - } - - while (true) - { - multi_get_timeout(m, &m->top.c2.timeval); - get_io_flags_udp(&m->top, m->mtcp, p2mp_iow_fl= ags(m)); - MULTI_CHECK_SIG(m); - - multi_process_per_second_timers(m); - - if (m->mtcp->udp_flags =3D=3D ES_TIMEOUT) - { - multi_process_timeout(m, MPP_PRE_SELECT | = MPP_CLOSE_ON_SIGNAL); - } - else - { - multi_process_io_udp(m); - MULTI_CHECK_SIG(m); - break; - } - } - break; - } - } - } - else - { -#ifdef ENABLE_MANAGEMENT - if (e->arg =3D=3D MTCP_MANAGEMENT) - { - ASSERT(management); - management_io(management); - } - else -#endif - /* incoming data on TUN? */ - if (e->arg =3D=3D MTCP_TUN) - { - if (e->rwflags & EVENT_WRITE) - { - multi_tcp_action(m, NULL, TA_TUN_WRITE, false); - } - else if (e->rwflags & EVENT_READ) - { - multi_tcp_action(m, NULL, TA_TUN_READ, false); - } - } - /* new incoming TCP client attempting to connect? */ - else if (e->arg =3D=3D MTCP_SOCKET) - { - struct multi_instance *mi; - ASSERT(m->top.c2.link_sockets[0]); - socket_reset_listen_persistent(m->top.c2.link_sockets[0]); - mi =3D multi_create_instance_tcp(m, m->top.c2.link_sockets= [0]); - if (mi) - { - multi_tcp_action(m, mi, TA_INITIAL, false); - } - } -#if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBS= D)) - /* incoming data on DCO? */ - else if (e->arg =3D=3D MTCP_DCO) - { - multi_process_incoming_dco(m); - } -#endif - /* signal received? */ - else if (e->arg =3D=3D MTCP_SIG) - { - get_signal(&m->top.sig->signal_received); - } -#ifdef ENABLE_ASYNC_PUSH - else if (e->arg =3D=3D MTCP_FILE_CLOSE_WRITE) - { - multi_process_file_closed(m, MPP_PRE_SELECT | MPP_RECORD_T= OUCH); - } -#endif - } - if (IS_SIG(&m->top)) - { - break; - } - } - mtcp->n_esr =3D 0; - - /* - * Process queued mbuf packets destined for TCP socket - */ - { - struct multi_instance *mi; - while (!IS_SIG(&m->top) && (mi =3D mbuf_peek(m->mbuf)) !=3D NULL) - { - multi_tcp_action(m, mi, TA_SOCKET_WRITE, true); - } - } -} - -/* - * Top level event loop for single-threaded operation. - * TCP mode. - */ -void -tunnel_server_tcp(struct context *top) -{ - struct multi_context multi; - int status; - - top->mode =3D CM_TOP; - context_clear_2(top); - - /* initialize top-tunnel instance */ - init_instance_handle_signals(top, top->es, CC_HARD_USR1_TO_HUP); - if (IS_SIG(top)) - { - return; - } - - /* initialize global multi_context object */ - multi_init(&multi, top); - - /* initialize our cloned top object */ - multi_top_init(&multi, top); - - /* initialize management interface */ - init_management_callback_multi(&multi); - - /* finished with initialization */ - initialization_sequence_completed(top, ISC_SERVER); /* --mode server -= -proto tcp-server */ - -#ifdef ENABLE_ASYNC_PUSH - multi.top.c2.inotify_fd =3D inotify_init(); - if (multi.top.c2.inotify_fd < 0) - { - msg(D_MULTI_ERRORS | M_ERRNO, "MULTI: inotify_init error"); - } -#endif - - /* per-packet event loop */ - while (true) - { - perf_push(PERF_EVENT_LOOP); - - /* wait on tun/socket list */ - multi_get_timeout(&multi, &multi.top.c2.timeval); - status =3D multi_tcp_wait(&multi.top, multi.mtcp); - MULTI_CHECK_SIG(&multi); - - /* check on status of coarse timers */ - multi_process_per_second_timers(&multi); - - /* timeout? */ - if (status > 0) - { - /* process the I/O which triggered select */ - /*multi_tcp_process_io(&multi); */ - MULTI_CHECK_SIG(&multi); - } - else if (status =3D=3D 0) - { - /*multi_tcp_action(&multi, NULL, TA_TIMEOUT, false); */ - } - - perf_pop(); - } - -#ifdef ENABLE_ASYNC_PUSH - close(top->c2.inotify_fd); -#endif - - /* shut down management interface */ - uninit_management_callback(); - - /* save ifconfig-pool */ - multi_ifconfig_pool_persist(&multi, true); - - /* tear down tunnel instance (unless --persist-tun) */ - multi_uninit(&multi); - multi_top_free(&multi); - close_instance(top); -} diff --git a/src/openvpn/mtcp.h b/src/openvpn/mtcp.h index d55bdfd..b8a0191 100644 --- a/src/openvpn/mtcp.h +++ b/src/openvpn/mtcp.h @@ -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_i= nstance *mi); +void multi_tcp_dereference_instance(struct multi_protocol *multi_io, struc= t multi_instance *mi); bool multi_tcp_instance_specific_init(struct multi_context *m, struct mult= i_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_ins= tance *mi); +struct context *multi_tcp_context(struct multi_context *m, struct multi_in= stance *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 */ diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index 8945a55..d29f7a5 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -379,7 +379,7 @@ void multi_process_io_udp(struct multi_context *m) { - unsigned int status =3D m->mtcp->udp_flags; + unsigned int status =3D m->multi_io->udp_flags; const unsigned int mpp_flags =3D m->top.c2.fast_io ? (MPP_CONDITIONAL_PRE_SELECT | MPP_CLO= SE_ON_SIGNAL) : (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL= ); diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 108a5a8..b29134e 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -440,7 +440,7 @@ /* * Initialize multi-socket TCP I/O wait object */ - m->mtcp =3D multi_tcp_init(t->options.max_clients, &m->max_clients); + m->multi_io =3D multi_protocol_init(t->options.max_clients, &m->max_cl= ients); m->tcp_queue_limit =3D 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 =3D (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 =3D multi_tcp_wait(&multi->top, multi->mtcp); + status =3D 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 =3D=3D 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) { diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 472c2a3..dd7a29c 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -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 us= ing both TCP + * and UDP as external transpor= t. */ struct ifconfig_pool *ifconfig_pool; struct frequency_limit *new_connection_limiter; struct initial_packet_rate_limit *initial_rate_limiter; diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c new file mode 100644 index 0000000..a1ea7fb --- /dev/null +++ b/src/openvpn/multi_io.c @@ -0,0 +1,687 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single TCP/UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2002-2023 OpenVPN Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "syshead.h" + +#include "memdbg.h" + +#include "multi.h" +#include "forward.h" +#include "multi_io.h" + +#ifdef HAVE_SYS_INOTIFY_H +#include +#endif + +/* + * Special tags passed to event.[ch] functions + */ +#define MULTI_IO_SOCKET ((void *)1) +#define MULTI_IO_TUN ((void *)2) +#define MULTI_IO_SIG ((void *)3) /* Only on Windows */ +#define MULTI_IO_MANAGEMENT ((void *)4) +#define MULTI_IO_FILE_CLOSE_WRITE ((void *)5) +#define MULTI_IO_DCO ((void *)6) + +struct ta_iow_flags +{ + unsigned int flags; + unsigned int ret; + unsigned int tun; + unsigned int sock; +}; + +#ifdef ENABLE_DEBUG +static const char * +pract(int action) +{ + switch (action) + { + case TA_UNDEF: + return "TA_UNDEF"; + + case TA_SOCKET_READ: + return "TA_SOCKET_READ"; + + case TA_SOCKET_READ_RESIDUAL: + return "TA_SOCKET_READ_RESIDUAL"; + + case TA_SOCKET_WRITE: + return "TA_SOCKET_WRITE"; + + case TA_SOCKET_WRITE_READY: + return "TA_SOCKET_WRITE_READY"; + + case TA_SOCKET_WRITE_DEFERRED: + return "TA_SOCKET_WRITE_DEFERRED"; + + case TA_TUN_READ: + return "TA_TUN_READ"; + + case TA_TUN_WRITE: + return "TA_TUN_WRITE"; + + case TA_INITIAL: + return "TA_INITIAL"; + + case TA_TIMEOUT: + return "TA_TIMEOUT"; + + case TA_TUN_WRITE_TIMEOUT: + return "TA_TUN_WRITE_TIMEOUT"; + + default: + return "?"; + } +} +#endif /* ENABLE_DEBUG */ + +struct multi_protocol * +multi_protocol_init(int maxevents, int *maxclients) +{ + struct multi_protocol *multi_io; + const int extra_events =3D BASE_N_EVENTS; + + ASSERT(maxevents >=3D 1); + ASSERT(maxclients); + + ALLOC_OBJ_CLEAR(multi_io, struct multi_protocol); + multi_io->maxevents =3D maxevents + extra_events; + multi_io->es =3D event_set_init(&multi_io->maxevents, 0); + wait_signal(multi_io->es, MULTI_IO_SIG); + ALLOC_ARRAY(multi_io->esr, struct event_set_return, multi_io->maxevent= s); + *maxclients =3D max_int(min_int(multi_io->maxevents - extra_events, *m= axclients), 1); + msg(D_MULTI_LOW, "MULTI: TCP INIT maxclients=3D%d maxevents=3D%d", *ma= xclients, multi_io->maxevents); + return multi_io; +} + +void +multi_protocol_free(struct multi_protocol *multi_io) +{ + if (multi_io) + { + event_free(multi_io->es); + free(multi_io->esr); + free(multi_io); + } +} + +int +multi_protocol_io_wait(struct context *c, + struct multi_protocol *multi_io) +{ + int status, i; + unsigned int *persistent =3D &multi_io->tun_rwflags; + + for (i =3D 0; i < c->c1.link_sockets_num; i++) + { + socket_set_listen_persistent(c->c2.link_sockets[i], multi_io->es, + &c->c2.link_sockets[i]->ev_arg); + } + +#ifdef _WIN32 + if (tuntap_is_wintun(c->c1.tuntap)) + { + if (!tuntap_ring_empty(c->c1.tuntap)) + { + /* there is data in wintun ring buffer, read it immediately */ + multi_io->esr[0].arg =3D MULTI_IO_TUN; + multi_io->esr[0].rwflags =3D EVENT_READ; + multi_io->n_esr =3D 1; + return 1; + } + persistent =3D NULL; + } +#endif + tun_set(c->c1.tuntap, multi_io->es, EVENT_READ, MULTI_IO_TUN, persiste= nt); +#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) + dco_event_set(&c->c1.tuntap->dco, multi_io->es, MULTI_IO_DCO); +#endif + +#ifdef ENABLE_MANAGEMENT + if (management) + { + management_socket_set(management, multi_io->es, MULTI_IO_MANAGEMEN= T, &multi_io->management_persist_flags); + } +#endif + +#ifdef ENABLE_ASYNC_PUSH + /* arm inotify watcher */ + event_ctl(multi_io->es, c->c2.inotify_fd, EVENT_READ, MULTI_IO_FILE_CL= OSE_WRITE); +#endif + + status =3D event_wait(multi_io->es, &c->c2.timeval, multi_io->esr, mul= ti_io->maxevents); + update_time(); + multi_io->n_esr =3D 0; + if (status > 0) + { + multi_io->n_esr =3D status; + } + return status; +} + +static int +multi_protocol_wait_lite(struct multi_context *m, struct multi_instance *m= i, const int action, bool *tun_input_pending) +{ + struct context *c =3D multi_tcp_context(m, mi); + unsigned int looking_for =3D 0; + + dmsg(D_MULTI_DEBUG, "MULTI PROTOCOL: multi_protocol_wait_lite a=3D%s m= i=3D" ptr_format, + pract(action), + (ptr_type)mi); + + tv_clear(&c->c2.timeval); /* ZERO-TIMEOUT */ + + switch (action) + { + case TA_TUN_READ: + looking_for =3D TUN_READ; + tun_input_pending =3D NULL; + io_wait(c, IOW_READ_TUN); + break; + + case TA_SOCKET_READ: + looking_for =3D SOCKET_READ; + tun_input_pending =3D NULL; + io_wait(c, IOW_READ_LINK); + break; + + case TA_TUN_WRITE: + looking_for =3D TUN_WRITE; + tun_input_pending =3D NULL; + c->c2.timeval.tv_sec =3D 1; /* For some reason, the Linux 2.2 = TUN/TAP driver hits this timeout */ + perf_push(PERF_PROC_OUT_TUN_MTCP); + io_wait(c, IOW_TO_TUN); + perf_pop(); + break; + + case TA_SOCKET_WRITE: + looking_for =3D SOCKET_WRITE; + io_wait(c, IOW_TO_LINK|IOW_READ_TUN_FORCE); + break; + + default: + msg(M_FATAL, "MULTI PROTOCOL: multi_protocol_wait_lite, unhand= led action=3D%d", action); + } + + if (tun_input_pending && (c->c2.event_set_status & TUN_READ)) + { + *tun_input_pending =3D true; + } + + if (c->c2.event_set_status & looking_for) + { + return action; + } + else + { + switch (action) + { + /* MULTI PROTOCOL socket output buffer is full */ + case TA_SOCKET_WRITE: + return TA_SOCKET_WRITE_DEFERRED; + + /* TUN device timed out on accepting write */ + case TA_TUN_WRITE: + return TA_TUN_WRITE_TIMEOUT; + } + + return TA_UNDEF; + } +} + +static inline void +multi_protocol_set_global_rw_flags(struct multi_context *m, struct multi_i= nstance *mi) +{ + if (mi) + { + mi->socket_set_called =3D true; + socket_set(mi->context.c2.link_sockets[0], + m->multi_io->es, + mbuf_defined(mi->tcp_link_out_deferred) ? EVENT_WRITE := EVENT_READ, + &mi->ev_arg, + &mi->tcp_rwflags); + } +} + +static struct multi_instance * +multi_protocol_dispatch(struct multi_context *m, struct multi_instance *mi= , const int action) +{ + const unsigned int mpp_flags =3D MPP_PRE_SELECT|MPP_RECORD_TOUCH; + struct multi_instance *touched =3D mi; + m->mpp_touched =3D &touched; + + dmsg(D_MULTI_DEBUG, "MULTI PROTOCOL: multi_protocol_dispatch a=3D%s mi= =3D" ptr_format, + pract(action), + (ptr_type)mi); + + switch (action) + { + case TA_TUN_READ: + read_incoming_tun(&m->top); + if (!IS_SIG(&m->top)) + { + multi_process_incoming_tun(m, mpp_flags); + } + break; + + case TA_SOCKET_READ: + case TA_SOCKET_READ_RESIDUAL: + ASSERT(mi); + ASSERT(mi->context.c2.link_sockets); + ASSERT(mi->context.c2.link_sockets[0]); + set_prefix(mi); + read_incoming_link(&mi->context, mi->context.c2.link_sockets[0= ]); + clear_prefix(); + if (!IS_SIG(&mi->context)) + { + multi_process_incoming_link(m, mi, mpp_flags, + mi->context.c2.link_sockets[0]= ); + if (!IS_SIG(&mi->context)) + { + stream_buf_read_setup(mi->context.c2.link_sockets[0]); + } + } + break; + + case TA_TIMEOUT: + multi_process_timeout(m, mpp_flags); + break; + + case TA_TUN_WRITE: + multi_process_outgoing_tun(m, mpp_flags); + break; + + case TA_TUN_WRITE_TIMEOUT: + multi_process_drop_outgoing_tun(m, mpp_flags); + break; + + case TA_SOCKET_WRITE_READY: + ASSERT(mi); + multi_tcp_process_outgoing_link_ready(m, mi, mpp_flags); + break; + + case TA_SOCKET_WRITE: + multi_tcp_process_outgoing_link(m, false, mpp_flags); + break; + + case TA_SOCKET_WRITE_DEFERRED: + multi_tcp_process_outgoing_link(m, true, mpp_flags); + break; + + case TA_INITIAL: + ASSERT(mi); + multi_protocol_set_global_rw_flags(m, mi); + multi_process_post(m, mi, mpp_flags); + break; + + default: + msg(M_FATAL, "MULTI PROTOCOL: multi_protocol_dispatch, unhandl= ed action=3D%d", action); + } + + m->mpp_touched =3D NULL; + return touched; +} + +static int +multi_protocol_post(struct multi_context *m, struct multi_instance *mi, co= nst int action) +{ + struct context *c =3D multi_tcp_context(m, mi); + int newaction =3D TA_UNDEF; + +#define MTP_NONE 0 +#define MTP_TUN_OUT (1<<0) +#define MTP_LINK_OUT (1<<1) + unsigned int flags =3D MTP_NONE; + + if (TUN_OUT(c)) + { + flags |=3D MTP_TUN_OUT; + } + if (LINK_OUT(c)) + { + flags |=3D MTP_LINK_OUT; + } + + switch (flags) + { + case MTP_TUN_OUT|MTP_LINK_OUT: + case MTP_TUN_OUT: + newaction =3D TA_TUN_WRITE; + break; + + case MTP_LINK_OUT: + newaction =3D TA_SOCKET_WRITE; + break; + + case MTP_NONE: + if (mi && sockets_read_residual(c)) + { + newaction =3D TA_SOCKET_READ_RESIDUAL; + } + else + { + multi_protocol_set_global_rw_flags(m, mi); + } + break; + + default: + { + struct gc_arena gc =3D gc_new(); + msg(M_FATAL, "MULTI PROTOCOL: multi_protocol_post bad state, m= i=3D%s flags=3D%d", + multi_instance_string(mi, false, &gc), + flags); + gc_free(&gc); + break; + } + } + + dmsg(D_MULTI_DEBUG, "MULTI PROTOCOL: multi_protocol_post %s -> %s", + pract(action), + pract(newaction)); + + return newaction; +} + +void +multi_protocol_process_io(struct multi_context *m) +{ + struct multi_protocol *multi_io =3D m->multi_io; + const unsigned int udp_status =3D multi_io->udp_flags; + const unsigned int mpp_flags =3D m->top.c2.fast_io + ? (MPP_CONDITIONAL_PRE_SELECT | MPP_CLO= SE_ON_SIGNAL) + : (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL= ); + int i; + + for (i =3D 0; i < multi_io->n_esr; ++i) + { + struct event_set_return *e =3D &multi_io->esr[i]; + struct event_arg *ev_arg =3D (struct event_arg *)e->arg; + + /* incoming data for instance or listening socket? */ + if (e->arg >=3D MULTI_N) + { + switch (ev_arg->type) + { + struct multi_instance *mi; + + /* react to event on child instance */ + case EVENT_ARG_MULTI_INSTANCE: + if (!ev_arg->u.mi) + { + msg(D_MULTI_ERRORS, "MULTI PROTOCOL: multi_proto_p= roc_io: null minstance"); + break; + } + + mi =3D ev_arg->u.mi; + if (e->rwflags & EVENT_WRITE) + { + multi_protocol_action(m, mi, TA_SOCKET_WRITE_READY= , false); + } + else if (e->rwflags & EVENT_READ) + { + multi_protocol_action(m, mi, TA_SOCKET_READ, false= ); + } + break; + + /* new incoming TCP client attempting to connect? */ + case EVENT_ARG_LINK_SOCKET: + if (!ev_arg->u.ls) + { + msg(D_MULTI_ERRORS, "MULTI PROTOCOL: multi_proto_p= roc_io: null socket"); + break; + } + + if (!proto_is_dgram(ev_arg->u.ls->info.proto)) + { + socket_reset_listen_persistent(ev_arg->u.ls); + mi =3D multi_create_instance_tcp(m, ev_arg->u.ls); + if (mi) + { + multi_protocol_action(m, mi, TA_INITIAL, false= ); + } + break; + } + else + { + if (e->arg >=3D MULTI_N) + { + struct event_arg *ev_arg =3D (struct event_arg= *)e->arg; + if (ev_arg->type !=3D EVENT_ARG_LINK_SOCKET) + { + multi_io->udp_flags =3D ES_ERROR; + msg(D_LINK_ERRORS, + "MULTI PROTOCOL: io_work: non socket e= vent delivered"); + break; + } + } + else + { + ev_arg->pending =3D true; + } + + if (udp_status & SOCKET_READ) + { + read_incoming_link(&m->top, ev_arg->u.ls); + if (!IS_SIG(&m->top)) + { + multi_process_incoming_link(m, NULL, mpp_f= lags, + ev_arg->u.ls); + } + } + + while (true) + { + multi_get_timeout(m, &m->top.c2.timeval); + get_io_flags_udp(&m->top, m->multi_io, p2mp_io= w_flags(m)); + MULTI_CHECK_SIG(m); + + multi_process_per_second_timers(m); + + if (m->multi_io->udp_flags =3D=3D ES_TIMEOUT) + { + multi_process_timeout(m, MPP_PRE_SELECT | = MPP_CLOSE_ON_SIGNAL); + } + else + { + multi_process_io_udp(m); + MULTI_CHECK_SIG(m); + break; + } + } + break; + } + } + } + else + { +#ifdef ENABLE_MANAGEMENT + if (e->arg =3D=3D MULTI_IO_MANAGEMENT) + { + ASSERT(management); + management_io(management); + } + else +#endif + /* incoming data on TUN? */ + if (e->arg =3D=3D MULTI_IO_TUN) + { + if (e->rwflags & EVENT_WRITE) + { + multi_protocol_action(m, NULL, TA_TUN_WRITE, false); + } + else if (e->rwflags & EVENT_READ) + { + multi_protocol_action(m, NULL, TA_TUN_READ, false); + } + } + /* new incoming TCP client attempting to connect? */ + else if (e->arg =3D=3D MULTI_IO_SOCKET) + { + struct multi_instance *mi; + ASSERT(m->top.c2.link_sockets[0]); + socket_reset_listen_persistent(m->top.c2.link_sockets[0]); + mi =3D multi_create_instance_tcp(m, m->top.c2.link_sockets= [0]); + if (mi) + { + multi_protocol_action(m, mi, TA_INITIAL, false); + } + } +#if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBS= D)) + /* incoming data on DCO? */ + else if (e->arg =3D=3D MULTI_IO_DCO) + { + multi_process_incoming_dco(m); + } +#endif + /* signal received? */ + else if (e->arg =3D=3D MULTI_IO_SIG) + { + get_signal(&m->top.sig->signal_received); + } +#ifdef ENABLE_ASYNC_PUSH + else if (e->arg =3D=3D MULTI_IO_FILE_CLOSE_WRITE) + { + multi_process_file_closed(m, MPP_PRE_SELECT | MPP_RECORD_T= OUCH); + } +#endif + } + if (IS_SIG(&m->top)) + { + break; + } + } + multi_io->n_esr =3D 0; + + /* + * Process queued mbuf packets destined for TCP socket + */ + { + struct multi_instance *mi; + while (!IS_SIG(&m->top) && (mi =3D mbuf_peek(m->mbuf)) !=3D NULL) + { + multi_protocol_action(m, mi, TA_SOCKET_WRITE, true); + } + } +} + +void +multi_protocol_action(struct multi_context *m, struct multi_instance *mi, = int action, bool poll) +{ + bool tun_input_pending =3D false; + + do + { + dmsg(D_MULTI_DEBUG, "MULTI PROTOCOL: multi_protocol_action a=3D%s = p=3D%d", + pract(action), + poll); + + /* + * If TA_SOCKET_READ_RESIDUAL, it means we still have pending + * input packets which were read by a prior recv. + * + * Otherwise do a "lite" wait, which means we wait with 0 timeout + * on I/O events only related to the current instance, not + * the big list of events. + * + * On our first pass, poll will be false because we already know + * that input is available, and to call io_wait would be redundant. + */ + if (poll && action !=3D TA_SOCKET_READ_RESIDUAL) + { + const int orig_action =3D action; + action =3D multi_protocol_wait_lite(m, mi, action, &tun_input_= pending); + if (action =3D=3D TA_UNDEF) + { + msg(M_FATAL, "MULTI PROTOCOL: I/O wait required blocking i= n multi_protocol_action, action=3D%d", orig_action); + } + } + + /* + * Dispatch the action + */ + struct multi_instance *touched =3D multi_protocol_dispatch(m, mi, = action); + + /* + * Signal received or connection + * reset by peer? + */ + if (touched && IS_SIG(&touched->context)) + { + if (mi =3D=3D touched) + { + mi =3D NULL; + } + multi_close_instance_on_signal(m, touched); + } + + + /* + * If dispatch produced any pending output + * for a particular instance, point to + * that instance. + */ + if (m->pending) + { + mi =3D m->pending; + } + + /* + * Based on the effects of the action, + * such as generating pending output, + * possibly transition to a new action state. + */ + action =3D multi_protocol_post(m, mi, action); + + /* + * If we are finished processing the original action, + * check if we have any TUN input. If so, transition + * our action state to processing this input. + */ + if (tun_input_pending && action =3D=3D TA_UNDEF) + { + action =3D TA_TUN_READ; + mi =3D NULL; + tun_input_pending =3D false; + poll =3D false; + } + else + { + poll =3D true; + } + + } while (action !=3D TA_UNDEF); +} + +void +multi_protocol_delete_event(struct multi_protocol *multi_io, event_t event) +{ + if (multi_io && multi_io->es) + { + event_del(multi_io->es, event); + } +} diff --git a/src/openvpn/multi_io.h b/src/openvpn/multi_io.h new file mode 100644 index 0000000..bd27f08 --- /dev/null +++ b/src/openvpn/multi_io.h @@ -0,0 +1,77 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single TCP/UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2002-2023 OpenVPN Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * Multi-protocol specific code for --mode server + */ + +#ifndef MULTI_IO_H +#define MULTI_IO_H + +#include "event.h" + +/* + * I/O processing States + */ + +#define TA_UNDEF 0 +#define TA_SOCKET_READ 1 +#define TA_SOCKET_READ_RESIDUAL 2 +#define TA_SOCKET_WRITE 3 +#define TA_SOCKET_WRITE_READY 4 +#define TA_SOCKET_WRITE_DEFERRED 5 +#define TA_TUN_READ 6 +#define TA_TUN_WRITE 7 +#define TA_INITIAL 8 +#define TA_TIMEOUT 9 +#define TA_TUN_WRITE_TIMEOUT 10 + +/* + * Extra state info needed for Multi-protocol + */ +struct multi_protocol +{ + struct event_set *es; + struct event_set_return *esr; + int n_esr; + int maxevents; + unsigned int tun_rwflags; + unsigned int udp_flags; +#ifdef ENABLE_MANAGEMENT + unsigned int management_persist_flags; +#endif +}; + +struct multi_protocol *multi_protocol_init(int maxevents, int *maxclients); + +void multi_protocol_free(struct multi_protocol *multi_io); + +int multi_protocol_io_wait(struct context *c, struct multi_protocol *multi= _io); + +void multi_protocol_process_io(struct multi_context *m); + +void multi_protocol_action(struct multi_context *m, struct multi_instance = *mi, int action, bool poll); + +void multi_protocol_delete_event(struct multi_protocol *multi_io, event_t = event); + +#endif /* ifndef MULTI_IO_H */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/441?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Id2d7957f5950115d9baade4c09fd9679b01f749b Gerrit-Change-Number: 441 Gerrit-PatchSet: 1 Gerrit-Owner: ordex Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --/+HJ+sN5qjY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

ordex would like plaisthos and flichtenheld to review t= his change.

Vi= ew Change

multiproto: move generic event handling code in dedicated fil=
es

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

Renamed the struct mtcp to struc= t multi_protocol since it
encompasses the event_set used by the parent c= ontext in server mode.

Several methods have also been renamed and mo= ved to fit the
multiproto structure:

- multi_tcp_init() -> mul= ti_protocol_init();
- multi_tcp_free() -> multi_protocol_free();
-= multi_tcp_wait() -> multi_protocol_io_wait();
and so forth.

C= hange-Id: Id2d7957f5950115d9baade4c09fd9679b01f749b
Signed-off-by: Gianm= arco De Gregori <gianmarco@...2726...>
---
M CMakeLists.txt
= M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/forwa= rd.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(+), 77= 7 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn re=
fs/changes/41/441/1
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d21c9bd..ee27465 100644
--- a/CMakeList= s.txt
+++ b/CMakeLists.txt
@@ -402,6 +402,8= @@
src/openvpn/mudp.h
src/openvp= n/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
diff --git a/src/openvpn/= Makefile.am b/src/openvpn/Makefile.am
index 52deef8..17fcb1= b 100644
--- a/src/openvpn/Makefile.am
+++ = b/src/openvpn/Makefile.am
@@ -89,6 +89,7 @@
mtu.c mtu.h \

mudp.c mudp.h \
multi.= c multi.h \
+ multi_i= o.c multi_io.h \
networking_freebsd.c \
= networking_iproute2.c networking_iproute2.h \
networking= _sitnl.c networking_sitnl.h \
diff --git a/src/openvpn/forw= ard.c b/src/openvpn/forward.c
index ee18f8b..0e5b611 100644=
--- a/src/openvpn/forward.c
+++ b/src/open= vpn/forward.c
@@ -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_proto= col *multi_io, const unsigned int flags)
{
unsigned int socket =3D 0;

unsigned int tuntap = =3D 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.pro= to))
{
- socket_set(c->c2.link_sockets[i], mtcp->es, soc= ket,
+ soc= ket_set(c->c2.link_sockets[i], multi_io->es, socket,
= &c->c2.link_sockets[i]->ev_arg, NULL);
}
}
- mtcp->udp_flags =3D socket | tuntap;
+ multi_io->udp_flag= s =3D socket | tuntap;
}

void

-get_io_flags_ud= p(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)
{
- mtc= p->udp_flags =3D ES_ERROR;
+ multi_io->udp_flags =3D ES_ERROR;
if = (c->c2.fast_io && (flags & (IOW_TO_TUN | IOW_TO_LINK | IOW_M= BUF)))
{
/* fast path -- only= for TUN/TAP/UDP writes */
@@ -2179,7 +2179,7 @@
= {
ret |=3D SOCKET_WRITE;=
}
- = mtcp->udp_flags =3D ret;
+ multi_io->udp_flags =3D ret;
= }
else
{
@@ -220= 5,13 +2205,13 @@
{
= ret |=3D TUN_READ;
}
- mtcp->udp_flags =3D ret;
+ multi_io-= >udp_flags =3D ret;
}
= else
#endif /* ifdef _WIN32 */
{<= /span>
/* 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, mu= lti_io, flags);
}
} }
diff --git a/src/openvpn/forward.h b/src/openvpn/= forward.h
index 39ac975..a251d04 100644
---= a/src/openvpn/forward.h
+++ b/src/openvpn/forward.h=
@@ -50,7 +50,7 @@
#include "openvpn.h"=
#include "occ.h"
#include &quo= t;ping.h"
-#includ= e "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 */<= /span>
+/*struct multi_conte= xt;
+ * struct multi_= protocol;
+ * struct = context;*/
+ extern counter_type link_read_bytes_global;

extern counter_type link_write_bytes_global;
=
-void get_io_flags_dow= ork_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 unsig= ned 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 *mu= lti_io, const unsigned int flags);

void = io_wait_dowork(struct context *c, const unsigned int flags);

diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c
index 128a375..4efce35 100644
--- a/src/openv= pn/mtcp.c
+++ b/src/openvpn/mtcp.c
@@ -29,6= +29,8 @@

#include "multi.h"
#include "forward.h"
+#include "mtcp.h"
+#include "multi_io.h"
#include "memdbg.h"
<= /span>
@@ -36,70 +38,7 @@
#include <sys/inotif= y.h>
#endif

-/*
- * Special tags passed to event.[ch] functions
- */
-#define MTCP_SOCKET ((void *)1)
-#define MTCP_TUN ((void *)2)=
-#define MTCP_SIG ((v= oid *)3) /* Only on Windows */
-#define MTCP_MANAGEMENT ((void *)4)
-#define MTCP_FILE_CLOSE_WRITE ((void *)5)
= -#define MTCP_DCO ((void *= )6)
-
-struct ta_iow_flags
-{
- unsigned int flags;
- unsigned int ret;
- unsigned int tun;
- unsigned int sock;
-};
-
-#ifdef ENABLE_DEBUG
-static const char *
-pract(int action)-{
- switch (action)
- {
- case TA_UNDEF:
- return "TA_UNDEF";
-
- case TA_SOCKET_READ:
- return "TA_SOCKET_READ";
-
- case TA_SOCKET_READ_RESIDUAL:
- return "TA_SOCKET_READ_RES= IDUAL";
-- case TA_SOCKET_WRITE:<= /span>
- return &qu= ot;TA_SOCKET_WRITE";
-
- case TA_S= OCKET_WRITE_READY:
- = return "TA_SOCKET_WRITE_READY";
-
- case TA_SOCKET_WRITE_DEFERRED:
- return "TA_SOCKET_WRITE_DEFERRED&= quot;;
-
- case TA_TUN_READ:

= - return "TA_TUN_= READ";
-- case TA_TUN_WRITE:
- return "T= A_TUN_WRITE";
-
- case TA_INITIAL:=
- return &q= uot;TA_INITIAL";
-=
- case TA_TIMEO= UT:
- return= "TA_TIMEOUT";
- case TA_TU= N_WRITE_TIMEOUT:
- = return "TA_TUN_WRITE_TIMEOUT";
-
- default:
-= return "?";
- }
-}
-#endif /* ENABLE_DEBUG *= /
-
-static struct multi_instance *
= +struct multi_instance *=
multi_create_instance_tcp(struct multi_context *m, struct link_s= ocket *ls)
{
struct gc_arena gc =3D g= c_new();
@@ -180,126 +119,19 @@
mbuf_f= ree(mi->tcp_link_out_deferred);
}

-struct multi_tcp *=
-multi_tcp_init(int maxevents= , int *maxclients)
-{
- struct multi_tcp *m= tcp;
- const int ext= ra_events =3D BASE_N_EVENTS;
-
- ASSERT(max= events >=3D 1);
- = ASSERT(maxclients);
-<= /span>
- ALLOC_OBJ_CLEAR(mt= cp, struct multi_tcp);
= - mtcp->maxevents =3D maxevents + extra_events;
- mtcp->es =3D event_set_init(&mtc= p->maxevents, 0);
- = wait_signal(mtcp->es, MTCP_SIG);
- ALLOC_ARRAY(mtcp->esr, struct event_set_return, mtc= p->maxevents);
- = *maxclients =3D max_int(min_int(mtcp->maxevents - extra_events, *maxclie= nts), 1);
- msg(D_MU= LTI_LOW, "MULTI: TCP INIT maxclients=3D%d maxevents=3D%d", *maxcl= ients, mtcp->maxevents);
- return mtcp;
= -}
-
v= oid
-multi_tcp_delete_e= vent(struct multi_tcp *mtcp, event_t event)
-{
- if (mtcp && mtcp->es)
- {
= - event_del(mtcp->es, event);
- }
-}
-
-void
-multi_tcp_free(struct multi_tcp *mtcp)
-{
- if (mtcp)
- {
- = event_free(mtcp->es);
- free(mtcp);
- }
-}<= br>-
-void
-multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi= _instance *mi)
+multi= _tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_ins= tance *mi)
{
struct link_socket *ls = =3D mi->context.c2.link_sockets[0];
if (ls &&am= p; mi->socket_set_called)
{
- event_del(mtcp->es, socket_event= _handle(ls));
+ = event_del(multi_io->es, socket_event_handle(ls));
= mi->socket_set_called =3D false;
}
<= span style=3D"color: hsl(0, 100%, 40%);">- mtcp->n_esr =3D 0;
<= br>+ multi_io->n_esr =3D = 0;
}

-static inline void
-multi_tcp_set_global_rw_flags(struct multi_context *m, struc= t multi_instance *mi)
-= {
- if (mi)- {
- mi->socket_set_called =3D true;
- socket_set(mi->= ;context.c2.link_sockets[0],
- m->mtcp->es,
- mbuf_defined(mi->tcp_link_out_= deferred) ? EVENT_WRITE : EVENT_READ,
- &mi->ev_arg,
- &mi->tcp_rwflags= );
- }
-}

-
-i= nt
-multi_tcp_wait(stru= ct context *c,
- = struct multi_tcp *mtcp)
-{
- int st= atus, i;
- unsigned = int *persistent =3D &mtcp->tun_rwflags;
-
- for (i =3D 0; i < c->c1.link_sockets_num; i++)
- {

- socket_set_listen_persistent(c->c2.link_s= ockets[i], mtcp->es,
- &c->c2.link_sockets[i]->ev= _arg);
- }-
-#ifdef _WIN32
- if (tuntap_is_wintun(c->c1.tuntap))
- {
- if (!tuntap_ring_empty(c->c1.tuntap))=
- {
- /* there is data in wintun r= ing buffer, read it immediately */
- mtcp->esr[0].arg =3D MTCP_TUN;
- mtcp->esr[0].rwflags = =3D EVENT_READ;
- = mtcp->n_esr =3D 1;
- return 1;
- }
- = persistent =3D NULL;
= - }
-#endif- tun_set(c->c1.tuntap, m= tcp->es, EVENT_READ, MTCP_TUN, persistent);
-#if defined(TARGET_LINUX) || defined(TARGET_FREEBS= D)
- dco_event_set(&= amp;c->c1.tuntap->dco, mtcp->es, MTCP_DCO);
-#endif
-
-#ifd= ef ENABLE_MANAGEMENT
- = if (management)
- = {
- management_= socket_set(management, mtcp->es, MTCP_MANAGEMENT, &mtcp->manageme= nt_persist_flags);
- = }
-#endif
-

-#ifdef ENABLE_ASYNC_PUSH
- /* arm inotify watcher */
- event_ctl(mtcp->es, c->c2.inotify= _fd, EVENT_READ, MTCP_FILE_CLOSE_WRITE);
-#endif
-
- status =3D ev= ent_wait(mtcp->es, &c->c2.timeval, mtcp->esr, mtcp->maxeven= ts);
- update_time()= ;
- mtcp->n_esr = =3D 0;
- if (status = > 0)
- {- mtcp->n_esr =3D sta= tus;
- }
<= span style=3D"color: hsl(0, 100%, 40%);">- return status;

-}

-
-st= atic inline struct context *
+struct context *
multi_tcp_context(struct multi_c= ontext *m, struct multi_instance *mi)
{
= if (mi)
@@ -312,7 +144,7 @@
}
}

-static bool
+bool
multi_tcp_process_outgoing_link_ready(struct multi_= context *m, struct multi_instance *mi, const unsigned int mpp_flags)=
{
struct mbuf_item item;
@@= -336,7 +168,7 @@
return ret;
}

-static bo= ol
+bool
multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, c= onst unsigned int mpp_flags)

{
struct= multi_instance *mi =3D multi_process_outgoing_link_pre(m);
@@ -379,566 +211,3 @@

}
return r= et;
}
= -
-static int-multi_tcp_wait_lite(struct mult= i_context *m, struct multi_instance *mi, const int action, bool *tun_input_= pending)
-{
<= span style=3D"color: hsl(0, 100%, 40%);">- struct context *c =3D multi_t= cp_context(m, mi);

- = unsigned int looking_for =3D 0;
-
- dmsg(D= _MULTI_DEBUG, "MULTI TCP: multi_tcp_wait_lite a=3D%s mi=3D" ptr_f= ormat,
- pract(= action),
- (ptr= _type)mi);
-
= - tv_clear(&c->c2.timev= al); /* ZERO-TIMEOUT */
-
- switch (action)=
- {
- case TA_TUN_READ:

<= span style=3D"color: hsl(0, 100%, 40%);">- looking_for =3D TUN_R= EAD;

- tun_i= nput_pending =3D NULL;
= - io_wait(c, IOW_READ_TUN);
- break;
-
- = case TA_SOCKET_READ:
-= looking_for =3D SOCKET_READ;
- tun_input_pending =3D NULL;
- io_wait(c, IOW_READ_LINK);=
- break;
-
- case TA_TUN_WRITE:
- looking_for =3D TUN_WRITE;=
- tun_input= _pending =3D NULL;
- = c->c2.timeval.tv_sec =3D 1; /* For some reason, the Linux 2.2 T= UN/TAP driver hits this timeout */
- perf_push(PERF_PROC_OUT_TUN_MTCP);
- io_wait(c, IOW_TO_TUN);
- perf_pop();=
- break;
-
- case TA_SOCKET_WRITE:
- looking_for =3D SOCKET_= WRITE;

- io_= wait(c, IOW_TO_LINK|IOW_READ_TUN_FORCE);
- break;
-
- = default:
- = msg(M_FATAL, "MULTI TCP: multi_tcp_wait_lite, unhandled action=3D%d&= quot;, action);
- }<= /span>
-
- if (tun_input_pending && (c->= ;c2.event_set_status & TUN_READ))
- {
-= *tun_input_pending =3D true;
- }
-<= /span>
- if (c->c2.event= _set_status & looking_for)
- {
- = return action;
- }<= /span>
- else
- {

- switch (action)
- {
- /* TCP socket output buffer is full */
= - case TA_SOCKET_WRITE= :
- retu= rn TA_SOCKET_WRITE_DEFERRED;
-
- /*= TUN device timed out on accepting write */
- case TA_TUN_WRITE:
- return TA_TUN_WRITE_TIMEOUT= ;
- }
= -
- return TA_UNDEF;
- }
-}
-
= -static struct multi_instance *
-multi_tcp_dispatch(stru= ct multi_context *m, struct multi_instance *mi, const int action)-{
- const unsigned int mpp_flags =3D MPP_PRE_SELECT= |MPP_RECORD_TOUCH;
- = struct multi_instance *touched =3D mi;
- m->mpp_touched =3D &touched;
-
- dmsg(D_MULTI_DEBUG, "MULTI TCP: multi_tcp_dispatch = a=3D%s mi=3D" ptr_format,
- pract(action),
- (ptr_type)mi);
-
- swit= ch (action)
- {
- case TA_TUN_READ:<= /span>
- read_incom= ing_tun(&m->top);
- {
- multi_process_incoming_tun(m, mpp_flags);
- }
<= span style=3D"color: hsl(0, 100%, 40%);">- break;

-

- case TA_SOCKET_READ:
- case TA_SOCKET_READ_RESIDUAL:
- ASSERT(mi);

= - ASSERT(mi->contex= t.c2.link_sockets);
- = ASSERT(mi->context.c2.link_sockets[0]);
- set_prefix(mi);
- read_incoming_link(&m= i->context, mi->context.c2.link_sockets[0]);

- clear_prefix();
- if (!IS_SIG(&mi->cont= ext))
- {
- multi_pr= ocess_incoming_link(m, mi, mpp_flags,
- mi->context.= c2.link_sockets[0]);
- = if (!IS_SIG(&mi->context))
- {
- stream_buf_read_setup(mi->con= text.c2.link_sockets[0]);
- }
-= }
- = break;
-
= - case TA_TIMEOUT:<= br>- multi_process_tim= eout(m, mpp_flags);
- = break;
-
- case TA_TUN_WRITE:=
- multi_pro= cess_outgoing_tun(m, mpp_flags);
- break;
-
- case = TA_TUN_WRITE_TIMEOUT:
-= multi_process_drop_outgoing_tun(m, mpp_flags);
- break;
-
- case TA_SOCKET_WRITE_READY:
- ASSERT(mi);
- multi_tcp_process_outgoing_link_re= ady(m, mi, mpp_flags);
= - break;
-
- case TA_SOCKET_= WRITE:
- mul= ti_tcp_process_outgoing_link(m, false, mpp_flags);
- break;
-
- case TA_SOCKET_WRITE_DEFERRED:
- multi_tcp_process_outgoing_link(m, true, = mpp_flags);
- = break;
-
- case TA_INITIAL:
- ASSERT(mi);<= br>- multi_tcp_set_glo= bal_rw_flags(m, mi);
- = multi_process_post(m, mi, mpp_flags);
- break;
-
- = msg(M_FATAL, "MULTI TCP: multi_tcp_dispatch, unhandled actio= n=3D%d", action);
= - }
-
- m->mpp_touched =3D NULL;
- return touched;=
-}
-
-static int
-multi= _tcp_post(struct multi_context *m, struct multi_instance *mi, const int act= ion)
-{
- struct context *c =3D multi_tcp_c= ontext(m, mi);

- int= newaction =3D TA_UNDEF;
-#define MTP_NONE = 0
-#define MTP_T= UN_OUT (1<<0)
- unsigned int flags =3D MTP_NONE;
-
- if (TUN_OUT(c))
- {
- = flags |=3D MTP_TUN_OUT;
- }
- if (LIN= K_OUT(c))
- {=
- flags |=3D MTP_LINK_= OUT;
- }
<= span style=3D"color: hsl(0, 100%, 40%);">-

- switch (flags)
- {
- case MTP_TUN_OUT|MTP_LINK_OUT:
- case MTP_TUN_OUT:
- newaction =3D TA_TUN_WRITE;
- break;

-

- case MTP_LINK_OUT:
- newaction =3D TA_SOCKET_WRITE;
= - break;
-

- case MTP_NONE:
- if (mi && sockets_read_residual(c))=
- {<= br>- newaction =3D= TA_SOCKET_READ_RESIDUAL;
- }
- = else
- = {
- m= ulti_tcp_set_global_rw_flags(m, mi);
- }
- break;
-
- default:<= /span>
- {
- struct gc_arena gc =3D= gc_new();

- = msg(M_FATAL, "MULTI TCP: multi_tcp_post bad state, mi=3D%s flags=3D%d= ",
- = multi_instance_string(mi, false, &gc),
- flags);
- gc_free(&gc);
- break;
- }
- }
-
- dmsg(D_MULTI_= DEBUG, "MULTI TCP: multi_tcp_post %s -> %s",
- pract(action),
- pract(newaction));
-
- return newaction;
-}
-void
-multi_tcp_action(struct multi_conte= xt *m, struct multi_instance *mi, int action, bool poll)

-{
- bool tun_input_pending =3D false;
-
- do
- = {
- dmsg(D_MULTI= _DEBUG, "MULTI TCP: multi_tcp_action a=3D%s p=3D%d",
- pract(action),
=
- poll);-
- /*
- * If TA_SOCKET_READ_RESIDUAL, it means we still have = pending
- * inp= ut packets which were read by a prior TCP recv.
- *
- * Otherwise do a "lite" wait, which means= we wait with 0 timeout
- * on I/O events only related to the current instance, not=
- * the big list of e= vents.
- *
- * On our first pa= ss, poll will be false because we already know
- * that input is available, and to call io= _wait would be redundant.
- */
- = if (poll && action !=3D TA_SOCKET_READ_RESIDUAL)
- {
- const int orig_action =3D action;
- action =3D mul= ti_tcp_wait_lite(m, mi, action, &tun_input_pending);
- if (action =3D=3D TA_UNDEF)<= /span>
- {- msg(M_FATAL, &= quot;MULTI TCP: I/O wait required blocking in multi_tcp_action, action=3D%d= ", orig_action);
-= }
- = }
-
- /*
- * Dispatch the action
- */
- struct multi_instance *touched =3D multi_tcp_= dispatch(m, mi, action);
- /*<= br>- * Signal received or= TCP connection
- = * reset by peer?
- = */
- if (= touched && IS_SIG(&touched->context))
- {
- if (mi =3D=3D touched)
- {
- mi =3D NULL;
- }
- multi_close_instance_on_signal(m, touch= ed);
- }<= br>-
-
- /*
- = * If dispatch produced any pending output
- * for a particular instance, point to=
- * that instance.
- */
- if (m->pending)
<= br>- {
- mi =3D m->pending;<= br>- }
-
- /*
- * Based on the effects of the action,
- * such as generating pending output,
- * possibly tran= sition to a new action state.
- */
- = action =3D multi_tcp_post(m, mi, action);
-
- /*
- = * If we are finished processing the original action,
- * check if we have any TUN input= . If so, transition
- = * our action state to processing this input.
- */
- if (tun_input_pending && action =3D= =3D TA_UNDEF)
- = {
- action = =3D TA_TUN_READ;
- = mi =3D NULL;
- = tun_input_pending =3D false;
- poll =3D false;
- }
- else
- {
- = poll =3D true;
- = }
-
- } while (action !=3D TA_UNDEF);
-}
-
-void
-multi_= tcp_process_io(struct multi_context *m)
-{
- = struct multi_tcp *mtcp =3D m->mtcp;
- const unsigned int udp_status =3D mtcp->udp_flags= ;
- const unsigned i= nt mpp_flags =3D m->top.c2.fast_io
- ? (MPP_CONDITIONAL_PRE_S= ELECT | MPP_CLOSE_ON_SIGNAL)
- : (MPP_PRE_SELECT | MPP_CLOSE_ON_= SIGNAL);
- int i;
-
- for (i =3D 0; i < mtcp->n_esr; ++= i)
- {
- struct event_set_return *e = =3D &mtcp->esr[i];

- struct event_arg *ev_arg =3D (struct event_arg *)e->arg;
-
- /* incoming data for instance or liste= ning socket? */
- = if (e->arg >=3D MULTI_N)
- {
- = switch (ev_arg->type)
- {
- struct multi_instance *mi;
-
- /* react to event on child instance */
- case EVENT_ARG_MULTI= _INSTANCE:

- = if (!ev_arg->u.mi)
- {
- msg(D_MULTI_ERRORS, "MULTI: mtcp_proc= _io: null minstance");
- break;
- }
-
- = mi =3D ev_arg->u.mi;
- if (e->rwflags & EVENT_WRITE)
- {
- = multi_tcp_action(m, mi, TA_SOCKET_WRITE_READY, false);
- }
- else if (e->rwflags= & EVENT_READ)
- = {
- = multi_tcp_action(m, mi, TA_SOCKET_READ, false);=
- }=
- break;
-
- /* new incoming TCP client = attempting to connect? */
- case EVENT_ARG_LINK_SOCKET:
- if (!ev_arg->u.ls)<= br>- {<= br>- msg(D= _MULTI_ERRORS, "MULTI: mtcp_proc_io: null socket");
- break;
- }
-
- if (!proto_is_dgram(ev_arg-= >u.ls->info.proto))
- {
- socket_reset_listen_persistent(ev_arg->u.ls)= ;
- = mi =3D multi_create_instance_tcp(m, ev_arg->u.ls);
- if (mi)<= br>- {

- = multi_tcp_action(m, mi, TA_INITIAL, false);
- }
- break;
- }

- else

- {

- if (e->= arg >=3D MULTI_N)

- = {
- = if (ev_arg->type !=3D EVENT_ARG_LINK_SOCKET)
- = {
- = mtcp->udp_flags =3D ES_ERROR;
- msg(D_LINK_ERRORS,<= /span>
- = "io_work: non socket event delivered");
<= span style=3D"color: hsl(0, 100%, 40%);">- b= reak;

- = }
- = }
- = else
- ev_arg->pending =3D true;
<= span style=3D"color: hsl(0, 100%, 40%);">- }
<= br>-
- if (udp_status & SOCKE= T_READ)
- = {
- = read_incoming_link(&m->top, ev_arg->u.ls);
- = if (!IS_SIG(&m->top))
- {
- multi_process_incoming_lin= k(m, NULL, mpp_flags,
-= ev_arg->u.ls= );
- = }
- = }
-=
- whil= e (true)
- = {
- = multi_get_timeout(m, &m->top.c2.timeval);<= br>- g= et_io_flags_udp(&m->top, m->mtcp, p2mp_iow_flags(m));
<= span style=3D"color: hsl(0, 100%, 40%);">- MULTI= _CHECK_SIG(m);

-=
- = multi_process_per_second_timers(m);
-
- = if (m->mtcp->udp_flags =3D=3D ES_TIMEOUT)=
- = {
- = multi_process_timeout(m, MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);=
- = }
- = else
- = {
- multi_process_io_udp(m);
- MU= LTI_CHECK_SIG(m);

- = break;
- }
- }
- break;
- }
- }
- }
- else
- {
-#ifdef = ENABLE_MANAGEMENT
- = if (e->arg =3D=3D MTCP_MANAGEMENT)
- {
- ASSERT(management);
- management_io(management);<= /span>
- }- else
-#endif

- /* incoming data on TUN? */
= - if (e->arg =3D=3D= MTCP_TUN)
- = {
- if = (e->rwflags & EVENT_WRITE)
- {
- multi_tcp_action(m, NULL, TA_TUN_WRITE, false);=
- }
- else if (= e->rwflags & EVENT_READ)
- {
- multi_tcp_action(m, NULL, TA_TUN_READ, false);
- }=
- }
- /* new incoming TCP clie= nt attempting to connect? */

- else if (e->arg =3D=3D MTCP_SOCKET)
- {
- struct multi_instance *mi;
- ASSERT(m-&= gt;top.c2.link_sockets[0]);
- socket_reset_listen_persistent(m->top.c2.link_sock= ets[0]);
- = mi =3D multi_create_instance_tcp(m, m->top.c2.link_sockets[0]);
- if (mi)
- {<= br>- multi_tcp= _action(m, mi, TA_INITIAL, false);
- }
- }
= -#if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGE= T_FREEBSD))
- = /* incoming data on DCO? */
- else if (e->arg =3D=3D MTCP_DCO)
- {
- multi_process_incoming_dco(m);
- }
= -#endif
- /* signal received? */
- else if (e->arg =3D= =3D MTCP_SIG)

- = {
- = get_signal(&m->top.sig->signal_received);
- }
-#ifdef ENABLE_ASYNC_PUSH
- else if (e->arg =3D=3D MTCP_FILE_= CLOSE_WRITE)
- = {
- m= ulti_process_file_closed(m, MPP_PRE_SELECT | MPP_RECORD_TOUCH);
<= span style=3D"color: hsl(0, 100%, 40%);">- }

-#endif
- }
- if (IS_SIG(&m->top))
- {
- break;
- }
- }<= /span>
- mtcp->n_esr =3D= 0;
-
- /*
- * Process queued mbuf packets destined for TCP so= cket
- */- {
- struct multi_instance *mi;
- while (!IS_SIG(&m->= top) && (mi =3D mbuf_peek(m->mbuf)) !=3D NULL)

- {
- multi_tcp_action(m, mi, TA_SOCKET_WRITE= , true);
- }
- }
-}
-
-/*
- * Top level event loop fo= r single-threaded operation.
- * TCP mode.
- *= /
-void
-tunnel_server_tcp(struct context *top= )

-{
- struct multi_context multi;- int status;
-

- top->mode =3D CM_TOP;
- context_clear_2(top);
-
- /* initialize top-tunnel instance */
- init_instance_handle_signals(top, top->es= , CC_HARD_USR1_TO_HUP);
- if (IS_SIG(top))
= - {
- return;=
- }
-

- /* initialize global multi_context object */- multi_init(&multi, top)= ;
-
- /* initialize our cloned top object *= /
- multi_top_init(&= amp;multi, top);
-
- /* initialize manageme= nt interface */
- in= it_management_callback_multi(&multi);
-
- = /* finished with initialization */
- initialization_sequence_completed(top, ISC_SERVER); /* = --mode server --proto tcp-server */
-
-#ifdef = ENABLE_ASYNC_PUSH
- = multi.top.c2.inotify_fd =3D inotify_init();
- if (multi.top.c2.inotify_fd < 0)
- {

- msg(D_MULTI_ERRORS | M_ERRNO, "MULTI: = inotify_init error");
- }
-#endif
-
- /* per-packet event loop */
- while (true)

- {
- perf_push(PERF_EVENT_LOOP);
-
- /* wait on tun/socket list */
- multi_get_timeout(&multi, &multi= .top.c2.timeval);
- = status =3D multi_tcp_wait(&multi.top, multi.mtcp);
- MULTI_CHECK_SIG(&multi);
-
- /* check on status of coarse timers= */
- multi_proc= ess_per_second_timers(&multi);
-
- = /* timeout? */
- = if (status > 0)
- = {
- /*= process the I/O which triggered select */
- /*multi_tcp_process_io(&multi); */
- MULTI_CHECK_S= IG(&multi);
- = }
- else if (s= tatus =3D=3D 0)
- = {
- /*mult= i_tcp_action(&multi, NULL, TA_TIMEOUT, false); */
- }
-
- = perf_pop();
- = }
-
-#ifdef ENABLE_ASYNC_PUSH
- close(top->c2.inotify_fd);
-#endif
-
- /* shut down management interface */
- uninit_management_callback();-
- /* save ifconfig-pool */
- multi_ifconfig_pool_persist(&multi,= true);
-
- /* tear down tunnel instance (u= nless --persist-tun) */

- multi_uninit(&multi);
- multi_top_free(&multi);
- close_instance(top);
-}
diff --git a/src/openvpn/mtcp.h b/= src/openvpn/mtcp.h
index d55bdfd..b8a0191 100644
= --- a/src/openvpn/mtcp.h
+++ b/src/openvpn/mtcp.h
@@ -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);
-
-vo= id multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_inst= ance *mi);
+void mult= i_tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_in= stance *mi);

bool multi_tcp_instance_spe= cific_init(struct multi_context *m, struct multi_instance *mi);
<= span>

void multi_tcp_instance_specific_free(struct multi_= instance *mi);

-int multi_tcp_wait(struct context *c, struct multi_tcp *mtcp);
+bool multi_tcp_proces= s_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_r= eady(struct multi_context *m, struct multi_instance *mi, const unsigned int= mpp_flags);

-void multi_tcp_action(struct multi_context *m, struct multi_instan= ce *mi, int action, bool poll);
-
+struct mu= lti_instance *multi_create_instance_tcp(struct multi_context *m, struct lin= k_socket *ls);

void multi_tcp_link_out_d= eferred(struct multi_context *m, struct multi_instance *mi);

+struct context *= multi_tcp_context(struct multi_context *m, struct multi_instance *mi);

/*******************************************= *******************************/
/**
@@ -9= 1,9 +88,6 @@
*
* @param top - Top-level= context structure.
*/
-void tunnel_server_tcp(struct context *top);
<= span style=3D"color: hsl(0, 100%, 40%);">-

-
-= void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);<= br>+/*void tunnel_server_tcp(st= ruct context *top); */

#endif /* ifndef = MTCP_H */
diff --git a/src/openvpn/mudp.c b/src/openvpn/mud= p.c
index 8945a55..d29f7a5 100644
--- a/src= /openvpn/mudp.c
+++ b/src/openvpn/mudp.c
@@= -379,7 +379,7 @@
void
multi_process_io_u= dp(struct multi_context *m)
{
- unsigned int status =3D m->mtcp->udp_fla= gs;
+ unsigned int= status =3D m->multi_io->udp_flags;
const unsign= ed int mpp_flags =3D m->top.c2.fast_io
= ? (MPP_CONDITIONAL_PRE_SELECT | MPP_CLOSE_ON_SIGNAL)
: (MPP_PRE_SELECT | MPP_CL= OSE_ON_SIGNAL);
diff --git a/src/openvpn/multi.c b/src/open= vpn/multi.c
index 108a5a8..b29134e 100644
-= -- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c@@ -440,7 +440,7 @@
/*
*= Initialize multi-socket TCP I/O wait object
*/
- m->mtcp =3D multi_tc= p_init(t->options.max_clients, &m->max_clients);
+ m->multi_io =3D multi_protoco= l_init(t->options.max_clients, &m->max_clients);
=
m->tcp_queue_limit =3D t->options.tcp_queue_li= mit;

@@ -668,7 +668,7 @@
=
if (!is_dgram)
{=
- multi_tcp_derefe= rence_instance(m->mtcp, mi);
+ multi_tcp_dereference_instance(m->multi_io, mi);=
}

mbuf= _dereference_instance(m->mbuf, mi);
@@ -746,7 +746,7 @@<= /span>
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-&g= t;multi_io);

}
}

@@ -3997,9 +3997,9 @@
management_delete_even= t(void *arg, event_t event)
{
struct = multi_context *m =3D (struct multi_context *) arg;
- if (m->mtcp)
+ if (m->multi_io)
{=
- multi_tcp_del= ete_event(m->mtcp, event);
+ multi_protocol_delete_event(m->multi_io, event);
}
}

@@ -= 4177,7 +4177,7 @@
ASSERT(mi->context.c2.tls_multi-&= gt;peer_id < m->max_clients);
}

-
+/* Actual multi protocol event loop in se= rver mode */
void
tunnel_server_loop(stru= ct multi_context *multi)
{
@@ -4189,7 +418= 9,7 @@

/* wait on tun/socket lis= t */
multi_get_timeout(multi, &multi->top.c= 2.timeval);
- st= atus =3D multi_tcp_wait(&multi->top, multi->mtcp);
+ status =3D multi_protocol_= io_wait(&multi->top, multi->multi_io);

M= ULTI_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 (s= tatus =3D=3D 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
tu= nnel_server_init(struct context *top)
{
di= ff --git a/src/openvpn/multi.h b/src/openvpn/multi.h
index = 472c2a3..dd7a29c 100644
--- a/src/openvpn/multi.h+++ b/src/openvpn/multi.h
@@ -37,6 +37,7 @@ #include "pool.h"
#include "mudp.h= "
#include "mtcp.h"
+#include "multi_io.h" #include "perf.h"
#include "vlan.h&= quot;
#include "reflect_filter.h"
@@ -169,8 +170,8 @@

struct mbuf_set *mbuf; /**&= lt; 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 ifco= nfig_pool *ifconfig_pool;
struct frequency_limit *new_= connection_limiter;
struct initial_packet_rate_limit *= initial_rate_limiter;
diff --git a/src/openvpn/multi_io.c b= /src/openvpn/multi_io.c
new file mode 100644
index 0000000..a1ea7fb

--- /dev/null
+++ = b/src/openvpn/multi_io.c
@@ -0,0 +1,687 @@
+/*
+ * OpenVPN -- An application to securely tunnel IP n= etworks
+ * = over a single TCP/UDP port, with support for SSL/TLS-based
+ * session authentica= tion and key exchange,

+ * packet compressi= on.
+ *
+ * Copyright (C) 2002-2023 OpenV= PN Inc <sales@...515...>

+ *
+ * Th= is program is free software; you can redistribute it and/or modify+ * it under the terms of th= e GNU General Public License version 2
+ * as published by the Free Software Foundation.=
+ *
+ * This program is distributed in the ho= pe that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY o= r FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of= the GNU General Public License along
+ * with this program; if not, write to the Free Software= Foundation, Inc.,
+ = * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */

+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include &quo= t;syshead.h"
+
+#include "memdbg= .h"
+
= +#include "multi.h"
+#include "forwar= d.h"
+#include &= quot;multi_io.h"
+
+#ifdef HAVE_SYS_I= NOTIFY_H
+#include &l= t;sys/inotify.h>
+= #endif
+
+/*

+ * Special tags passed to event.[ch] functions
+ */
+#define MULTI_IO_SOCKET ((void *)= 1)
+#define MULTI_IO_= TUN ((void *)2)
+#define MULTI_IO_SIG ((void *)3) /* Only on Windows */+#define MULTI_IO_MANAGEMENT = ((void *)4)
+#define = MULTI_IO_FILE_CLOSE_WRITE ((void *)5)
+#define MULTI_IO_DCO ((void *)6)
+
+struct ta_iow_flags
+{
= + unsigned int flags;
+ unsigned int ret;
+ unsigned int tun;
+ unsigned int sock;
+};
+
+#ifdef ENABLE_DEBUG
+static const char *
+pract(int action)=
+{
+ switch (action)
+ {
+ case TA_UNDEF:
+ return "TA_UNDEF";
+

+ case TA_SOCKET_READ:
+ return "TA_SOCKET_READ"= ;;
+
+ case TA_SOCKET_READ_RESIDUAL= :
+ return= "TA_SOCKET_READ_RESIDUAL";
+
+ = case TA_SOCKET_WRITE:
+ return "TA_SOCKET_WRITE";
+
+ case TA_SOCKET_WRITE_READY:
+ return "TA_SOCKET_WRITE_= READY";
+=
+ case TA_SOCKET_WRI= TE_DEFERRED:
+ = return "TA_SOCKET_WRITE_DEFERRED";
+
+ case TA_TUN_READ:
+ return "TA_TUN_READ";
+

+ case TA_TUN_WRITE:
+ return "TA_TUN_WRITE";
+
+ case TA_INITIAL:
+ return "TA_INITIAL= ";

+
<= span style=3D"color: hsl(120, 100%, 40%);">+ case TA_TIMEOUT:
=
+ return "T= A_TIMEOUT";
+
+ case TA_TUN_WR= ITE_TIMEOUT:
+ = return "TA_TUN_WRITE_TIMEOUT";
+
+ default:
+ return "?";
+ }
+}
+#endif /* ENAB= LE_DEBUG */
+<= br>+struct multi_protocol *
+multi_protocol_init(int= maxevents, int *maxclients)
+{
+ struc= t multi_protocol *multi_io;
+ const int extra_events =3D BASE_N_EVENTS;
+
+ ASSERT(maxevents >=3D 1);
+ ASSERT(maxclients);
+
+ ALLOC_OBJ_CLEAR(multi_io, struct multi_protocol);=
+ multi_io->maxevents= =3D maxevents + extra_events;
+ multi_io->es =3D event_set_init(&multi_io->maxeven= ts, 0);
+ wait_sig= nal(multi_io->es, MULTI_IO_SIG);
+ ALLOC_ARRAY(multi_io->esr, struct event_set_return, = multi_io->maxevents);
+ *maxclients =3D max_int(min_int(multi_io->maxevents - extra_eve= nts, *maxclients), 1);
+ return multi_io;
+}
+
+void
+multi_protocol_free(stru= ct multi_protocol *multi_io)
+{
+ if (m= ulti_io)
+ {
+ event_free(multi_= io->es);
+ = free(multi_io->esr);
+ free(multi_io);
+ }
+}
+
+int
+multi_protocol_io_wait(struct context *c,
+ struct multi= _protocol *multi_io)

= +{
+ int status, i= ;
+ unsigned int *= persistent =3D &multi_io->tun_rwflags;
+
+ for (i =3D 0; i < c->c1.link_sockets_num; i++)
<= span style=3D"color: hsl(120, 100%, 40%);">+ {

+ socket_set_listen_persistent(c->c2= .link_sockets[i], multi_io->es,
+ &c->c2.link_sock= ets[i]->ev_arg);
+= }
+
+#ifdef _WIN32

+ if (tuntap_is_wintun(c->c1.tunta= p))
+ {
= + if (!tuntap_ring_empty= (c->c1.tuntap))
+ = {
+ = /* there is data in wintun ring buffer, read it immediately */
<= span style=3D"color: hsl(120, 100%, 40%);">+ multi_io->esr[0]= .arg =3D MULTI_IO_TUN;

+ multi_io->n_esr =3D 1= ;
+ return= 1;
+ }=
+ persistent =3D NUL= L;
+ }
<= span style=3D"color: hsl(120, 100%, 40%);">+#endif

+ tun_set(c->c1.tuntap, multi_io->es= , EVENT_READ, MULTI_IO_TUN, persistent);
+#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
+ dco_event_set(&am= p;c->c1.tuntap->dco, multi_io->es, MULTI_IO_DCO);
+#endif
+
+#ifdef ENABLE_MANAGEMENT
+ if (management)
+ {
+ = management_socket_set(management, multi_io->es, MULTI_IO_MANAGEMEN= T, &multi_io->management_persist_flags);
+ }
+#endif
= +
+#ifdef ENABLE_ASYN= C_PUSH
+ /* arm in= otify watcher */
+ = event_ctl(multi_io->es, c->c2.inotify_fd, EVENT_READ, MULTI_IO_FILE_= CLOSE_WRITE);
+#endif=
+
+ status =3D event_wait(multi_io->= ;es, &c->c2.timeval, multi_io->esr, multi_io->maxevents);
+ update_time();
+ multi_io->n_esr = =3D 0;
+ if (statu= s > 0)
+ {
+ multi_io->n_e= sr =3D status;
+ }=
+ return status;<= /span>
+}
+
+static int
+multi_protocol_wait_lite(struct multi_context *m, struct multi_ins= tance *mi, const int action, bool *tun_input_pending)
+{
+ struct context *c =3D multi_tcp_context(m, mi);<= br>+ unsigned int looking_fo= r =3D 0;
+
= + dmsg(D_MULTI_DEBUG, "= MULTI PROTOCOL: multi_protocol_wait_lite a=3D%s mi=3D" ptr_format,
+ pract(action),=
+ (ptr_type)= mi);
+
+ tv_clear(&c->c2.timeval= ); /* ZERO-TIMEOUT */

+
+ switch (actio= n)
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ case TA_TUN_READ:
+ looking_for = =3D TUN_READ;
+ = tun_input_pending =3D NULL;
+ io_wait(c, IOW_READ_TUN);
+ break;
+
+ case TA_SOCKET_READ:
+ looking_for =3D SOCKET_READ;
= + tun_input_pending = =3D NULL;
+ = io_wait(c, IOW_READ_LINK);
+ break;
+
+ cas= e TA_TUN_WRITE:
+ = looking_for =3D TUN_WRITE;
+ tun_input_pending =3D NULL;
+ c->c2.timeval.tv_sec =3D = 1; /* For some reason, the Linux 2.2 TUN/TAP driver hits this timeout */
+ perf_push(= PERF_PROC_OUT_TUN_MTCP);
+ io_wait(c, IOW_TO_TUN);
+ perf_pop();
+ break;
+
+ case TA_SOCKET_WRITE:
+ looking_for =3D SOCKET_WRITE;
+ io_wait(c, IOW_TO_LINK|IOW= _READ_TUN_FORCE);
+ = break;
+
+ default:
+ msg(M_FATAL, = "MULTI PROTOCOL: multi_protocol_wait_lite, unhandled action=3D%d"= , action);
+ }
+
+ if (tun_input_pending && (c-&= gt;c2.event_set_status & TUN_READ))
+ {
+ *tun_input_pending =3D true;
+ }
+
+ if (c-= >c2.event_set_status & looking_for)
+ {
+ return action;
+ }
+ = else
+ {<= br>+ switch (action)
+ {
+ /* MULTI PROTOCOL soc= ket output buffer is full */

+ case TA_SOCKET_WRITE:
+ return TA_SOCKET_WRITE_DEFERRED;
+
+ /* TUN device timed out on ac= cepting write */
+ = case TA_TUN_WRITE:
+ return TA_TUN_WRITE_TIMEOUT;
+ }
+
+ return TA_UNDEF;
+ }
+}
+
+static inline void
+multi_protocol_set_global_rw_flags(struct= multi_context *m, struct multi_instance *mi)
+{
+ if (mi)
+= {
+ mi->= ;socket_set_called =3D true;
+ socket_set(mi->context.c2.link_sockets[0],
+ m->multi_i= o->es,

+ = mbuf_defined(mi->tcp_link_out_deferred) ? EVENT_WRITE : EVENT_R= EAD,
+ = &mi->ev_arg,
+ &mi->tcp_rwflags);
+ }
+}
+
+static struct multi_in= stance *
+multi_proto= col_dispatch(struct multi_context *m, struct multi_instance *mi, const int = action)
+{
= + const unsigned int mpp_fla= gs =3D MPP_PRE_SELECT|MPP_RECORD_TOUCH;
+ struct multi_instance *touched =3D mi;
+ m->mpp_touched =3D &t= ouched;

+
<= span style=3D"color: hsl(120, 100%, 40%);">+ dmsg(D_MULTI_DEBUG, "M= ULTI PROTOCOL: multi_protocol_dispatch a=3D%s mi=3D" ptr_format,
+ pract(action),
+ (ptr_type)mi= );
+
+ switch (action)
+ {
+ case TA_TUN_READ:
+ read_incoming_tun(&m->top= );
+ if (!= IS_SIG(&m->top))
+ {
+ = multi_process_incoming_tun(m, mpp_flags);
+ }
+ break;
+
+ case TA_SOCKET_READ:
+ case TA_SOCKET_READ_RESIDUAL:
+ ASSERT(mi);
+ ASSERT(mi->context.= c2.link_sockets);

+ = ASSERT(mi->context.c2.link_sockets[0]);
+ set_prefix(mi);
+ read_incoming_link(&a= mp;mi->context, mi->context.c2.link_sockets[0]);

+ clear_prefix();
+ if (!IS_SIG(&mi-= >context))

+ = {
+ = multi_process_incoming_link(m, mi, mpp_flags,
+ m= i->context.c2.link_sockets[0]);
+ if (!IS_SIG(&mi->context))
= + {
+ stream_buf_r= ead_setup(mi->context.c2.link_sockets[0]);

+ }
+ }
+ break;
+
+ = case TA_TIMEOUT:
+ break;
+
+ case TA_TUN_WRITE:
+ multi_process_outgoing_tun(m, mpp_flags);=
+ break;<= /span>
+
+ case TA_TUN_WRITE_TIMEOUT:
+ multi_proces= s_drop_outgoing_tun(m, mpp_flags);
+ break;
+
+ = case TA_SOCKET_WRITE_READY:
+ ASSERT(mi);
+ multi_tcp_process_outgoing_link_ready(m, mi, mpp= _flags);
+ = break;
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ case TA_SOCKET_WRITE:
+ multi_tcp= _process_outgoing_link(m, false, mpp_flags);
+ break;
+
+ case TA_SOCKET_WRITE_DEFERRED:
+ multi_tcp_process_outgoing_link(m, true= , mpp_flags);
+ = break;
+=
+ case TA_INITIAL:
+ ASSERT(mi= );
+ multi= _protocol_set_global_rw_flags(m, mi);
+ multi_process_post(m, mi, mpp_flags);<= br>+ break;+
+ default:
+ msg(M_FATAL, "MULTI PROTOCOL: mul= ti_protocol_dispatch, unhandled action=3D%d", action);
+ }

+
+ m->mpp_touched =3D NULL;
+ return touched;
+}
= +
+static int<= br>+multi_protocol_post(struct = multi_context *m, struct multi_instance *mi, const int action)
+{

+ struct context *c =3D multi_tcp_context(m, mi)= ;
+ int newaction = =3D TA_UNDEF;
+
+#define MTP_NONE = 0
+#define MTP_TUN_OU= T (1<<0)
+= #define MTP_LINK_OUT (1<<1)
+ unsigned int flags =3D MTP_NONE;
+
+ if (TUN_OUT(c))
+ {
+ flags |=3D MTP_TUN_OUT;
+ }
+= if (LINK_OUT(c))
= + {
+ flags= |=3D MTP_LINK_OUT;
+= }
+
+ switch (flags)

+ {

+ case MTP_TUN_OUT|MTP_LINK_OUT:+ case MTP_TUN_OUT:
+ newaction = =3D TA_TUN_WRITE;
+ = break;
+
+ case MTP_LINK_= OUT:
+ new= action =3D TA_SOCKET_WRITE;
+ break;
+
+ case= MTP_NONE:
+ = if (mi && sockets_read_residual(c))
+ {
+ newaction =3D TA_SOCKET_READ_RESIDUAL;=
+ }
+ else+ {
+ multi_protocol_set= _global_rw_flags(m, mi);

+ }
+ = break;
+
+ default:
+ {
+ struct gc_arena gc =3D= gc_new();

+ = msg(M_FATAL, "MULTI PROTOCOL: multi_protocol_post bad state, mi=3D%= s flags=3D%d",
+= multi_instance_string(mi, false, &gc),
+ flags);
+ gc_free(&gc);
+ break;
+ }
+ }

+
+ dmsg(D_MULTI_DEBUG, "MULTI PROTOCOL: multi_protocol_post = %s -> %s",
+ = pract(action),
+
+ retu= rn newaction;
+}
+
+void
+multi_protocol_process_io(struct multi_context *m)
+{
+ struct multi_protocol *multi_io =3D m= ->multi_io;
+ c= onst unsigned int udp_status =3D multi_io->udp_flags;
+ const unsigned int mpp_flags =3D m= ->top.c2.fast_io
+= ? (MPP_CONDITIONAL_PRE_SELECT | MPP_CLOS= E_ON_SIGNAL)
+ = : (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);
+ int i;
+

+ for (i =3D 0; i < multi_io->n_esr; ++i)
+ {
+ struct event_set_return *e = =3D &multi_io->esr[i];
+ struct event_arg *ev_arg =3D (struct event_arg *)e->ar= g;
+
+ /* incoming data for instanc= e or listening socket? */
+ if (e->arg >=3D MULTI_N)
+ {
+ switch (ev_arg->type)
+ {
+ struct multi_instance *mi;
+
+ /* react to event on chil= d instance */
+ = case EVENT_ARG_MULTI_INSTANCE:
+ if (!ev_arg->u.mi)
+ {

= + msg(D_= MULTI_ERRORS, "MULTI PROTOCOL: multi_proto_proc_io: null minstance&quo= t;);
+ = break;
+ = }
+
+ m= i =3D ev_arg->u.mi;
+ {
+ multi_pro= tocol_action(m, mi, TA_SOCKET_WRITE_READY, false);

+ }
+ else if (e->rwflag= s & EVENT_READ)
+= {
+ multi_protocol_action(m, mi, TA_SOCKET_READ, fals= e);
+ = }
+ = break;
+=
+ /* new inc= oming TCP client attempting to connect? */
+ case EVENT_ARG_LINK_SOCKET:+ if (!ev_= arg->u.ls)
+ = {
+ = msg(D_MULTI_ERRORS, "MULTI PROTOCOL: multi_proto_p= roc_io: null socket");
+ break;
+ }
+
+ if (!proto_is_dgram(ev_arg->u.ls->info.proto))<= /span>
+ = {
+ = socket_reset_listen_persistent(ev_arg->u.ls);
+ mi =3D multi_cre= ate_instance_tcp(m, ev_arg->u.ls);
+ if (mi)
+ {
+ multi_proto= col_action(m, mi, TA_INITIAL, false);
+ }
+ break;
+ }
+ else
+ {

<= span style=3D"color: hsl(120, 100%, 40%);">+ if (e-&= gt;arg >=3D MULTI_N)

+ {
+ struct event_arg *ev_arg =3D (struct = event_arg *)e->arg;
+ = {
+ = multi_io->udp_flags =3D ES_ERROR;
+ = msg(D_LINK_ERRORS,

+ = "MULTI PROTOCOL: io_work: non socke= t event delivered");
+ break;
+ }
+ }
+ else
+ {=
+ = ev_arg->pending =3D true;
+ }
+
+ if (udp_status & SOCKET_READ)
+ {
=
+ = read_incoming_link(&m->top, ev_arg->u.ls);
+ if (!IS_SIG(= &m->top))
+ = {
+ multi_process_incoming_link(m, NULL,= mpp_flags,
+ = ev_arg->u.ls);
+ = }
+ = }
++ whil= e (true)
+ = {
+ = multi_get_timeout(m, &m->top.c2.timeval);
+ = get_io_flags_udp(&m->top, m->multi_io, p2mp_iow_flags(m));
+ = MULTI_CHECK_SIG(m);
+
+ = multi_process_per_second_timers(m);
+
+ if (m->multi_io->udp_flags= =3D=3D ES_TIMEOUT)
+= {
+ multi_process_timeout(m, MPP_PRE_= SELECT | MPP_CLOSE_ON_SIGNAL);
+ }
+ else
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ = multi_process_io_udp(m);

+ MULTI_CHECK_SIG(m);
+ break= ;
+ = }
+ = }
+ = break;
+ }
+ }
+ }
+ = else
+ {
+#ifdef ENABLE_MANAGEME= NT
+ if (e= ->arg =3D=3D MULTI_IO_MANAGEMENT)
+ {
+ ASSERT(management);
+ management_io(management);
+ }
<= span style=3D"color: hsl(120, 100%, 40%);">+ else

+#endif

+ /* incoming data on TUN? */<= br>+ if (e->arg = =3D=3D MULTI_IO_TUN)
= + {
+ = if (e->rwflags & EVENT_WRITE)
+ {
+ multi_protocol_action(m, NULL= , TA_TUN_WRITE, false);
+ }
+ else if (e->rwflags & EVENT_READ)
+ {
+ multi_protocol_act= ion(m, NULL, TA_TUN_READ, false);
+ }
+ }
+ /* new incoming TCP client attempting to connect? */
+ else if (e-&= gt;arg =3D=3D MULTI_IO_SOCKET)
+ {
+ struct multi_instance *mi;
+ ASSERT(m->top.c2.link_socket= s[0]);
+ = socket_reset_listen_persistent(m->top.c2.link_sockets[0]);
= + mi =3D multi_c= reate_instance_tcp(m, m->top.c2.link_sockets[0]);
+ if (mi)
+ {
+ multi_protocol_acti= on(m, mi, TA_INITIAL, false);
+ }
+ }
+#if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARG= ET_FREEBSD))
+ = /* incoming data on DCO? */
+ else if (e->arg =3D=3D MULTI_IO_DCO)
= + {
+ multi_process_incomi= ng_dco(m);
+ = }
+#endif+ /* signal receiv= ed? */
+ e= lse if (e->arg =3D=3D MULTI_IO_SIG)
+ {
+ get_signal(&m->top.sig->signal_recei= ved);
+ }<= /span>
+#ifdef ENABLE_ASYNC_= PUSH
+ els= e if (e->arg =3D=3D MULTI_IO_FILE_CLOSE_WRITE)
+ {
+ multi_process_file_closed(m, MPP_PR= E_SELECT | MPP_RECORD_TOUCH);
+ }
+#endif
+ }=
+ if (IS_SIG(= &m->top))
+ = {
+ b= reak;
+ }
+ }
+ multi_io->n_esr =3D 0;+
+ /*
+ * Process queued mbuf packets destined for TCP socket
+ */
+ {

+ struct multi_instance *mi;
+ while (!IS_SIG(&m-&g= t;top) && (mi =3D mbuf_peek(m->mbuf)) !=3D NULL)

+ {

+ multi_protocol_action(m, mi, TA_S= OCKET_WRITE, true);
+= }
+ }
+}
+
+void
+= multi_protocol_action(struct multi_context *m, struct multi_instance *mi, i= nt action, bool poll)
+{
+ bool tun_inp= ut_pending =3D false;
+
+ do
= + {
+ dmsg(D_MULTI_DEBUG, "MULTI PROT= OCOL: multi_protocol_action a=3D%s p=3D%d",
+ pract(action),
+ poll);
+
+ /*
+ * If TA_SOCKET_READ_RESIDUAL, it means we still have pend= ing
+ * input= packets which were read by a prior recv.
+ *
+ * Otherwise do a "lite" wait, which means w= e wait with 0 timeout
+ * on I/O events only related to the current instance, not=
+ * the big list of= events.
+ *<= /span>
+ * On our fi= rst pass, poll will be false because we already know
+ * that input is available, and t= o call io_wait would be redundant.
+ */
+ if (poll && action !=3D TA_SOCKET_READ_RESIDUAL)
+ {
+ const int orig_action= =3D action;

+ = action =3D multi_protocol_wait_lite(m, mi, action, &tun_input_pend= ing);
+ if= (action =3D=3D TA_UNDEF)
+ {
+= msg(M_FATAL, "MULTI PROTOCOL: I/O wait required blocki= ng in multi_protocol_action, action=3D%d", orig_action);
+ }

+ }
+
+ /*
+ = * Dispatch the action
+ */
= + struct multi_instance *touched =3D multi_protocol_dispatch(m, mi, = action);
+
= + /*
+ * Signal received or connectio= n
+ * reset b= y peer?
+ */<= /span>
+ if (touched = && IS_SIG(&touched->context))
+ {
+ if (mi =3D=3D touched)
+ {
+ mi =3D NULL;
+ }
+ multi_close_instance_on_signal(m, t= ouched);
+ }
+
+
+ /*
+ * If dispatch produced any pending output
+ * for a particular instance,= point to
+ *= that instance.
+ = */
+ if (= m->pending)
+ = {
+ mi = =3D m->pending;
+ = }
+
= + /*
+ * Based on the effects of the = action,
+ * s= uch as generating pending output,
+ * possibly transition to a new action state.<= br>+ */
+ action =3D multi_protocol_p= ost(m, mi, action);

+=
+ /*+ * If we are finishe= d processing the original action,
+ * check if we have any TUN input. If so, transition=
+ * our acti= on state to processing this input.
+ */
+ if (tun_input_pending && action =3D=3D TA_UNDEF)
+ {
+ action =3D TA_TUN_REA= D;

+ mi = =3D NULL;
+ = tun_input_pending =3D false;
+ poll =3D false;
+ }
+ else
+ {
+ = poll =3D true;
+ = }
+
= + } while (action !=3D TA_UN= DEF);
+}
+

+void
+multi_protocol_delete_event(struct multi_protocol *multi_io, event= _t event)
+{+ if (multi_io && = multi_io->es)
+ = {
+ event_del= (multi_io->es, event);
+ }
+}=
diff --git a/src/openvpn/multi_io.h b/src/openvpn/multi_io.h
new file mode 100644
index 0000000..bd27f08
--- /dev/null
+++ b/src/openvpn/multi_io.h
@@ -0,0 +1,77 @@
+/*
+ * Ope= nVPN -- An application to securely tunnel IP networks
+ * over a single TCP/UDP port= , with support for SSL/TLS-based
+ * session authentication and key exchange,=
+ * packet encr= yption, packet authentication, and
+ * packet compression.
+ *
+ * Copyright (C) 2002-2023 OpenVPN Inc <sales@...515...>= ;
+ *
+ * This program is free software; = you can redistribute it and/or modify

+ * it under the terms of the GNU General Public License = version 2
+ * as pub= lished by the Free Software Foundation.
+ *
+ * but WITHOUT ANY WARR= ANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURP= OSE. See the
+ * GN= U General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License= along
+ * with this= program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Fl= oor, Boston, MA 02110-1301 USA.

+ */
+
+/*
+ * Multi-protocol specific code for --mo= de server
+ */=
+
+#ifndef MULTI_IO_H
+#define MULTI_IO_H
+
+#include "event.h"
+
+/= *
+ * I/O processing = States
+ */+
+#define TA_UNDEF 0
+#define TA_SOCKET_READ = 1

+#define TA_SOCKET_= READ_RESIDUAL 2
+#de= fine TA_SOCKET_WRITE 3
+#define TA_SOCKET_WRITE_READY 4
+#define TA_SOCKET_WRITE_DEFERRED 5
+#define TA_TUN_READ = 6

+#define TA_TUN_WRI= TE 7
+#de= fine TA_INITIAL 8
+#define TA_TIMEOUT 9
+#define TA_TUN_WRITE_TIMEOUT 10
+

+/*
+ * Extra state info needed for Multi-protocol
+ */
+struct multi_protocol
+{
+ struct event_set *es;
+ struct event_set_return *esr;
+ int n_esr;
+ int maxevents;
+ unsigned int tun_rwflags;
+ unsigned int udp_flags;
+#ifdef ENABLE_MANAGEMENT
+ unsigned int management_persist_= flags;
+#endif=
+};
+
+struct multi_protocol *multi_protocol_init(int maxevents, in= t *maxclients);
+
+void multi_protocol_fre= e(struct multi_protocol *multi_io);
+
+int= multi_protocol_io_wait(struct context *c, struct multi_protocol *multi_io)= ;
+
+void multi_protocol_process_io(struct= multi_context *m);
+=
+void multi_protocol= _action(struct multi_context *m, struct multi_instance *mi, int action, boo= l poll);
+
= +void multi_protocol_delete_eve= nt(struct multi_protocol *multi_io, event_t event);
+
+#endif /* ifndef MULTI_IO_H */

To view, visit change 441. To unsubscribe, or for help writing mail filte= rs, visit settings.

<= div itemscope itemtype=3D"http://schema.org/EmailMessage">
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id2d7957f5950115d9baade4c09f= d9679b01f749b
Gerrit-Change-Number: 441
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <a@...2181...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--/+HJ+sN5qjY=--