From: "ordex (Code Review)" Date: Wed, 15 Nov 2023 13:45:18 +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="vgZH2vw5n+4="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: Using the same wait function for both TCP and UDP List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --vgZH2vw5n+4= 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/+/440?usp=3Demail to review the following change. Change subject: Using the same wait function for both TCP and UDP ...................................................................... Using the same wait function for both TCP and UDP FORWARD: added a new function to collect UDP flags. MTCP: the mtcp structure has been modified to carry around those flags. The second wait function (in UDP case) has been removed. MULTI: properly remove TCP instances by checking the multi_instance protocol instead of the global one. TLS: set the tls_option xmit_hold bool value to true only in case of TCP child instance to avoid checking the global protocol value. INIT: initialize the c->c2.event_set in the inherit_context_top() by default and not only in case of UDP since we could have multiple different sockets. Change-Id: I81ec69d12abc9a661875c93c7f1bd97e525df55f Signed-off-by: Gianmarco De Gregori --- M src/openvpn/forward.c M src/openvpn/forward.h M src/openvpn/init.c M src/openvpn/mtcp.c M src/openvpn/mtcp.h M src/openvpn/mudp.c M src/openvpn/multi.c M src/openvpn/options.c M src/openvpn/options.h 9 files changed, 177 insertions(+), 244 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/40/440/1 diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 63a684b..ee18f8b 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -2053,48 +2053,20 @@ */ void -io_wait_dowork_udp(struct context *c, struct multi_tcp *mtcp, const unsign= ed int flags) +get_io_flags_dowork_udp(struct context *c, struct multi_tcp *mtcp, const u= nsigned int flags) { unsigned int socket =3D 0; unsigned int tuntap =3D 0; - struct event_set_return esr[4]; - - /* These shifts all depend on EVENT_READ and EVENT_WRITE */ - static uintptr_t socket_shift =3D 0; /* depends on SOCKET_READ and S= OCKET_WRITE */ - static uintptr_t tun_shift =3D 2; /* depends on TUN_READ and TUN_= WRITE */ - static uintptr_t err_shift =3D 4; /* depends on ES_ERROR */ -#ifdef ENABLE_MANAGEMENT - static uintptr_t management_shift =3D 6; /* depends on MANAGEMENT_READ= and MANAGEMENT_WRITE */ -#endif -#ifdef ENABLE_ASYNC_PUSH - static int file_shift =3D FILE_SHIFT; -#endif -#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) - static int dco_shift =3D DCO_SHIFT; /* Event from DCO linux kernel = module */ -#endif - int i; + static uintptr_t err_shift =3D 4; /* - * Decide what kind of events we want to wait for. - */ - /*c->c2.event_set =3D mtcp->es; */ - /*event_reset(mtcp->es); */ - /*event_reset(c->c2.event_set); */ - - /* - * On win32 we use the keyboard or an event object as a source - * of asynchronous signals. + * Calculate the flags based on the provided 'flags' argument. */ if (flags & IOW_WAIT_SIGNAL) { wait_signal(mtcp->es, (void *)err_shift); } - /* - * If outgoing data (for TCP/UDP port) pending, wait for ready-to-send - * status from TCP/UDP port. Otherwise, wait for incoming data on - * TUN/TAP device. - */ if (flags & IOW_TO_LINK) { if (flags & IOW_SHAPER) @@ -2180,117 +2152,68 @@ /* * Configure event wait based on socket, tuntap flags. */ - for (i =3D 0; i < c->c1.link_sockets_num; i++) + for (int i =3D 0; i < c->c1.link_sockets_num; i++) { - socket_set(c->c2.link_sockets[i], mtcp->es, socket, - &c->c2.link_sockets[i]->ev_arg, NULL); - } - tun_set(c->c1.tuntap, c->c2.event_set, tuntap, (void *)tun_shift, NULL= ); -#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) - if (socket & EVENT_READ && c->c2.did_open_tun) - { - dco_event_set(&c->c1.tuntap->dco, mtcp->es, (void *)&dco_shift); - } -#endif - -#ifdef ENABLE_MANAGEMENT - if (management) - { - management_socket_set(management, mtcp->es, (void *)management_shi= ft, NULL); - } -#endif - -#ifdef ENABLE_ASYNC_PUSH - /* arm inotify watcher */ - if (c->options.mode =3D=3D MODE_SERVER) - { - event_ctl(mtcp->es, c->c2.inotify_fd, EVENT_READ, (void *)&file_sh= ift); - } -#endif - - /* - * Possible scenarios: - * (1) tcp/udp port has data available to read - * (2) tcp/udp port is ready to accept more data to write - * (3) tun dev has data available to read - * (4) tun dev is ready to accept more data to write - * (5) we received a signal (handler sets signal_received) - * (6) timeout (tv) expired - */ - - mtcp->event_set_status =3D ES_ERROR; - - if (!c->sig->signal_received) - { - if (!(flags & IOW_CHECK_RESIDUAL) || !sockets_read_residual(c)) + if (proto_is_dgram(c->c2.link_sockets[i]->info.proto)) { - int status; - -#ifdef ENABLE_DEBUG - if (check_debug_level(D_EVENT_WAIT)) - { - show_wait_status(c); - } -#endif - - /* - * Wait for something to happen. - */ - status =3D event_wait(mtcp->es, &c->c2.timeval, esr, SIZE(esr)= ); - - check_status(status, "event_wait", NULL, NULL); - - if (status > 0) - { - /*printf("\nstatus: %d\n", status); */ - int i; - mtcp->event_set_status =3D 0; - for (i =3D 0; i < status; ++i) - { - const struct event_set_return *e =3D &esr[i]; - uintptr_t shift; - - 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->event_set_status =3D ES_ERROR; - msg(D_LINK_ERRORS, - "io_work: non socket event delivered"); - return; - } - - shift =3D socket_shift; - /* mark socket so that the multi code knows where = we - * have pending i/o */ - ev_arg->pending =3D true; - } - else - { - shift =3D (uintptr_t)e->arg; - } - - mtcp->event_set_status |=3D ((e->rwflags & 3) << shift= ); - } - } - else if (status =3D=3D 0) - { - mtcp->event_set_status =3D ES_TIMEOUT; - } + socket_set(c->c2.link_sockets[i], mtcp->es, socket, + &c->c2.link_sockets[i]->ev_arg, NULL); } } + mtcp->udp_flags =3D socket | tuntap; +} - /* 'now' should always be a reasonably up-to-date timestamp */ - update_time(); - - /* set signal_received if a signal was received */ - if (mtcp->event_set_status & ES_ERROR) +void +get_io_flags_udp(struct context *c, struct multi_tcp *mtcp, const unsigned= int flags) +{ + mtcp->udp_flags =3D ES_ERROR; + if (c->c2.fast_io && (flags & (IOW_TO_TUN | IOW_TO_LINK | IOW_MBUF))) { - get_signal(&c->sig->signal_received); + /* fast path -- only for TUN/TAP/UDP writes */ + unsigned int ret =3D 0; + if (flags & IOW_TO_TUN) + { + ret |=3D TUN_WRITE; + } + if (flags & (IOW_TO_LINK | IOW_MBUF)) + { + ret |=3D SOCKET_WRITE; + } + mtcp->udp_flags =3D ret; } - - dmsg(D_EVENT_WAIT, "I/O WAIT status=3D0x%04x", mtcp->event_set_status); + else + { +#ifdef _WIN32 + bool skip_iowait =3D flags & IOW_TO_TUN; + if (flags & IOW_READ_TUN) + { + /* + * don't read from tun if we have pending write to link, + * since every tun read overwrites to_link buffer filled + * by previous tun read + */ + skip_iowait =3D !(flags & IOW_TO_LINK); + } + if (tuntap_is_wintun(c->c1.tuntap) && skip_iowait) + { + unsigned int ret =3D 0; + if (flags & IOW_TO_TUN) + { + ret |=3D TUN_WRITE; + } + if (flags & IOW_READ_TUN) + { + ret |=3D TUN_READ; + } + mtcp->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); + } + } } void @@ -2308,10 +2231,10 @@ static uintptr_t management_shift =3D 6; /* depends on MANAGEMENT_READ= and MANAGEMENT_WRITE */ #endif #ifdef ENABLE_ASYNC_PUSH - static int file_shift =3D FILE_SHIFT; + static uintptr_t file_shift =3D FILE_SHIFT; #endif #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) - static int dco_shift =3D DCO_SHIFT; /* Event from DCO linux kernel = module */ + static uintptr_t dco_shift =3D DCO_SHIFT; /* Event from DCO linux k= ernel module */ #endif int i; @@ -2428,7 +2351,7 @@ #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) if (socket & EVENT_READ && c->c2.did_open_tun) { - dco_event_set(&c->c1.tuntap->dco, c->c2.event_set, (void *)&dco_sh= ift); + dco_event_set(&c->c1.tuntap->dco, c->c2.event_set, (void *)dco_shi= ft); } #endif @@ -2443,7 +2366,7 @@ /* arm inotify watcher */ if (c->options.mode =3D=3D MODE_SERVER) { - event_ctl(c->c2.event_set, c->c2.inotify_fd, EVENT_READ, (void *)&= file_shift); + event_ctl(c->c2.event_set, c->c2.inotify_fd, EVENT_READ, (void *)f= ile_shift); } #endif diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h index cb184a8..39ac975 100644 --- a/src/openvpn/forward.h +++ b/src/openvpn/forward.h @@ -69,7 +69,9 @@ extern counter_type link_write_bytes_global; -void io_wait_dowork_udp(struct context *c, struct multi_tcp *mtcp, const u= nsigned int flags); +void get_io_flags_dowork_udp(struct context *c, struct multi_tcp *mtcp, co= nst unsigned int flags); + +void get_io_flags_udp(struct context *c, struct multi_tcp *mtcp, const uns= igned int flags); void io_wait_dowork(struct context *c, const unsigned int flags); @@ -366,58 +368,6 @@ return flags; } -static inline void -io_wait_udp(struct context *c, struct multi_tcp *mtcp, const unsigned int = flags) -{ - if (c->c2.fast_io && (flags & (IOW_TO_TUN|IOW_TO_LINK|IOW_MBUF))) - { - /* fast path -- only for TUN/TAP/UDP writes */ - unsigned int ret =3D 0; - if (flags & IOW_TO_TUN) - { - ret |=3D TUN_WRITE; - } - if (flags & (IOW_TO_LINK|IOW_MBUF)) - { - ret |=3D SOCKET_WRITE; - } - mtcp->event_set_status =3D ret; - } - else - { -#ifdef _WIN32 - bool skip_iowait =3D flags & IOW_TO_TUN; - if (flags & IOW_READ_TUN) - { - /* - * don't read from tun if we have pending write to link, - * since every tun read overwrites to_link buffer filled - * by previous tun read - */ - skip_iowait =3D !(flags & IOW_TO_LINK); - } - if (tuntap_is_wintun(c->c1.tuntap) && skip_iowait) - { - unsigned int ret =3D 0; - if (flags & IOW_TO_TUN) - { - ret |=3D TUN_WRITE; - } - if (flags & IOW_READ_TUN) - { - ret |=3D TUN_READ; - } - mtcp->event_set_status =3D ret; - } - else -#endif /* ifdef _WIN32 */ - { - /* slow path */ - io_wait_dowork_udp(c, mtcp, flags); - } - } -} - /* * This is the core I/O wait function, used for all I/O waits except * for TCP in server mode. diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 762793a..2b88551 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -230,7 +230,7 @@ if (streq(p[1], "HTTP")) { struct http_proxy_options *ho; - if (ce->proto !=3D PROTO_TCP && ce->proto !=3D PROTO_TCP_CLIEN= T) + if (ce->proto !=3D PROTO_TCP && c->mode !=3D CM_CHILD_TCP) { msg(M_WARN, "HTTP proxy support only works for TCP based c= onnections"); return false; @@ -607,7 +607,10 @@ ce_defined =3D false; } + int proto =3D c->options.ce.proto; c->options.ce =3D *ce; + c->options.ce.proto =3D proto; + #ifdef ENABLE_MANAGEMENT if (ce_defined && management && management_query_remote_enabled(ma= nagement)) { @@ -2628,7 +2631,7 @@ =20 if (found & OPT_P_EXPLICIT_NOTIFY) { - if (!proto_is_udp(c->options.ce.proto) && c->options.ce.explicit_e= xit_notification) + if (!proto_is_udp(c->c2.link_sockets[0]->info.proto) && c->options= .ce.explicit_exit_notification) { msg(D_PUSH, "OPTIONS IMPORT: --explicit-exit-notify can only b= e used with --proto udp"); c->options.ce.explicit_exit_notification =3D 0; @@ -2788,14 +2791,21 @@ int sec =3D 2; int backoff =3D 0; - switch (c->options.ce.proto) + switch (c->mode) { - case PROTO_TCP_SERVER: - sec =3D 1; + case CM_TOP: + if (has_udp_in_local_list(&c->options)) + { + sec =3D c->options.ce.connect_retry_seconds; + } + else + { + sec =3D 1; + } break; - case PROTO_UDP: - case PROTO_TCP_CLIENT: + case CM_CHILD_UDP: + case CM_CHILD_TCP: sec =3D c->options.ce.connect_retry_seconds; break; } @@ -2813,7 +2823,7 @@ } /* Slow down reconnection after 5 retries per remote -- for TCP client= or UDP tls-client only */ - if (c->options.ce.proto =3D=3D PROTO_TCP_CLIENT + if (c->mode =3D=3D CM_CHILD_TCP || (c->options.ce.proto =3D=3D PROTO_UDP && c->options.tls_client)) { backoff =3D (c->options.unsuccessful_attempts / c->options.connect= ion_list->len) - 4; @@ -3293,7 +3303,21 @@ to.server =3D options->tls_server; to.replay_window =3D options->replay_window; to.replay_time =3D options->replay_time; - to.tcp_mode =3D link_socket_proto_connection_oriented(options->ce.prot= o); + + if (c->options.ce.local_list->len > 1) + { + for (int i =3D 0; i < c->options.ce.local_list->len; i++) + { + if (proto_is_dgram(c->options.ce.local_list->array[i]->proto)) + { + to.tcp_mode =3D false; + } + } + } + else + { + to.tcp_mode =3D link_socket_proto_connection_oriented(c->options.c= e.local_list->array[0]->proto); + } to.config_ciphername =3D c->options.ciphername; to.config_ncp_ciphers =3D c->options.ncp_ciphers; to.transition_window =3D options->transition_window; @@ -3338,7 +3362,7 @@ /* should we not xmit any packets until we get an initial * response from client? */ - if (to.server && options->ce.proto =3D=3D PROTO_TCP_SERVER) + if (to.server && c->mode =3D=3D CM_CHILD_TCP) { to.xmit_hold =3D true; } @@ -4257,20 +4281,13 @@ #ifdef _WIN32 msg(M_INFO, "NOTE: --fast-io is disabled since we are running on W= indows"); #else - if (!proto_is_udp(c->options.ce.proto)) + if (c->options.shaper) { - msg(M_INFO, "NOTE: --fast-io is disabled since we are not usin= g UDP"); + msg(M_INFO, "NOTE: --fast-io is disabled since we are using --= shaper"); } else { - if (c->options.shaper) - { - msg(M_INFO, "NOTE: --fast-io is disabled since we are usin= g --shaper"); - } - else - { - c->c2.fast_io =3D true; - } + c->c2.fast_io =3D true; } #endif } @@ -4967,6 +4984,7 @@ /* options */ dest->options =3D src->options; + dest->options.ce.proto =3D ls->info.proto; options_detach(&dest->options); dest->c2.event_set =3D src->c2.event_set; @@ -5065,10 +5083,7 @@ dest->c2.es_owned =3D false; dest->c2.event_set =3D NULL; - if (proto_is_dgram(src->options.ce.proto)) - { - do_event_set_init(dest, false); - } + do_event_set_init(dest, false); #ifdef USE_COMP dest->c2.comp_context =3D NULL; diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c index ba0905e..128a375 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -680,11 +680,11 @@ 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= ); - struct multi_tcp *mtcp =3D m->mtcp; - const unsigned int status =3D mtcp->event_set_status; int i; for (i =3D 0; i < mtcp->n_esr; ++i) @@ -725,9 +725,10 @@ msg(D_MULTI_ERRORS, "MULTI: mtcp_proc_io: null soc= ket"); break; } - socket_reset_listen_persistent(ev_arg->u.ls); + 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) { @@ -737,7 +738,23 @@ } else { - if (status & SOCKET_READ) + 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)) @@ -750,12 +767,12 @@ while (true) { multi_get_timeout(m, &m->top.c2.timeval); - io_wait_udp(&m->top, m->mtcp, p2mp_iow_flags(m= )); + 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->event_set_status =3D=3D ES_TIMEOU= T) + if (m->mtcp->udp_flags =3D=3D ES_TIMEOUT) { multi_process_timeout(m, MPP_PRE_SELECT | = MPP_CLOSE_ON_SIGNAL); } diff --git a/src/openvpn/mtcp.h b/src/openvpn/mtcp.h index b2fdb6e..d55bdfd 100644 --- a/src/openvpn/mtcp.h +++ b/src/openvpn/mtcp.h @@ -55,7 +55,7 @@ int n_esr; int maxevents; unsigned int tun_rwflags; - unsigned int event_set_status; + unsigned int udp_flags; #ifdef ENABLE_MANAGEMENT unsigned int management_persist_flags; #endif diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index 4979751..8945a55 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -198,7 +198,6 @@ if (mroute_extract_openvpn_sockaddr(&real, &m->top.c2.from.dest, true) && m->top.c2.buf.len > 0) { - /*real.proto =3D ls->info.proto; */ struct hash_element *he; const uint32_t hv =3D hash_value(hash, &real); struct hash_bucket *bucket =3D hash_bucket(hash, hv); @@ -380,9 +379,7 @@ void multi_process_io_udp(struct multi_context *m) { - const unsigned int status =3D m->mtcp->event_set_status; - /*p2mp_iow_flags(m); */ - /*m->top.c2.event_set_status; */ + unsigned int status =3D m->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= ); diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 5098581..108a5a8 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -607,6 +607,7 @@ ASSERT(!mi->halt); mi->halt =3D true; + bool is_dgram =3D proto_is_dgram(mi->context.c2.link_sockets[0]->info.= proto); dmsg(D_MULTI_DEBUG, "MULTI: multi_close_instance called"); @@ -665,7 +666,7 @@ mi->did_iroutes =3D false; } - if (m->mtcp && !proto_is_dgram(m->top.options.ce.proto)) + if (!is_dgram) { multi_tcp_dereference_instance(m->mtcp, mi); } @@ -3406,6 +3407,7 @@ perf_push(PERF_PROC_IN_LINK); lsi =3D get_link_socket_info(c); + /*lsi =3D &ls->info; */ orig_buf =3D c->c2.buf.data; if (process_incoming_link_part1(c, lsi, floated)) { @@ -3856,7 +3858,7 @@ while ((he =3D hash_iterator_next(&hi))) { struct multi_instance *mi =3D (struct multi_instance *) he->value; - if (!mi->halt) + if (!mi->halt && proto_is_dgram(mi->context.options.ce.proto)) { send_control_channel_string(&mi->context, next_server ? "RESTA= RT,[N]" : "RESTART", D_PUSH); multi_schedule_context_wakeup(m, mi); @@ -3894,13 +3896,15 @@ status_close(so); return false; } - else if (proto_is_dgram(m->top.options.ce.proto) - && is_exit_restart(m->top.sig->signal_received) - && (m->deferred_shutdown_signal.signal_received =3D=3D 0) - && m->top.options.ce.explicit_exit_notification !=3D 0) + else if (has_udp_in_local_list(&m->top.options)) { - multi_push_restart_schedule_exit(m, m->top.options.ce.explicit_exi= t_notification =3D=3D 2); - return false; + if (is_exit_restart(m->top.sig->signal_received) + && (m->deferred_shutdown_signal.signal_received =3D=3D 0) + && m->top.options.ce.explicit_exit_notification !=3D 0) + { + multi_push_restart_schedule_exit(m, m->top.options.ce.explicit= _exit_notification =3D=3D 2); + return false; + } } return true; } @@ -4198,10 +4202,10 @@ multi_tcp_process_io(multi); MULTI_CHECK_SIG(multi); } - /*else if (status =3D=3D 0) - * { - * multi_tcp_action(multi, NULL, TA_TIMEOUT, false); - * }*/ + else if (status =3D=3D 0) + { + multi_tcp_action(multi, NULL, TA_TIMEOUT, false); + } perf_pop(); } diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 9e800bb..553bc26 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -987,10 +987,13 @@ const struct connection_entry *e, const int i) { - setenv_str_i(es, "proto", proto2ascii(e->proto, e->af, false), i); - /* expected to befor single socket contexts only */ - setenv_str_i(es, "local", e->local_list->array[0]->local, i); - setenv_str_i(es, "local_port", e->local_list->array[0]->port, i); + for (int j =3D 0; j < e->local_list->len; j++) + { + setenv_str_i(es, "proto", proto2ascii(e->local_list->array[j]->pro= to, e->af, false), i); + /* expected to befor single socket contexts only */ + setenv_str_i(es, "local", e->local_list->array[j]->local, i); + setenv_str_i(es, "local_port", e->local_list->array[j]->port, i); + } setenv_str_i(es, "remote", e->remote, i); setenv_str_i(es, "remote_port", e->remote_port, i); @@ -2455,7 +2458,7 @@ { struct local_entry *le =3D ce->local_list->array[i]; - if (proto_is_net(ce->proto) + if (proto_is_net(le->proto) && string_defined_equal(le->local, ce->remote) && string_defined_equal(le->port, ce->remote_port)) { @@ -3781,6 +3784,12 @@ options_postprocess_mutate_ce(o, o->connection_list->array[i]); } + if (!has_udp_in_local_list(o)) + { + o->fast_io =3D false; + msg(M_INFO, "NOTE: --fast-io is disabled while using multi-socket"= ); + } + if (o->ce.local_list) { for (i =3D 0; i < o->ce.local_list->len; i++) @@ -9629,3 +9638,19 @@ err: gc_free(&gc); } + +bool +has_udp_in_local_list(const struct options *options) +{ + if (options->ce.local_list) + { + for (int i =3D 0; i < options->ce.local_list->len; i++) + { + if (proto_is_dgram(options->ce.local_list->array[i]->proto)) + { + return true; + } + } + } + return false; +} diff --git a/src/openvpn/options.h b/src/openvpn/options.h index cba0333..59035f8 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -913,6 +913,8 @@ bool key_is_external(const struct options *options); +bool has_udp_in_local_list(const struct options *options); + /** * Returns whether the current configuration has dco enabled. */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/440?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: I81ec69d12abc9a661875c93c7f1bd97e525df55f Gerrit-Change-Number: 440 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 --vgZH2vw5n+4= 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

Using the same wait function for both TCP and UDP

FORW= ARD: added a new function to collect UDP flags.

MTCP: the mtcp struc= ture has been modified to carry around those flags.
The second wai= t function (in UDP case) has been removed.

MULTI: properly remove TC= P instances by checking the multi_instance
protocol instead of th= e global one.

TLS: set the tls_option xmit_hold bool value to true o= nly in case of
TCP child instance to avoid checking the global prot= ocol
value.

INIT: initialize the c->c2.event_set in the i= nherit_context_top()
by default and not only in case of UDP since = we could have
multiple different sockets.

Change-Id: I81ec6= 9d12abc9a661875c93c7f1bd97e525df55f
Signed-off-by: Gianmarco De Gregori = <gianmarco@...2726...>
---
M src/openvpn/forward.c
M src/ope= nvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mtcp.c
M src/ope= nvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/multi.c
M src/openv= pn/options.c
M src/openvpn/options.h
9 files changed, 177 insertions(= +), 244 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/open=
vpn refs/changes/40/440/1
diff --git a/src/openvpn/forward.c b/src/=
openvpn/forward.c
index 63a684b..ee18f8b 100644
<= span>--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.= c
@@ -2053,48 +2053,20 @@
*/

void
-io_wait_dowork_udp(struct context *c, struct multi_tcp *mtcp, const u= nsigned int flags)
+g= et_io_flags_dowork_udp(struct context *c, struct multi_tcp *mtcp, const uns= igned int flags)
{
unsigned int socke= t =3D 0;
unsigned int tuntap =3D 0;
- struct event_set_return esr[4];
-
- /* These shifts all depend on EVENT_READ an= d EVENT_WRITE */
- s= tatic uintptr_t socket_shift =3D 0; /* depends on SOCKET_READ and SOCKET_= WRITE */
- static ui= ntptr_t tun_shift =3D 2; /* depends on TUN_READ and TUN_WRITE */
- static uintptr_t err_sh= ift =3D 4; /* depends on ES_ERROR */
-#ifdef ENABLE_MANAGEMENT
- static uintptr_t management_shift =3D 6; /* depe= nds on MANAGEMENT_READ and MANAGEMENT_WRITE */
-#endif
-#ifdef ENABLE_ASYNC_PUSH
- static int file_shift =3D FILE_SHIFT;
-#endif
-#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
- static int dco_shift = =3D DCO_SHIFT; /* Event from DCO linux kernel module */
-#endif
- int i;
+ static uintptr_t err_shift =3D 4;
=
/*
- = * Decide what kind of events we want to wait for.
- */
- /*c->c2.event_set =3D mtcp->es; */
- /*event_reset(mtcp->es); */

- /*event_reset(c->= c2.event_set); */
-
- /*
- * On win32 we use the keyboard or a= n event object as a source
- * of asynchronous signals.
+ * Calculate the flags based on the provided 'flag= s' argument.
*/
if (flags &a= mp; IOW_WAIT_SIGNAL)
{
wait_s= ignal(mtcp->es, (void *)err_shift);
}

- /*
= - * If outgoing data (for TCP= /UDP port) pending, wait for ready-to-send
- * status from TCP/UDP port. Otherwise, wait for i= ncoming data on
- *= TUN/TAP device.
- = */
if (flags & IOW_TO_LINK)
{=
if (flags & IOW_SHAPER)
@@ -2= 180,117 +2152,68 @@
/*
* Configu= re event wait based on socket, tuntap flags.
*/
- for (i =3D 0; i < c-= >c1.link_sockets_num; i++)
+ for (int i =3D 0; i < c->c1.link_sockets_num; i++)
{
- = socket_set(c->c2.link_sockets[i], mtcp->es, socket,
- &c->c2.l= ink_sockets[i]->ev_arg, NULL);

- }
- = tun_set(c->c1.tuntap, c->c2.event_set, tuntap, (void *)tun_shift, NUL= L);
-#if defined(TARGET= _LINUX) || defined(TARGET_FREEBSD)
- if (socket & EVENT_READ && c->c2.did_open_t= un)
- {
- dco_event_set(&c->c= 1.tuntap->dco, mtcp->es, (void *)&dco_shift);

- }
-#endif
-#ifdef ENABLE_MANA= GEMENT
- if (managem= ent)
- {
<= span style=3D"color: hsl(0, 100%, 40%);">- management_socket_set(man= agement, mtcp->es, (void *)management_shift, NULL);
- }
-#endif
-
-#ifdef ENABLE_ASYNC= _PUSH
- /* arm inoti= fy watcher */
- if (= c->options.mode =3D=3D MODE_SERVER)
- {
= - event_ctl(mtcp->es, c->c2.inotify_fd, EVENT_READ, (void *)&a= mp;file_shift);
- }<= /span>
-#endif
-

- /*
- * Possible scenarios:
- * (1) tcp/udp port has data available to read
- * (2) tcp/udp port is ready to a= ccept more data to write
- * (4) tun dev is ready to accept more dat= a to write
- * (5)= we received a signal (handler sets signal_received)
- * (6) timeout (tv) expired
= - */
-
- mtcp->event_set_status =3D ES_ERROR;
-
- if (!c->sig->signal_received)
- {
- if (!(flags & IOW_CHECK_RESIDUAL) || !sockets_read= _residual(c))
+ = if (proto_is_dgram(c->c2.link_sockets[i]->info.proto))
{
- = int status;
-
-#ifdef ENABLE_DEBUG=
- if (check_debug_= level(D_EVENT_WAIT))
- = {
- = show_wait_status(c);
- }
-#e= ndif
-
- /*
- * Wait for something to happen= .
- */
- status =3D eve= nt_wait(mtcp->es, &c->c2.timeval, esr, SIZE(esr));
-

- check_status(status, "event_wait", = NULL, NULL);
-- if (status > 0)=
- {<= br>- /*printf(&quo= t;\nstatus: %d\n", status); */
- int i;
- mtcp->event_set_status =3D 0;
<= span style=3D"color: hsl(0, 100%, 40%);">- for (i =3D 0; i &= lt; status; ++i)

- = {
- = const struct event_set_return *e =3D &esr[i];
- uintptr_t shift;=
-
- 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->event_set_= status =3D ES_ERROR;
- = msg(D_LINK_ERRORS,
- "io_work: non = socket event delivered");
- return;
- }
-
- shift =3D socket_shift;
- /* mark socket so t= hat the multi code knows where we
- * have pending i/o */
- ev_arg->pen= ding =3D true;
- = }
- = else
- = {
- = shift =3D (uintptr_t)e->arg;
- }
-
- mtcp->event_set_status |=3D ((e->rwfla= gs & 3) << shift);
- }
- = else if (status =3D=3D 0)
- {
- }
+ socket_set(c->c2.link_sock= ets[i], mtcp->es, socket,
+ &c->c2.link_sockets[i]->ev_arg, N= ULL);
}
}
+ mtcp->udp_flags =3D socket | tun= tap;
+}

- /* 'now&#= 39; should always be a reasonably up-to-date timestamp */
- update_time();
-
- /* set signal_received if a signal was received */- if (mtcp->event_set_sta= tus & ES_ERROR)
+= void
+get_io_flags_ud= p(struct context *c, struct multi_tcp *mtcp, const unsigned int flags)
+{
+ mtcp->udp_flags =3D ES_ERROR;
+ if (c->c2.fast_io= && (flags & (IOW_TO_TUN | IOW_TO_LINK | IOW_MBUF)))
= {
- g= et_signal(&c->sig->signal_received);
+ /* fast path -- only for TUN/TAP/UDP wri= tes */
+ unsig= ned int ret =3D 0;
+ = if (flags & IOW_TO_TUN)
+ {
+ ret |=3D TUN_WRITE;
+ }
+ if (flags & (IOW_TO_LINK | IOW_MBUF))
+ {
+ ret |=3D SOCKET_WRITE;
+ }

+ mtcp->udp_flags =3D ret;
}
-

- dmsg(D_EVENT_WAIT, &q= uot;I/O WAIT status=3D0x%04x", mtcp->event_set_status);
<= span style=3D"color: hsl(120, 100%, 40%);">+ else
+ {
+#ifdef _WIN32
+ bool skip_iowait =3D flags & IOW_TO_TUN;+ if (flags & IOW_= READ_TUN)
+ {<= /span>
+ /*
+ * don't = read from tun if we have pending write to link,
+ * since every tun read overwrites = to_link buffer filled
+ * by previous tun read
+ */
+ skip_iowait =3D !(flags & IOW_TO_LINK);
+ }
+ if (tuntap_is_wintun(c->= c1.tuntap) && skip_iowait)

+ {
+ unsigned int ret =3D 0;
+ if (flags & IOW_TO_TUN)
+ {

+ ret |=3D TUN_WRITE;
+ }
= + if (flags & IO= W_READ_TUN)
+ = {
+ = ret |=3D TUN_READ;
= + }
+ = mtcp->udp_flags =3D ret;
+ }
+ else
+#e= ndif /* ifdef _WIN32 */
+ {
+ = /* slow path - delegate to io_wait_dowork_udp to calculate flags */
+ get_io_fl= ags_dowork_udp(c, mtcp, flags);
+ }
+ }
}

void@@ -2308,10 +2231,10 @@
static uintptr_t manag= ement_shift =3D 6; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */

#endif
#ifdef ENABLE_ASYNC_PUSH
<= span style=3D"color: hsl(0, 100%, 40%);">- static int file_shift =3D FIL= E_SHIFT;
+ static = uintptr_t file_shift =3D FILE_SHIFT;
#endif
#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
- static int dco_shift =3D DCO_SHIFT; = /* Event from DCO linux kernel module */
+ static uintptr_t dco_shift =3D DCO_SHIFT; /* = Event from DCO linux kernel module */
#endif
int i;

@@ -2428,7 +2351,7 @@

#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) if (socket & EVENT_READ && c->c2.did_open_tun)
{
-= dco_event_set(&c->c1.tuntap->dco, c->c2.event_set, (vo= id *)&dco_shift);
+ dco_event_set(&c->c1.tuntap->dco, c->c2.event_set, (= void *)dco_shift);
}
#endif
@@ -2443,7 +2366,7 @@
/* arm = inotify watcher */
if (c->options.mode =3D=3D MODE_= SERVER)
{
- event_ctl(c->c2.event_set, c->c2.inotify_fd, EVENT_R= EAD, (void *)&file_shift);
+ event_ctl(c->c2.event_set, c->c2.inotify_fd, EVENT= _READ, (void *)file_shift);
}
#endif<= /span>

diff --git a/src/openvpn/forward.h b/src/= openvpn/forward.h
index cb184a8..39ac975 100644
<= span>--- a/src/openvpn/forward.h

+++ b/src/openvpn/forward.= h
@@ -69,7 +69,9 @@

exte= rn counter_type link_write_bytes_global;

-void io_wait_dowork_udp(struct context= *c, struct multi_tcp *mtcp, const unsigned int flags);
+void get_io_flags_dowork_udp(struct con= text *c, struct multi_tcp *mtcp, const unsigned int flags);
+

+void get_io_flags_udp(struct context *c, struct multi_= tcp *mtcp, const unsigned int flags);

vo= id io_wait_dowork(struct context *c, const unsigned int flags);
<= span>
@@ -366,58 +368,6 @@
return fla= gs;
}

-static inline void
-io_wait_udp(struct context *c, struct multi_tcp *mtcp, cons= t unsigned int flags)
-= {
- if (c->c2.fas= t_io && (flags & (IOW_TO_TUN|IOW_TO_LINK|IOW_MBUF)))
= - {
- /* fast path -- only for TUN/TAP/UDP wri= tes */
- unsigne= d int ret =3D 0;
- = if (flags & IOW_TO_TUN)
- {
- = ret |=3D TUN_WRITE;
- }
- = if (flags & (IOW_TO_LINK|IOW_MBUF))
- {
- ret |=3D SOCKET_WRITE;
- }
- mtcp->event_set_status =3D ret;
- }
- else
-#ifdef _WIN32=
- bool skip_iow= ait =3D flags & IOW_TO_TUN;
- if (flags & IOW_READ_TUN)
- {
- /*
- * don't read from tun if we have pending write to l= ink,
- * si= nce every tun read overwrites to_link buffer filled
- * by previous tun read<= br>- */
- skip_iowait =3D !(flags= & IOW_TO_LINK);
- = }
- if (t= untap_is_wintun(c->c1.tuntap) && skip_iowait)
- {
- unsigned int ret =3D 0;
- if (flags & IOW_TO_TUN= )
- {=
- ret |=3D TUN= _WRITE;
- }<= /span>
- if (flags = & IOW_READ_TUN)
- = {
- = ret |=3D TUN_READ;
- = mtcp->event_set_status =3D ret;
- }
- else
-#= endif /* ifdef _WIN32 */
- = /* slow path */
- = io_wait_dowork_udp(c, mtcp, flags);
- }
- }
-}

-
/*
* This is the core I/O wait function, used for all I/O waits = except
* for TCP in server mode.
diff --g= it a/src/openvpn/init.c b/src/openvpn/init.c
index 762793a.= .2b88551 100644
--- a/src/openvpn/init.c
++= + b/src/openvpn/init.c
@@ -230,7 +230,7 @@
= if (streq(p[1], "HTTP"))
{
struct http_proxy_options *ho;
- if (ce->proto !=3D PROTO_T= CP && ce->proto !=3D PROTO_TCP_CLIENT)
+ if (ce->proto !=3D PROTO_TCP &= amp;& c->mode !=3D CM_CHILD_TCP)
{
msg(M_WARN, "HTTP proxy support only work= s for TCP based connections");
return= false;
@@ -607,7 +607,10 @@
c= e_defined =3D false;
}
+ int proto =3D c->o= ptions.ce.proto;
c->options.ce =3D *ce;<= br>+ c->options.ce.pr= oto =3D proto;
+
#ifdef ENABLE_MANAGEMENT
if (ce_defin= ed && management && management_query_remote_enabled(managem= ent))
{
@@ -2628,7 +2631,7 @@

if (found & OPT_P_EXPLICIT_NOTIFY)
{
-= if (!proto_is_udp(c->options.ce.proto) && c->options.= ce.explicit_exit_notification)
+ if (!proto_is_udp(c->c2.link_sockets[0]->info.prot= o) && c->options.ce.explicit_exit_notification)
= {
msg(D_PUSH, "OPTIONS IMPORT: -= -explicit-exit-notify can only be used with --proto udp");
<= span> c->options.ce.explicit_exit_notification =3D 0;
=
@@ -2788,14 +2791,21 @@
int sec =3D 2;
int backoff =3D 0;

- switch (c->options.ce.proto)<= br>+ switch (c->mode)
{
- = case PROTO_TCP_SERVER:
- sec =3D 1;
+ case CM_TOP:
+ if (has_udp_in_local_list(&c->options))
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ sec =3D c->o= ptions.ce.connect_retry_seconds;

+ }
+ else
+ {
+ = sec =3D 1;
+ }
break;

- case PROTO_UDP:<= /span>
- case PROTO_TCP= _CLIENT:
+ cas= e CM_CHILD_UDP:
+ = case CM_CHILD_TCP:
sec =3D c->options.c= e.connect_retry_seconds;
break;
}

@@ -2813,7 +2823,7 @@
}

/* Slow down reconnection after 5 retries= per remote -- for TCP client or UDP tls-client only */
- if (c->options.ce.proto =3D=3D PRO= TO_TCP_CLIENT
+ if= (c->mode =3D=3D CM_CHILD_TCP
|| (c->options= .ce.proto =3D=3D PROTO_UDP && c->options.tls_client))
= {
backoff =3D (c->options.unsuccessf= ul_attempts / c->options.connection_list->len) - 4;
@= @ -3293,7 +3303,21 @@
to.server =3D options->tls_se= rver;
to.replay_window =3D options->replay_window;<= /span>
to.replay_time =3D options->replay_time;
= - to.tcp_mode =3D link_socket_= proto_connection_oriented(options->ce.proto);
+
+ if (c->options.ce.local_list->len > 1)
+ {

+ for (int i =3D 0; i < c->options.= ce.local_list->len; i++)
+ {
+ = if (proto_is_dgram(c->options.ce.local_list->array[i]->p= roto))
+ {=
+ to.= tcp_mode =3D false;
+= }
+ = }
+ }
= + else
+ {
+ to.tcp_mode =3D link_socket_proto_connection_or= iented(c->options.ce.local_list->array[0]->proto);
+ }

to.confi= g_ciphername =3D c->options.ciphername;
to.config_n= cp_ciphers =3D c->options.ncp_ciphers;
to.transitio= n_window =3D options->transition_window;
@@ -3338,7 +336= 2,7 @@

/* should we not xmit any pac= kets until we get an initial
* response from client? = */
- if (to.server &= amp;& options->ce.proto =3D=3D PROTO_TCP_SERVER)
+ if (to.server && c->mode= =3D=3D CM_CHILD_TCP)
{
to.xm= it_hold =3D true;
}
@@ -4257,20 +4281,= 13 @@
#ifdef _WIN32
msg(M_INFO, &= quot;NOTE: --fast-io is disabled since we are running on Windows");
#else
- = if (!proto_is_udp(c->options.ce.proto))
+ if (c->options.shaper)
<= span> {

- = msg(M_INFO, "NOTE: --fast-io is disabled since we are not using = UDP");
+ = msg(M_INFO, "NOTE: --fast-io is disabled since we are using --shap= er");
}
else<= br> {
- = if (c->options.shaper)
- {
- msg(M_INFO, "NOTE: --fast-io is disabled since w= e are using --shaper");
- }
- = else
- = {
- = c->c2.fast_io =3D true;
- }
= + c->c2.fast_io =3D true;
} #endif
}
@@ -4967,6 +4984,7 @= @

/* options */
= dest->options =3D src->options;
+ dest->options.ce.proto =3D ls->info.proto;
options_detach(&dest->options);
<= /span>
dest->c2.event_set =3D src->c2.event_set;=
@@ -5065,10 +5083,7 @@
dest->c2.es_owned = =3D false;

dest->c2.event_set =3D= NULL;
- if (proto_i= s_dgram(src->options.ce.proto))
- {
- = do_event_set_init(dest, false);
- }
= + do_event_set_init(dest, false);

#if= def USE_COMP
dest->c2.comp_context =3D NULL;=
diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c
index ba0905e..128a375 100644

--- a/src/openvpn/mtcp.c<= /span>
+++ b/src/openvpn/mtcp.c
@@ -680,11 +680,11= @@
void
multi_tcp_process_io(struct mult= i_context *m)
{
+ struct multi_tcp *mtcp =3D m->mtcp;
+ const unsigned int udp_status =3D m= tcp->udp_flags;
const unsigned int mpp_flags =3D m-= >top.c2.fast_io
? (M= PP_CONDITIONAL_PRE_SELECT | MPP_CLOSE_ON_SIGNAL)
= : (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);<= br>- struct multi_tcp *mtcp = =3D m->mtcp;
- co= nst unsigned int status =3D mtcp->event_set_status;
= int i;

for (i =3D 0; i < mtcp-&g= t;n_esr; ++i)
@@ -725,9 +725,10 @@
= msg(D_MULTI_ERRORS, "MULTI: mtcp_proc_io: null socket= ");
break;
= }
- = socket_reset_listen_persistent(ev_arg->u.ls);<= br>+
= if (!proto_is_dgram(ev_arg->u.ls->info.proto))
<= span> {

+ socket_reset_listen_persistent(ev_arg->u= .ls);
mi =3D multi_create_instance= _tcp(m, ev_arg->u.ls);
if (mi)<= /span>
{
@@ -737,7 +738,2= 3 @@
}
= else
{
- if (status & SOCKET= _READ)
+ = if (e->arg >=3D MULTI_N)
+ {
+ struct event_arg *e= v_arg =3D (struct event_arg *)e->arg;
+ if (ev_arg->type !=3D E= VENT_ARG_LINK_SOCKET)
+ {
+ mtcp->udp_flags =3D ES_ERROR= ;
+ = msg(D_LINK_ERRORS,
+ "io_work: non socket = event delivered");
+ break;
+ }
+ }
+ else
=
+ {<= /span>
+ = ev_arg->pending =3D true;
+ }
+
+ if (udp_status & SOCKET_READ)
{

= read_incoming_link(&m->top, ev_arg->u.ls);
= if (!IS_SIG(&m->top))
@@ -750= ,12 +767,12 @@
while (true)=
{
= multi_get_timeout(m, &m->top.c2.timeval);
- io_wait_udp(&= amp;m->top, m->mtcp, p2mp_iow_flags(m));
+ get_io_flags_udp(&am= p;m->top, m->mtcp, p2mp_iow_flags(m));
= MULTI_CHECK_SIG(m);

= multi_process_per_second_timers(m);
=
- = if (m->mtcp->event_set_status =3D=3D ES_TIMEOUT)
+ if (= m->mtcp->udp_flags =3D=3D ES_TIMEOUT)

= {
multi_proc= ess_timeout(m, MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);
= }
diff --git a/src/openvpn/mtcp.h b= /src/openvpn/mtcp.h
index b2fdb6e..d55bdfd 100644--- a/src/openvpn/mtcp.h
+++ b/src/openvpn/mtcp.h
@@ -55,7 +55,7 @@
int n_esr;
<= span> int maxevents;

unsigned int tun_rwflags;
- unsigned int event_se= t_status;
+ unsign= ed int udp_flags;
#ifdef ENABLE_MANAGEMENT
unsigned int management_persist_flags;

#endif=
diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c
index 4979751..8945a55 100644

--- a/src/openvpn/mudp.c<= /span>
+++ b/src/openvpn/mudp.c
@@ -198,7 +198,6 @= @
if (mroute_extract_openvpn_sockaddr(&real, &= m->top.c2.from.dest, true)
&& m->top= .c2.buf.len > 0)
{
- /*real.proto =3D ls->info.proto; */<= br> struct hash_element *he;
const u= int32_t hv =3D hash_value(hash, &real);
struct= hash_bucket *bucket =3D hash_bucket(hash, hv);
@@ -380,9 += 379,7 @@
void
multi_process_io_udp(struct= multi_context *m)
{
- const unsigned int status =3D m->mtcp->event_set_= status;
- /*p2mp_iow= _flags(m); */
- /*m-= >top.c2.event_set_status; */
+ unsigned int status =3D m->mtcp->udp_flags; const unsigned int mpp_flags =3D m->top.c2.fast_io ? (MPP_CONDITIONAL_PRE_SELECT | = MPP_CLOSE_ON_SIGNAL)
: = (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);
diff --git a/src/op= envpn/multi.c b/src/openvpn/multi.c
index 5098581..108a5a8 = 100644
--- a/src/openvpn/multi.c
+++ b/src/= openvpn/multi.c
@@ -607,6 +607,7 @@

ASSERT(!mi->halt);
mi->halt =3D = true;
+ bool is_dg= ram =3D proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto);

dmsg(D_MULTI_DEBUG, "MULTI: mult= i_close_instance called");

@@ -665,7= +666,7 @@
mi->did_iroutes =3D false;
}

- if (m->mtcp && !proto_is_dgram(m->t= op.options.ce.proto))
+ if (!is_dgram)
{
= multi_tcp_dereference_instance(m->mtcp, mi);
= }
@@ -3406,6 +3407,7 @@

perf_push(PERF_PROC_IN_LINK);

= lsi =3D get_link_socket_info(c);
+ /*lsi =3D &ls->info; */
= orig_buf =3D c->c2.buf.data;
if (= process_incoming_link_part1(c, lsi, floated))
= {
@@ -3856,7 +3858,7 @@
while ((he =3D= hash_iterator_next(&hi)))
{
= struct multi_instance *mi =3D (struct multi_instance *) he->value;
- if (!mi->hal= t)
+ if (!mi-&= gt;halt && proto_is_dgram(mi->context.options.ce.proto))<= br> {
send_control_channel_strin= g(&mi->context, next_server ? "RESTART,[N]" : "RESTAR= T", D_PUSH);
multi_schedule_context_wakeu= p(m, mi);
@@ -3894,13 +3896,15 @@
= status_close(so);
return false;
= }
- else if (prot= o_is_dgram(m->top.options.ce.proto)
- && is_exit_restart(m->top.sig->= signal_received)
- = && (m->deferred_shutdown_signal.signal_received =3D=3D 0= )
- &&a= mp; m->top.options.ce.explicit_exit_notification !=3D 0)
+ else if (has_udp_in_local_list(= &m->top.options))

{
- multi_push_restart_schedule_exit(m, m->= ;top.options.ce.explicit_exit_notification =3D=3D 2);
- return false;
+ if (is_exit_restart(m->top.sig= ->signal_received)
+ && (m->deferred_shutdown_signal.signal_received = =3D=3D 0)
+ = && m->top.options.ce.explicit_exit_notification !=3D 0)=
+ {
+ multi_push_restart_sched= ule_exit(m, m->top.options.ce.explicit_exit_notification =3D=3D 2);
+ return false= ;
+ } }
return true;
}<= br>@@ -4198,10 +4202,10 @@
multi_tcp_pro= cess_io(multi);
MULTI_CHECK_SIG(multi);=
}
- = /*else if (status =3D=3D 0)
- * {
- * multi_tcp_action(multi, NULL, TA_TIMEOUT, false);- * }*/
+ else if (status =3D=3D 0)
+ {
+ multi_tcp_action(mul= ti, NULL, TA_TIMEOUT, false);

+ }

perf_pop();<= /span>
}
diff --git a/src/openvpn/options.c b= /src/openvpn/options.c
index 9e800bb..553bc26 100644=
--- a/src/openvpn/options.c
+++ b/src/openvpn/opt= ions.c
@@ -987,10 +987,13 @@
= const struct connection_entry *e,
= const int i)
{
- setenv_str_i(es, "proto", proto2ascii(e-= >proto, e->af, false), i);
- /* expected to befor single socket contexts only */- setenv_str_i(es, "loc= al", e->local_list->array[0]->local, i);
- setenv_str_i(es, "local_port"= ;, e->local_list->array[0]->port, i);
+ for (int j =3D 0; j < e->local_list-&g= t;len; j++)
+ {
+ setenv_str_i(e= s, "proto", proto2ascii(e->local_list->array[j]->proto, = e->af, false), i);
+ /* expected to befor single socket contexts only */
+ setenv_str_i(es, "lo= cal", e->local_list->array[j]->local, i);

+ setenv_str_i(es, "local_po= rt", e->local_list->array[j]->port, i);
+ }
setenv_str_i(e= s, "remote", e->remote, i);
setenv_str_i(= es, "remote_port", e->remote_port, i);

@@ -2455,7 +2458,7 @@
{
= struct local_entry *le =3D ce->local_list->array[i];
=
- if (pr= oto_is_net(ce->proto)
+ if (proto_is_net(le->proto)
&a= mp;& string_defined_equal(le->local, ce->remote)
= && string_defined_equal(le->port, ce->remote_por= t))
{
@@ -3781,6 +3784,12 @@
options_postprocess_mutate_ce(o, o->connection_list-= >array[i]);
}

+ if (!has_udp_in_local_list(o))
+ {
+ o->fast_io =3D false;
+ msg(M_INFO, "= ;NOTE: --fast-io is disabled while using multi-socket");
+ }

+
if (o->ce.local_list)<= /span>
{
for (i =3D 0; i < o->= ce.local_list->len; i++)
@@ -9629,3 +9638,19 @@ err:
gc_free(&gc);
}
+
+bool
+has_udp_in_local_list(const struct options *options)
+{
+ if (options->ce.local_list)=
+ {
+ for (int i =3D 0; i < options= ->ce.local_list->len; i++)
+ {
+ = {
+ = return true;
+ = }
+ }
+ }
+ return false;
+}
diff --git a/src/open= vpn/options.h b/src/openvpn/options.h
index cba0333..59035f= 8 100644
--- a/src/openvpn/options.h
+++ b/= src/openvpn/options.h
@@ -913,6 +913,8 @@
=
bool key_is_external(const struct options *options);

+bool h= as_udp_in_local_list(const struct options *options);
+
/**
*= Returns whether the current configuration has dco enabled.
*/


To view, visit change 440. To unsubscr= ibe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81ec69d12abc9a661875c93c7f1= bd97e525df55f
Gerrit-Change-Number: 440
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
--vgZH2vw5n+4=--