From: "cron2 (Code Review)" Date: Wed, 14 Jan 2026 11:51:28 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, antonio@...2726... Message-ID: <519b72d4eb87e0838c33d2b82dc0b4ee72cb6cbc-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="gJmlFAT0fro="; charset=UTF-8 Subject: [Openvpn-devel] [XS] Change in openvpn[master]: Repair interaction between DCO and persist-tun after reconnection List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: plaisthos , openvpn-devel --gJmlFAT0fro= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/14= 73?usp=3Demail ) Change subject: Repair interaction between DCO and persist-tun after reconn= ection ...................................................................... Repair interaction between DCO and persist-tun after reconnection When --persist-tun is active, openvpn userland on Linux and FreeBSD fails to re-enable "poll for DCO events" after a reconnect (e.g. triggered by a ping timeout). The reconnect will still work fine, but the *next* DCO event notification from the kernel will not be received by OpenVPN userland, and so the system will get into an inconsistent state (Userland assumes "all is well", kernel DCO has disconnected the peer, connection is broken until the next tls-renegotion and/or manual restart, *and* the next DCO key setup might fail due to "peer id gone"). This only affects client side, --server tun is always "persistent", and there is no "full restart" (and the code path in question is also only used for client and p2p server). The root cause is an incorrect check for "is this interface up?" when calling dco_event_set() in forard.c::io_wait() - "c2.did_open_tun" is only true if the tun interface was actually configured on this reconnect, which it isn't if --persist-tun is active. Replace with a check for "do we have a tuntap structure, and if yes, do we have active DCO?" which reflects the original intent much better. The original code also had a check for "out_socket & EVENT_READ" there, which did to some extend avoid calling dco_event_set() for every single UDP packet sent and received by userland - but this only worked on initial connection, and is always true on reconnect, so this condition was removed for simplicity. We should come back here... v2: - some language fixes on the commit message - do not check ->dco.open in forward.c, as this is not available if not on FreeBSD, or if compiled with --disable-dco. FreeBSD DCO does the "if (!dco || !dco->open)" check in dco_event_set() anyway, so it's not needed, and Linux DCO has "dco->nl_sock", which is also reliably set/unset, and checked by dco_event_set() already. Github: OpenVPN/openvpn#947 Change-Id: Idbd0a47ba4d297a833a350611a23f19fd9a797b5 Signed-off-by: Gert Doering Acked-by: Antonio Quartulli Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1473 Message-Id: <20260114112403.7046-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35= 239.html Signed-off-by: Gert Doering --- M src/openvpn/forward.c 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index d208c21..39ac3b3 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -2197,7 +2197,7 @@ multi_io_process_flags(c, c->c2.event_set, flags, &out_socket, &out_tu= ntap); #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) - if (out_socket & EVENT_READ && c->c2.did_open_tun) + if (c->c1.tuntap) { dco_event_set(&c->c1.tuntap->dco, c->c2.event_set, (void *)dco_shi= ft); } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1473?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Idbd0a47ba4d297a833a350611a23f19fd9a797b5 Gerrit-Change-Number: 1473 Gerrit-PatchSet: 3 Gerrit-Owner: cron2 Gerrit-Reviewer: ordex Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --gJmlFAT0fro= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

Repair interaction between DCO and persist-tun a=
fter reconnection

When --persist-tun is active, openvpn userland on = Linux and FreeBSD fails
to re-enable "poll for DCO events" aft= er a reconnect (e.g. triggered by
a ping timeout). The reconnect will s= till work fine, but the *next*
DCO event notification from the kernel wi= ll not be received by OpenVPN
userland, and so the system will get into = an inconsistent state (Userland
assumes "all is well", kernel = DCO has disconnected the peer, connection
is broken until the next tls-r= enegotion and/or manual restart, *and* the
next DCO key setup might fail= due to "peer id gone").

This only affects client side, --= server tun is always "persistent", and
there is no "full = restart" (and the code path in question is also
only used for clien= t and p2p server).

The root cause is an incorrect check for "is= this interface up?" when
calling dco_event_set() in forard.c::io_w= ait() - "c2.did_open_tun" is
only true if the tun interface wa= s actually configured on this reconnect,
which it isn't if --persist= -tun is active. Replace with a check for
"do we have a tuntap stru= cture, and if yes, do we have active DCO?"
which reflects the origi= nal intent much better.

The original code also had a check for "= ;out_socket & EVENT_READ" there,
which did to some extend avoid= calling dco_event_set() for every single
UDP packet sent and received b= y userland - but this only worked on initial
connection, and is always t= rue on reconnect, so this condition was removed
for simplicity. We shou= ld come back here...

v2:
- some language fixes on the commit me= ssage
- do not check ->dco.open in forward.c, as this is not availa= ble if
not on FreeBSD, or if compiled with --disable-dco.
Fre= eBSD DCO does the "if (!dco || !dco->open)" check in dco_event= _set()
anyway, so it's not needed, and Linux DCO has "dco-&= gt;nl_sock", which is
also reliably set/unset, and checked by d= co_event_set() already.

Github: OpenVPN/openvpn#947

Change-Id= : Idbd0a47ba4d297a833a350611a23f19fd9a797b5
Signed-off-by: Gert Doering = <gert@...1296...>
Acked-by: Antonio Quartulli <antonio@...2786...= ..>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1473
Messag= e-Id: <20260114112403.7046-1-gert@...1296...>
URL: https://www.mai= l-archive.com/openvpn-devel@lists.sourceforge.net/msg35239.html
Signed-o= ff-by: Gert Doering <gert@...1296...>
---
M src/openvpn/forward= .c
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index d208c21..39ac3b3 100644
--- a/src/openvpn/forward.= c
+++ b/src/openvpn/forward.c
@@ -2197,7 +2= 197,7 @@
multi_io_process_flags(c, c->c2.event_set,= flags, &out_socket, &out_tuntap);

#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
- if (out_socket & EVENT_READ &= & c->c2.did_open_tun)
+ if (c->c1.tuntap)
{
= dco_event_set(&c->c1.tuntap->dco, c->c2.event_set, (voi= d *)dco_shift);
}

= To view, visit change 1473. To unsubscribe, or for help writing mail filters, v= isit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Idbd0a47ba4d297a833a350611a2= 3f19fd9a797b5
Gerrit-Change-Number: 1473
Gerrit-PatchSet: 3
Gerrit-Owner: cron2 <gert@...1296...>
Gerrit-Reviewer: ordex <antonio@...2726...&= gt;
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --gJmlFAT0fro=--