From: "its_Giaan (Code Review)" Date: Mon, 23 Sep 2024 13:41:33 +0000 References: Reply-To: gianmarco@...2726..., 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="5zhWaACfqi4="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Refinement to handle simultaneous UDP and TCP connections List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --5zhWaACfqi4= 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/+/766?usp=3Demail to review the following change. Change subject: Refinement to handle simultaneous UDP and TCP connections ...................................................................... Refinement to handle simultaneous UDP and TCP connections 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: Ibe0614bf6ced210c136b2d13036048188196f7ef Signed-off-by: Gianmarco De Gregori --- M src/openvpn/forward.c M src/openvpn/init.c M src/openvpn/mtcp.c M src/openvpn/mudp.c M src/openvpn/multi.c M src/openvpn/multi.h M src/openvpn/multi_io.c M src/openvpn/options.c M src/openvpn/options.h 9 files changed, 143 insertions(+), 54 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/66/766/1 diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 1357cad..c37095d 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -2358,7 +2358,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 diff --git a/src/openvpn/init.c b/src/openvpn/init.c index c817ce6..51b49f2 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -224,7 +224,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; @@ -601,7 +601,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)) { @@ -2600,7 +2603,7 @@ 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; @@ -2760,14 +2763,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; } @@ -2785,7 +2795,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; @@ -3265,7 +3275,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; @@ -3310,7 +3334,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; } @@ -4214,20 +4238,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 } @@ -4924,6 +4941,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; @@ -5022,10 +5040,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 1eb28ec..ba705a8 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -153,12 +153,19 @@ { 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); + if (proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto)) + { + return; + } + else + { + 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_WRI= TE : EVENT_READ, + &mi->ev_arg, + &mi->tcp_rwflags); + } } } diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index f9efcd5..9edd6ad 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -194,6 +194,7 @@ struct hash *hash =3D m->hash; real.proto =3D ls->info.proto; m->local.proto =3D real.proto; + m->hmac_reply_ls =3D ls; if (mroute_extract_openvpn_sockaddr(&real, &m->top.c2.from.dest, true) && m->top.c2.buf.len > 0) @@ -320,15 +321,8 @@ msg_set_prefix("Connection Attempt"); m->top.c2.to_link =3D m->hmac_reply; m->top.c2.to_link_addr =3D m->hmac_reply_dest; - for (int i =3D 0; i < m->top.c1.link_sockets_num; i++) - { - if (!proto_is_dgram(m->top.c2.link_sockets[i]->info.proto)) - { - continue; - } - - process_outgoing_link(&m->top, m->top.c2.link_sockets[i]); - } + process_outgoing_link(&m->top, m->hmac_reply_ls); + m->hmac_reply_ls =3D NULL; m->hmac_reply_dest =3D NULL; } } diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 4a6dd52..a6cdb67 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -606,6 +606,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"); =20 @@ -664,7 +665,7 @@ mi->did_iroutes =3D false; } - if (m->multi_io && !proto_is_dgram(m->top.options.ce.proto)) + if (!is_dgram) { multi_tcp_dereference_instance(m->multi_io, mi); } @@ -3400,7 +3401,7 @@ /* decrypt in instance context */ 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)) { @@ -3851,7 +3852,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); @@ -3889,13 +3890,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; } diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 65fd320..670826e 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -200,6 +200,7 @@ struct buffer hmac_reply; struct link_socket_actual *hmac_reply_dest; + struct link_socket *hmac_reply_ls; /* * Timer object for stale route check diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c index 57ed10e..269b045 100644 --- a/src/openvpn/multi_io.c +++ b/src/openvpn/multi_io.c @@ -142,6 +142,11 @@ &m->top.c2.link_sockets[i]->ev_arg); } + if (has_udp_in_local_list(&m->top.options)) + { + get_io_flags_udp(&m->top, m->multi_io, p2mp_iow_flags(m)); + } + #ifdef _WIN32 if (tuntap_is_wintun(m->top.c1.tuntap)) { @@ -396,6 +401,10 @@ 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) @@ -447,6 +456,39 @@ } 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); + } + } + else + { + multi_process_io_udp(m); + } + break; + } } } else diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 42210da..a06813e 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -993,10 +993,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); @@ -2466,7 +2469,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)) { @@ -3828,6 +3831,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++) @@ -9722,3 +9731,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 f3cf7e5..30bd5aa 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -917,6 +917,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/+/766?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: Ibe0614bf6ced210c136b2d13036048188196f7ef Gerrit-Change-Number: 766 Gerrit-PatchSet: 1 Gerrit-Owner: its_Giaan Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --5zhWaACfqi4= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

its_Giaan would like plaisthos and flichtenheld to review this change.

Vi= ew Change

Refinement to handle simultaneous UDP and TCP connections
=
MULTI: properly remove TCP instances by checking the multi_instance
= protocol instead of the global one.

TLS: set the tls_option x= mit_hold bool value to true only in case of
TCP child instance to a= void checking the global protocol
value.

INIT: initialize th= e c->c2.event_set in the inherit_context_top()
by default and n= ot only in case of UDP since we could have
multiple different sock= ets.

Change-Id: Ibe0614bf6ced210c136b2d13036048188196f7ef
Signed-= off-by: Gianmarco De Gregori <gianmarco@...2726...>
---
M src/o= penvpn/forward.c
M src/openvpn/init.c
M src/openvpn/mtcp.c
M src/o= penvpn/mudp.c
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/op= envpn/multi_io.c
M src/openvpn/options.c
M src/openvpn/options.h
9= files changed, 143 insertions(+), 54 deletions(-)

git pull ssh:=
//gerrit.openvpn.net:29418/openvpn refs/changes/66/766/1
diff --git=
 a/src/openvpn/forward.c b/src/openvpn/forward.c
index 1357= cad..c37095d 100644
--- a/src/openvpn/forward.c
<= span>+++ b/src/openvpn/forward.c
@@ -2358,7 +2358,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
diff --git a/src/openvpn/init.c b/src/openvpn/init= .c
index c817ce6..51b49f2 100644
--- a/src/= openvpn/init.c
+++ b/src/openvpn/init.c
@@ = -224,7 +224,7 @@
if (streq(p[1], "HTTP")= )
{
struct http_proxy= _options *ho;
- = if (ce->proto !=3D PROTO_TCP && ce->proto !=3D PROTO_TCP_= CLIENT)
+ = if (ce->proto !=3D PROTO_TCP && c->mode !=3D CM_CHILD_TCP)
{
msg(M_WARN, &= quot;HTTP proxy support only works for TCP based connections");=
return false;
@@ -601,7 +601,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 && manage= ment_query_remote_enabled(management))
{@@ -2600,7 +2603,7 @@

if (fou= nd & OPT_P_EXPLICIT_NOTIFY)
{
- if (!proto_is_udp(c->options.ce= .proto) && c->options.ce.explicit_exit_notification)
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (!proto_is_udp(c->= ;c2.link_sockets[0]->info.proto) && c->options.ce.explicit_ex= it_notification)

{
ms= g(D_PUSH, "OPTIONS IMPORT: --explicit-exit-notify can only be used wit= h --proto udp");
c->options.ce.explici= t_exit_notification =3D 0;
@@ -2760,14 +2763,21 @@ int sec =3D 2;
int backoff =3D 0;<= br>
- switch = (c->options.ce.proto)
+ switch (c->mode)
{
- case PROTO_TCP_SERVER:
- sec =3D 1;

<= span style=3D"color: hsl(120, 100%, 40%);">+ case CM_TOP:

= + if (has_udp_in_loc= al_list(&c->options))
+ {
+ }
+ 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;
}
@@ -2785,7 += 2795,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 &&am= p; c->options.tls_client))
{
= backoff =3D (c->options.unsuccessful_attempts / c->options.connect= ion_list->len) - 4;
@@ -3265,7 +3275,21 @@
to.server =3D options->tls_server;
to.repla= y_window =3D options->replay_window;
to.replay_time= =3D options->replay_time;
- to.tcp_mode =3D link_socket_proto_connection_oriented(options-&= gt;ce.proto);
+
+ if (c->options.ce.= local_list->len > 1)
+ {
+ = for (int i =3D 0; i < c->options.ce.local_list->len; i++)<= br>+ {
+ 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.ce.local_list-= >array[0]->proto);
+ }
to.config_ciphername =3D c->options.ciph= ername;
to.config_ncp_ciphers =3D c->options.ncp_ci= phers;
to.transition_window =3D options->transition= _window;
@@ -3310,7 +3334,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;
= }
@@ -4214,20 +4238,13 @@
#ifdef _WIN= 32
msg(M_INFO, "NOTE: --fast-io is disabled s= ince we are running on Windows");
#else
- if (!proto_is_udp(c->opt= ions.ce.proto))
+ = if (c->options.shaper)
{
- msg(M_INFO, "NOTE: --fa= st-io is disabled since we are not using UDP");
+ msg(M_INFO, "NOTE: --fas= t-io is disabled since we are using --shaper");
= }
else
{
- if (c->options.shape= r)
- {
- msg(M_INFO,= "NOTE: --fast-io is disabled since we are using --shaper");

- }
- else
- {
- c->c2.fast_io =3D true;

- }
+ c->c2.fast_io =3D= true;
}
#endif
= }
@@ -4924,6 +4941,7 @@

/* options */
dest->options =3D src->opt= ions;
+ dest->o= ptions.ce.proto =3D ls->info.proto;
options_detach(= &dest->options);

dest->c2.= event_set =3D src->c2.event_set;
@@ -5022,10 +5040,7 @@<= /span>
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, fals= e);

- }
+ do_event_set_init(dest, fals= e);


#ifdef USE_COMP
= dest->c2.comp_context =3D NULL;
diff --git a/src/openvp= n/mtcp.c b/src/openvpn/mtcp.c
index 1eb28ec..ba705a8 100644=
--- a/src/openvpn/mtcp.c
+++ b/src/openvpn= /mtcp.c
@@ -153,12 +153,19 @@
{
= 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_defer= red) ? EVENT_WRITE : EVENT_READ,
- &mi->ev_arg,
- &mi->tcp_rwflags);

+ if (proto_is_d= gram(mi->context.c2.link_sockets[0]->info.proto))
+ {
+ return;
+ }
+ else
+ {
+ = mi->socket_set_called =3D true;
+ socket_set(mi->context.c2.link_soc= kets[0],
+ = m->multi_io->es,
+ mbuf_defined(mi->tcp_link_out_defe= rred) ? EVENT_WRITE : EVENT_READ,
+ &mi->ev_arg,
+ &mi->tcp= _rwflags);
+ }=
}
}

diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c
inde= x f9efcd5..9edd6ad 100644
--- a/src/openvpn/mudp.c+++ b/src/openvpn/mudp.c
@@ -194,6 +194,7 @@=
struct hash *hash =3D m->hash;
real.= proto =3D ls->info.proto;
m->local.proto =3D rea= l.proto;
+ m->h= mac_reply_ls =3D ls;

if (mroute_extr= act_openvpn_sockaddr(&real, &m->top.c2.from.dest, true) && m->top.c2.buf.len > 0)
@@= -320,15 +321,8 @@
msg_set_prefix("Connection= Attempt");
m->top.c2.to_link =3D m->hm= ac_reply;
m->top.c2.to_link_addr =3D m->hmac= _reply_dest;
- f= or (int i =3D 0; i < m->top.c1.link_sockets_num; i++)
- {
- if (!proto_is_dgram(m->top.c2.link= _sockets[i]->info.proto))
- {
- = continue;
-

- process_outgoi= ng_link(&m->top, m->top.c2.link_sockets[i]);
- }
+ process_outgoing_link(&m->top, m->= hmac_reply_ls);
+ = m->hmac_reply_ls =3D NULL;
m->hmac_reply= _dest =3D NULL;
}
}
d= iff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index= 4a6dd52..a6cdb67 100644
--- a/src/openvpn/multi.c+++ b/src/openvpn/multi.c
@@ -606,6 +606,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");
<= br>@@ -664,7 +665,7 @@
mi->did_iroute= s =3D false;
}

- if (m->multi_io && != proto_is_dgram(m->top.options.ce.proto))
+ if (!is_dgram)
{
multi_tcp_dereference_instance(m->multi_io, = mi);
}
@@ -3400,7 +3401,7 @@
/* decrypt in instance context */
=
perf_push(PERF_PROC_IN_LINK);
- lsi =3D get_link_socket_i= nfo(c);

+ = lsi =3D &ls->info;
orig_buf =3D c->c= 2.buf.data;
if (process_incoming_link_part1(c,= lsi, floated))
{
@@ -3851,7 += 3852,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_dg= ram(mi->context.options.ce.proto))
{
= send_control_channel_string(&mi->context, next_se= rver ? "RESTART,[N]" : "RESTART", D_PUSH);
multi_schedule_context_wakeup(m, mi);

@@ -= 3889,13 +3890,15 @@
status_close(so);
return false;

}
- else if (proto_is_dgram(m->top.options.c= e.proto)
- = && is_exit_restart(m->top.sig->signal_received)
- && (m->defe= rred_shutdown_signal.signal_received =3D=3D 0)
- && m->top.options.ce.expli= cit_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-&g= t;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.c= e.explicit_exit_notification =3D=3D 2);
+ return false;
+ }
}
= return true;
}
diff --git a/src/openv= pn/multi.h b/src/openvpn/multi.h
index 65fd320..670826e 100= 644
--- a/src/openvpn/multi.h
+++ b/src/ope= nvpn/multi.h
@@ -200,6 +200,7 @@
struct buffer hmac_reply;
struct link_soc= ket_actual *hmac_reply_dest;
+ struct link_socket *hmac_reply_ls;
/*
* Timer object for stale route check
diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c=
index 57ed10e..269b045 100644
--- a/src/op= envpn/multi_io.c
+++ b/src/openvpn/multi_io.c
@@ -142,6 +142,11 @@

= &m->top.c2.link_sockets[i]->ev_arg);
}


+ = if (has_udp_in_local_list(&m->top.options))
+ {
+ get_io_flags_udp(&m->top, m->multi_io, p= 2mp_iow_flags(m));
+ = }
+
#ifdef _WIN32
if (tuntap_is_wintun(m->top.c1.tun= tap))
{
@@ -396,6 +401,10 @@ 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.fa= st_io
+ = ? (MPP_CONDITIONAL_PRE_SELECT | MPP_CLOSE_ON_SIGNAL)
+ = : (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);
= int i;

for (i =3D 0; i < multi_= io->n_esr; ++i)
@@ -447,6 +456,39 @@
= }
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)
+ {<= br>+ = multi_io->udp_flags =3D ES_ERROR;
+ msg(D_LINK_ERRORS,
+ = "MULTI PROTOCOL: io_work: non socket event delivered&quo= t;);
+ = break;
+ }
+ }
+ else
+ {
+ ev_arg->p= ending =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);
+ }
+ }
= + else
+ = {
+ = multi_process_io_udp(m);
+ }
+ break;
+ }
= }
}
else
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 42210da..a06813e 100644
--- a/src/openvpn/= options.c
+++ b/src/openvpn/options.c
@@ -9= 93,10 +993,13 @@
const struct conn= ection_entry *e,
const int i)
{
- set= env_str_i(es, "proto", proto2ascii(e->proto, e->af, false),= i);
- /* expected t= o befor single socket contexts only */
- setenv_str_i(es, "local", e->local_list-&= gt;array[0]->local, i);
- setenv_str_i(es, "local_port", e->local_list->arra= y[0]->port, i);
+ = for (int j =3D 0; j < e->local_list->len; j++)
+ {
+ setenv_str_i(es, "proto", proto2= ascii(e->local_list->array[j]->proto, e->af, false), i);=
+ /* expected to bef= or 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-&= gt;array[j]->port, i);
+ }
setenv_str_i(es, "remote", e->= ;remote, i);
setenv_str_i(es, "remote_port",= e->remote_port, i);

@@ -2466,7 +2469,= 7 @@
{
struct local_entry *le= =3D ce->local_list->array[i];

- if (proto_is_net(ce->proto)
+ if (proto_is_ne= t(le->proto)
&& string_defined_equa= l(le->local, ce->remote)
&& stri= ng_defined_equal(le->port, ce->remote_port))
= {
@@ -3828,6 +3831,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++)<= /span>
@@ -9722,3 +9731,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_d= gram(options->ce.local_list->array[i]->proto))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+}
diff --git a/src/openvpn/options.h b/src/openvpn/= options.h
index f3cf7e5..30bd5aa 100644
---= a/src/openvpn/options.h
+++ b/src/openvpn/options.h=
@@ -917,6 +917,8 @@

bool key_i= s_external(const struct options *options);

+bool has_udp_in_local_list(const s= truct options *options);

+
/**
* Returns whether the current = configuration has dco enabled.
*/
=

To view, visit change 766. To unsubscribe, or for help writing mail= filters, visit settings= .

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ibe0614bf6ced210c136b2d13036= 048188196f7ef
Gerrit-Change-Number: 766
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
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
--5zhWaACfqi4=--