The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
event/multi: add event_arg object to make eve=
nt handling more generic
In order to prepare the event handling code=
to deal with multiple listening sockets, we have to make sure that it i=
s possible to distinguish which of these sockets have been poked by an i=
ncoming connection request.
To achieve that, this patch changes t=
he object being passed as event handler argument, from a "partly in=
teger-evaluated variable" to a full struct with a proper type attri=
bute.
This struct will allow the code to carry around the particular=
listening socket where the connection is being established.
This=
change affects the TCP server code path only as UDP servers use only on=
e socket to handle all clients.
Change-Id: Icd7f6a2ad350cdc2312b3e80=
fa0dbdd7e4311d2e Signed-off-by: Antonio Quartulli <a@...2181...>--- M src/openvpn/event.h M src/openvpn/mtcp.c M src/openvpn/mul=
ti.c M src/openvpn/multi.h M src/openvpn/socket.c M src/openvpn/so=
cket.h 6 files changed, 68 insertions(+), 28 deletions(-)
<=
pre style=3D"font-family: monospace,monospace; white-space: pre-wrap;">git =
pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/757/3
d=
iff --git a/src/openvpn/event.h b/src/openvpn/event.h index=
856551a..844ea7b 100644 --- a/src/openvpn/event.h+++ b/src/openvpn/event.h @@ -126,6 +126,20 @@ struct event_set_functions func; }; +typedef=
enum { + EVENT_AR=
G_MULTI_INSTANCE =3D 0, + EVENT_ARG_LINK_SOCKET, +} event_arg_t; + +/* generic ev=
ent argument object to pass to event_ctl() */ +struct event_arg +{ + event_arg_t type; + union { + =
struct multi_instance *mi; /* if type =3D EVENT_ARG_MULTI_INSTANCE *=
/ + } u; +}; + /* * maxev=
ents on input: desired max number of event_t descriptors =
* simultaneously set with event_ctl d=
iff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c index 9=
6408d1..bb151af 100644 --- a/src/openvpn/mtcp.c <=
span>+++ b/src/openvpn/mtcp.c @@ -54,7 +54,6 @@ <=
span> /* * Special tags passed to event.[ch] functions */ -#de=
fine MTCP_SOCKET ((void *)1) #define MTCP_TUN =
((void *)2) #define MTCP_SIG ((void *)3) /* Only =
on Windows */ #define MTCP_MANAGEMENT ((void *)4)@@ -253,7 +252,7 @@ socket_set(mi->cont=
ext.c2.link_socket, m->mtcp->es,<=
/span> mbuf_defined(mi->tcp_link_out_deferr=
ed) ? EVENT_WRITE : EVENT_READ, - mi, + &mi->ev_arg, =
&mi->tcp_rwflags); } } @@ -263,8 +262,8 @@ s=
truct multi_tcp *mtcp) { int status;<=
/span> - unsigned int *pers=
istent =3D &mtcp->tun_rwflags; - socket_set_listen_persistent(c->c2.link_socket, mtcp=
->es, MTCP_SOCKET); + socket_set_listen_persistent(c->c2.link_socket, mtcp->es, + =
&c->c2.link_socket->ev_arg); #ifdef _WIN32 if (tuntap_is_wintun(c->c1.tu=
ntap)) @@ -280,7 +279,7 @@ persist=
ent =3D NULL; } #endif - tun_set(c->c1.tuntap, mtcp-&g=
t;es, EVENT_READ, MTCP_TUN, persistent); + tun_set(c->c1.tuntap, mtcp->es, EVENT_READ, =
MTCP_TUN, &mtcp->tun_rwflags); #if defined(TARGET_L=
INUX) || defined(TARGET_FREEBSD) dco_event_set(&c-=
>c1.tuntap->dco, mtcp->es, MTCP_DCO); #endif @@ -692,21 +691,44 @@ for (i =3D 0; i <=
mtcp->n_esr; ++i) { struc=
t event_set_return *e =3D &mtcp->esr[i]; + struct event_arg *ev_arg =3D (struct ev=
ent_arg *)e->arg; - /* incoming data for instance? */ + /* incoming data for instanc=
e or listening socket? */ if (e->arg >=3D MT=
CP_N) { - struct multi_instance *mi =3D (struct multi_instance=
*) e->arg; - =
if (mi) + =
switch (ev_arg->type) { - if (e->rwflags &a=
mp; EVENT_WRITE) - =
{ - =
multi_tcp_action(m, mi, TA_SOCKET_WRITE_READY, false); - } - else if (e->rwfl=
ags & EVENT_READ) -=
{ - =
multi_tcp_action(m, mi, TA_SOCKET_READ, false); <=
span style=3D"color: hsl(0, 100%, 40%);">- } + struct multi_instan=
ce *mi; + <=
span style=3D"color: hsl(120, 100%, 40%);">+ /* react to eve=
nt on child instance */ + case EVENT_ARG_MULTI_INSTANCE: + if (!ev_arg->u.mi) + {<=
/span> + =
msg(D_MULTI_ERRORS, "MULTI: mtcp_proc_io: null minstance");=
span> + =
break; + =
} +<=
br>+ mi =3D =
ev_arg->u.mi; + =
if (e->rwflags & EVENT_WRITE) + { + multi_tcp_actio=
n(m, mi, TA_SOCKET_WRITE_READY, false); + } + else if (e->rwflags & EVEN=
T_READ) + =
{ + =
multi_tcp_action(m, mi, TA_SOCKET_READ, false); + } <=
span style=3D"color: hsl(120, 100%, 40%);">+ break; + + /* new incoming TCP clien=
t attempting to connect? */ + case EVENT_ARG_LINK_SOCKET: + ASSERT(m->top.c2.l=
ink_socket); + =
socket_reset_listen_persistent(m->top.c2.link_socket); + mi =
=3D multi_create_instance_tcp(m); + if (mi) + { + multi_tcp_action(m, mi, TA_=
INITIAL, false); + =
} + =
break; } =
} else @@ -731,18 +753,6 @@=
multi_tcp_action(m, NULL, TA_TUN_READ=
, false); } }=
- /* new in=
coming TCP client attempting to connect? */ - else if (e->arg =3D=3D MTCP_SOCKET) - { =
- struct multi_ins=
tance *mi; - =
ASSERT(m->top.c2.link_socket); - socket_reset_listen_persistent(m->top.c=
2.link_socket); - =
mi =3D multi_create_instance_tcp(m); - if (mi) - { - multi_tcp_action(m, mi, TA_INITI=
AL, false); - =
} - }<=
/span> #if defined(ENABLE_DCO) && (defined(TARGET_LINUX) =
|| defined(TARGET_FREEBSD)) /* incoming data o=
n DCO? */ else if (e->arg =3D=3D MTCP_DCO)<=
/span> diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 0509911..45b3cfa 100644 --- a/src/openvpn=
/multi.c +++ b/src/openvpn/multi.c @@ -823,=
6 +823,9 @@ goto err; } + mi-=
>ev_arg.type =3D EVENT_ARG_MULTI_INSTANCE; + mi->ev_arg.u.mi =3D mi; + perf_pop(); gc_free(&gc); return mi;diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 7167639..7b78ddd 100644 --- a/src/openvpn/multi.h=
+++ b/src/openvpn/multi.h @@ -102,6 +102,1=
2 @@ struct schedule_entry se; /* this must be the fi=
rst element of the structure, =
* We cast between this and schedule_entry so the =
* beginning of the struct must be identical */=
span> + + struct event_arg ev_arg; /** this =
struct will store a pointer to either mi or + * link_socket, depe=
nding on the event type, to keep + * it accessible it's place=
d within the same struct + * it points to. */ + struct gc_arena g=
c; bool halt; int refcount; diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c<=
br>index 7b1e603..cf04090 100644 --- a/src/openvpn/so=
cket.c +++ b/src/openvpn/socket.c @@ -1830,=
6 +1830,8 @@ ALLOC_OBJ_CLEAR(sock, struct link_socket)=
; sock->sd =3D SOCKET_UNDEFINED; =
sock->ctrl_sd =3D SOCKET_UNDEFINED; + sock->ev_arg.type =3D EVENT_ARG_LINK_SOCKET;=
span> + =
return sock; } diff --g=
it a/src/openvpn/socket.h b/src/openvpn/socket.h index 2e58=
3af..5ff31ea 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -178,6 +178,11 @@<=
br> { struct link_socket_info info; + struct eve=
nt_arg ev_arg; /** this struct will store a pointer to either mi or + =
* link_socket, depending on the event type, to keep + * it=
accessible it's placed within the same struct + * it points =
to. */ + socket_descriptor_t sd; socket_descriptor_t c=
trl_sd; /* only used for UDP over Socks */
To view, visit change 757. To unsubscribe, or for help wri=
ting mail filters, visit set=
tings.