From: "ralf_lici (Code Review)" Date: Tue, 25 Nov 2025 09:14:57 +0000 References: Reply-To: ralf@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="egqxiu5Fq5U="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: dco: process messages immediately after read List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --egqxiu5Fq5U= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1403?usp=3Demail to review the following change. Change subject: dco: process messages immediately after read ...................................................................... dco: process messages immediately after read Currently, reading and processing of incoming DCO messages are decoupled: notifications are read, parsed, and the relevant information is stored in fields of dco_context_t for later processing (with the only exception being stats). This approach is problematic on Linux, since libnl does not allow reading a single netlink message at a time, which can result in loss of information when multiple notifications are available. This change adopts a read -> parse -> process paradigm. On Linux, processing is now invoked directly from within the parsing callback, which libnl calls for each received netlink packet. The other interfaces are adapted accordingly to unify the processing model across all platforms. Reported-by: Stefan Baranoff Change-Id: Iefc251cb4483c0b9fb9d6a5207db4445cd884d52 Signed-off-by: Ralf Lici --- M src/openvpn/dco.h M src/openvpn/dco_freebsd.c M src/openvpn/dco_linux.c M src/openvpn/dco_win.c M src/openvpn/forward.c M src/openvpn/forward.h M src/openvpn/mudp.c M src/openvpn/multi.c M src/openvpn/multi.h M src/openvpn/multi_io.c 10 files changed, 74 insertions(+), 41 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/03/1403/1 diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h index e5e8709..cd6e32a 100644 --- a/src/openvpn/dco.h +++ b/src/openvpn/dco.h @@ -127,12 +127,13 @@ void close_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx); /** - * Read data from the DCO communication channel (i.e. a control packet) + * Read and process data from the DCO communication channel + * (i.e. a control packet) * * @param dco the DCO context * @return 0 on success or a negative error code otherwise */ -int dco_do_read(dco_context_t *dco); +int dco_read_and_process(dco_context_t *dco); /** * Install a DCO in the main event loop @@ -305,7 +306,7 @@ } static inline int -dco_do_read(dco_context_t *dco) +dco_read_and_process(dco_context_t *dco) { ASSERT(false); return 0; diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index f2a89ac..ff29ee7 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -578,7 +578,7 @@ } int -dco_do_read(dco_context_t *dco) +dco_read_and_process(dco_context_t *dco) { struct ifdrv drv; uint8_t buf[4096]; @@ -689,6 +689,16 @@ nvlist_destroy(nvl); + if (dco->c->mode =3D=3D CM_TOP) + { + ASSERT(dco->c->multi); + multi_process_incoming_dco(dco->c->multi); + } + else + { + process_incoming_dco(dco->c); + } + return 0; } diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index 0ae30b1..ebdfc34 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -1094,29 +1094,34 @@ * message, that stores the type-specific attributes. * * the "dco" object is then filled accordingly with the information - * retrieved from the message, so that the rest of the OpenVPN code can - * react as need be. + * retrieved from the message, so that *process_incoming_dco can react + * as need be. */ + int ret; switch (gnlh->cmd) { case OVPN_CMD_PEER_GET: { - return ovpn_handle_peer(dco, attrs); + ret =3D ovpn_handle_peer(dco, attrs); + break; } case OVPN_CMD_PEER_DEL_NTF: { - return ovpn_handle_peer_del_ntf(dco, attrs); + ret =3D ovpn_handle_peer_del_ntf(dco, attrs); + break; } case OVPN_CMD_PEER_FLOAT_NTF: { - return ovpn_handle_peer_float_ntf(dco, attrs); + ret =3D ovpn_handle_peer_float_ntf(dco, attrs); + break; } case OVPN_CMD_KEY_SWAP_NTF: { - return ovpn_handle_key_swap_ntf(dco, attrs); + ret =3D ovpn_handle_key_swap_ntf(dco, attrs); + break; } default: @@ -1125,11 +1130,26 @@ return NL_STOP; } + if (ret !=3D NL_OK) + { + return ret; + } + + if (dco->c->mode =3D=3D CM_TOP) + { + ASSERT(dco->c->multi); + multi_process_incoming_dco(dco); + } + else + { + process_incoming_dco(dco); + } + return NL_OK; } int -dco_do_read(dco_context_t *dco) +dco_read_and_process(dco_context_t *dco) { msg(D_DCO_DEBUG, __func__); diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index ca5eedf..54044c5 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -690,7 +690,7 @@ } int -dco_do_read(dco_context_t *dco) +dco_read_and_process(dco_context_t *dco) { if (dco->ifmode !=3D DCO_MODE_MP) { @@ -727,6 +727,16 @@ break; } + if (dco->c->mode =3D=3D CM_TOP) + { + ASSERT(dco->c->multi); + multi_process_incoming_dco(dco); + } + else + { + ASSERT(false); + } + return 0; } diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index f01fb4c..3ef8794 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1243,13 +1243,11 @@ } } -static void -process_incoming_dco(struct context *c) +void +process_incoming_dco(dco_context_t *dco) { #if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBS= D)) - dco_context_t *dco =3D &c->c1.tuntap->dco; - - dco_do_read(dco); + struct context *c =3D dco->c; /* no message for us to handle - platform specific code has logged det= ails */ if (dco->dco_message_type =3D=3D 0) @@ -2379,7 +2377,7 @@ { if (!IS_SIG(c)) { - process_incoming_dco(c); + dco_read_and_process(&c->c1.tuntap->dco); } } } diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h index a575faf..9e9b02e 100644 --- a/src/openvpn/forward.h +++ b/src/openvpn/forward.h @@ -210,6 +210,13 @@ const struct sockaddr *float_sa); /** + * Process an incoming DCO message (from kernel space). + * + * @param dco - Pointer to the structure representing the DCO context. + */ +void process_incoming_dco(dco_context_t *dco); + +/** * Write a packet to the external network interface. * @ingroup external_multiplexer * diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index 31134be..08ec8ff 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -417,11 +417,7 @@ { if (!IS_SIG(&m->top)) { - bool ret =3D true; - while (ret) - { - ret =3D multi_process_incoming_dco(m); - } + dco_read_and_process(&m->top.c1.tuntap->dco); } } #endif diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 2b944667..f3c770e 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -3263,14 +3263,10 @@ multi_signal_instance(m, mi, SIGTERM); } -bool -multi_process_incoming_dco(struct multi_context *m) +void +multi_process_incoming_dco(dco_context_t *dco) { - dco_context_t *dco =3D &m->top.c1.tuntap->dco; - - struct multi_instance *mi =3D NULL; - - int ret =3D dco_do_read(&m->top.c1.tuntap->dco); + struct multi_context *m =3D dco->c->multi; int peer_id =3D dco->dco_message_peer_id; @@ -3279,12 +3275,12 @@ */ if (peer_id < 0) { - return ret > 0; + return; } if ((peer_id < m->max_clients) && (m->instances[peer_id])) { - mi =3D m->instances[peer_id]; + struct multi_instance *mi =3D m->instances[peer_id]; set_prefix(mi); if (dco->dco_message_type =3D=3D OVPN_CMD_DEL_PEER) { @@ -3329,7 +3325,6 @@ dco->dco_message_type =3D 0; dco->dco_message_peer_id =3D -1; dco->dco_del_peer_reason =3D -1; - return ret > 0; } #endif /* if defined(ENABLE_DCO) */ @@ -4462,4 +4457,4 @@ return (!ipv6_net_contains_host(&ifconfig_local, o->ifconfig_ipv6_netb= its, dest)); -} \ No newline at end of file +} diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index a62b07a..a44f9f2 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -305,13 +305,9 @@ /** * Process an incoming DCO message (from kernel space). * - * @param m - The single \c multi_context structure. - * - * @return - * - True, if the message was received correctly. - * - False, if there was an error while reading the message. + * @param dco - Pointer to the structure representing the DCO context. */ -bool multi_process_incoming_dco(struct multi_context *m); +void multi_process_incoming_dco(dco_context_t *dco); /*************************************************************************= */ /** diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c index 6e31687..3ade59f 100644 --- a/src/openvpn/multi_io.c +++ b/src/openvpn/multi_io.c @@ -516,7 +516,7 @@ /* incoming data on DCO? */ else if (e->arg =3D=3D MULTI_IO_DCO) { - multi_process_incoming_dco(m); + dco_read_and_process(&m->top.c1.tuntap->dco); } #endif /* signal received? */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1403?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Iefc251cb4483c0b9fb9d6a5207db4445cd884d52 Gerrit-Change-Number: 1403 Gerrit-PatchSet: 1 Gerrit-Owner: ralf_lici Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --egqxiu5Fq5U= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

ralf_lici would like plaisthos to review this change.

V= iew Change

dco: process messages immediately after rea=
d

Currently, reading and processing of incoming DCO messages are
= decoupled: notifications are read, parsed, and the relevant information
= is stored in fields of dco_context_t for later processing (with the onlyexception being stats). This approach is problematic on Linux, since
li= bnl does not allow reading a single netlink message at a time, which
can= result in loss of information when multiple notifications are
available= .

This change adopts a read -> parse -> process paradigm. On L= inux,
processing is now invoked directly from within the parsing callbac= k,
which libnl calls for each received netlink packet. The other interfa= ces
are adapted accordingly to unify the processing model across all
= platforms.

Reported-by: Stefan Baranoff
Change-Id: Iefc251cb4483c= 0b9fb9d6a5207db4445cd884d52
Signed-off-by: Ralf Lici <ralf@...2726...= >
---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/= openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/forward.cM src/openvpn/forward.h
M src/openvpn/mudp.c
M src/openvpn/multi.c<= br>M src/openvpn/multi.h
M src/openvpn/multi_io.c
10 files changed, 7= 4 insertions(+), 41 deletions(-)

git pull ssh:=
//gerrit.openvpn.net:29418/openvpn refs/changes/03/1403/1
diff --=
git a/src/openvpn/dco.h b/src/openvpn/dco.h
index e5e8709..= cd6e32a 100644
--- a/src/openvpn/dco.h
+++ = b/src/openvpn/dco.h
@@ -127,12 +127,13 @@
= void close_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx);

/**
- * Read data from the DCO communication channel (i.e. a control packet= )
+ * Read and proces= s data from the DCO communication channel
+ * (i.e. a control packet)
*=
* @param dco the DCO context
* @return = 0 on success or a negative error code otherwise
= */
-int dco_do_read(dco= _context_t *dco);
+in= t dco_read_and_process(dco_context_t *dco);

/**
* Install a DCO in the main event loop
= @@ -305,7 +306,7 @@
}

static inline int
= -dco_do_read(dco_context_t *dco)
+dco_read_and_process(dco_context_t *dco)
{

ASSERT(false);
return 0;
= diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c

index f2a89ac..ff29ee7 100644
--- a/src/openv= pn/dco_freebsd.c
+++ b/src/openvpn/dco_freebsd.c
= @@ -578,7 +578,7 @@
}

int
-dco_do_read(d= co_context_t *dco)
+d= co_read_and_process(dco_context_t *dco)
{
= struct ifdrv drv;
uint8_t buf[4096];
@@ -689,6 +689,16 @@

nvlist_dest= roy(nvl);

+ if (dco->c->mode =3D=3D CM_TOP)
+ {
+ ASSERT(dco->c->multi);
+ multi_process_incoming_dco(dco-&g= t;c->multi);
+ = }
+ else+ {
+ process_incoming_dco(dco->c);<= /span>
+ }
+

return 0;

}

diff --git a/src/openvpn= /dco_linux.c b/src/openvpn/dco_linux.c
index 0ae30b1..ebdfc= 34 100644
--- a/src/openvpn/dco_linux.c
+++= b/src/openvpn/dco_linux.c
@@ -1094,29 +1094,34 @@ * message, that stores the type-specific attributes. *
* the "dco" object is then = filled accordingly with the information
- * retrieved from the message, so that the rest of th= e OpenVPN code can
- = * react as need be.
+ * retrieved from the message, so that *process_incoming_dco can reac= t
+ * as need be.=
*/
+ int ret;
switch (gnlh->cmd)
{
case OVPN_CMD_PEER_GET:
= {
- = return ovpn_handle_peer(dco, attrs);
+ ret =3D ovpn_handle_peer(dco, attrs);<= br>+ break; }

case OVPN_CMD= _PEER_DEL_NTF:
{
- return ovpn_handle_peer_del_ntf(dco, attrs)= ;
+ ret = =3D ovpn_handle_peer_del_ntf(dco, attrs);
+ break;
}<= br>
case OVPN_CMD_PEER_FLOAT_NTF: {
- = return ovpn_handle_peer_float_ntf(dco, attrs);
+ ret =3D ovpn_handle_peer_flo= at_ntf(dco, attrs);
+= break;
}

<= span> case OVPN_CMD_KEY_SWAP_NTF:
{=
- return ovpn_hand= le_key_swap_ntf(dco, attrs);
+ ret =3D ovpn_handle_key_swap_ntf(dco, attrs);+ break; }

default:
@@ -1125,11 +1130,26 @@
return NL_S= TOP;
}

+ if (ret !=3D NL_OK)
+ {
+ return ret;
+ }
+
+ if (dco->c= ->mode =3D=3D CM_TOP)
+ {
+ A= SSERT(dco->c->multi);
+ multi_process_incoming_dco(dco);
+ }
+ else
+ {
+ pr= ocess_incoming_dco(dco);
+ }
+ return NL_OK;
}

<= span> int

-dco_do_read(= dco_context_t *dco)
+= dco_read_and_process(dco_context_t *dco)
{
msg(D_DCO_DEBUG, __func__);

diff --= git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c
index c= a5eedf..54044c5 100644
--- a/src/openvpn/dco_win.c+++ b/src/openvpn/dco_win.c
@@ -690,7 +690,7 @@

}

int
-dco_do_read(dco_context_t *dco)
= +dco_read_and_process(dco_conte= xt_t *dco)
{
if (dco->ifmode !=3D = DCO_MODE_MP)
{
@@ -727,6 +727,16 @@

break;
}
<= /span>
+ if (dco->c-&g= t;mode =3D=3D CM_TOP)
+ {
+ ASSE= RT(dco->c->multi);
+ multi_process_incoming_dco(dco);
+ }
+ else
= + {
+ ASSER= T(false);
+ }
+
re= turn 0;
}

diff --git a/s= rc/openvpn/forward.c b/src/openvpn/forward.c
index f01fb4c.= .3ef8794 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c

@@ -1243,13 +1243,11 @@=
}
}

-static void
-process_incoming_dco(struct context *c)
+void

+process_incoming_dco(dco_context_t *dco)<= br> {
#if defined(ENABLE_DCO) && (defined(TA= RGET_LINUX) || defined(TARGET_FREEBSD))
- dco_context_t *dco =3D &c->c1.tuntap->dco;<= /span>
-
- dco_do_read(dco);
+ struct context *c =3D dco->c;

/* no message for us to handle - platfor= m specific code has logged details */
if (dco->dco_= message_type =3D=3D 0)
@@ -2379,7 +2377,7 @@
{

if (!IS_SIG(c))
= {
- process_= incoming_dco(c);
+ = dco_read_and_process(&c->c1.tuntap->dco);
}

}
}
diff= --git a/src/openvpn/forward.h b/src/openvpn/forward.h
inde= x a575faf..9e9b02e 100644
--- a/src/openvpn/forward.h
+++ b/src/openvpn/forward.h
@@ -210,6 +210,13 @@=
const struct sockaddr *f= loat_sa);

/**
+ * Process an incoming DCO message (from kerne= l space).
+ *<= br>+ * @param dco - Pointer to = the structure representing the DCO context.
+ */
+void process_incoming_dco(dco_context_t *dco);
+
+/**
* Write a packet to the external netw= ork interface.
* @ingroup external_multiplexer
= *
diff --git a/src/openvpn/mudp.c b/src/openvpn/mud= p.c
index 31134be..08ec8ff 100644
--- a/src= /openvpn/mudp.c
+++ b/src/openvpn/mudp.c
@@= -417,11 +417,7 @@
{
if (!IS_= SIG(&m->top))
{
- bool ret =3D true;
- while (ret)
- {
- ret =3D multi_process_incoming= _dco(m);
- }=
+ dco_rea= d_and_process(&m->top.c1.tuntap->dco);
}=
}
#endif
diff --git = a/src/openvpn/multi.c b/src/openvpn/multi.c
index 2b944667.= .f3c770e 100644
--- a/src/openvpn/multi.c
+= ++ b/src/openvpn/multi.c
@@ -3263,14 +3263,10 @@
= multi_signal_instance(m, mi, SIGTERM);
}=

-bool
-multi_process_incoming_dco(= struct multi_context *m)
+void
+multi_proc= ess_incoming_dco(dco_context_t *dco)
{
- dco_context_t *dco =3D &m->top= .c1.tuntap->dco;
-
- struct multi_instan= ce *mi =3D NULL;
-
- int ret =3D dco_do_rea= d(&m->top.c1.tuntap->dco);
+ struct multi_context *m =3D dco->c->multi;

int peer_id =3D dco->dco_message_peer_= id;

@@ -3279,12 +3275,12 @@
*/

if (peer_id < 0)
{=
- return ret &g= t; 0;
+ return= ;
}

if ((peer_i= d < m->max_clients) && (m->instances[peer_id]))
= {
- m= i =3D m->instances[peer_id];
+ struct multi_instance *mi =3D m->instances[peer_id];=
set_prefix(mi);
if (dco-= >dco_message_type =3D=3D OVPN_CMD_DEL_PEER)
{
@@ -3329,7 +3325,6 @@
dco->dco_messa= ge_type =3D 0;
dco->dco_message_peer_id =3D -1;
dco->dco_del_peer_reason =3D -1;
- return ret > 0;
}
#endif /* if defined(ENABLE_DCO) */

@@ -4462,4 +4457,4 @@

ret= urn (!ipv6_net_contains_host(&ifconfig_local, o->ifconfig_ipv6_netbi= ts,
dest));
= -}
\ No newline a= t end of file
+}
diff --git a/src/openvpn/multi.h b/src/openvpn/multi.hindex a62b07a..a44f9f2 100644
--- a/src/openvpn/mul= ti.h
+++ b/src/openvpn/multi.h
@@ -305,13 += 305,9 @@
/**
* Process an incoming DCO m= essage (from kernel space).
*
- * @param m - The single \c multi_cont= ext structure.
- *
- * @return
- * - True, if the message was receiv= ed correctly.

- * - Fa= lse, if there was an error while reading the message.
+ * @param dco - Pointer to the structure = representing the DCO context.
*/
-bool multi_process_incoming_dco(struct multi_c= ontext *m);
+void mul= ti_process_incoming_dco(dco_context_t *dco);

/*********************************************************************= *****/

/**
diff --git a/src/openvpn/multi_= io.c b/src/openvpn/multi_io.c
index 6e31687..3ade59f 100644=
--- a/src/openvpn/multi_io.c
+++ b/src/ope= nvpn/multi_io.c
@@ -516,7 +516,7 @@
= /* incoming data on DCO? */
else= if (e->arg =3D=3D MULTI_IO_DCO)
{
- multi_= process_incoming_dco(m);
+ dco_read_and_process(&m->top.c1.tuntap->= dco);
}
#endif
= /* signal received? */

To view, visit change 1403. To unsubscribe, or for help writing mail fil= ters, visit sett= ings.

<= link itemprop=3D"url" href=3D"http://gerrit.openvpn.net/c/openvpn/+/1403?us= p=3Demail"/>
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iefc251cb4483c0b9fb9d6a5207d= b4445cd884d52
Gerrit-Change-Number: 1403
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <ralf@...2726...>= ;
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --egqxiu5Fq5U=--