From: "cron2 (Code Review)" Date: Sun, 9 Nov 2025 11:04:04 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, ralf@...2726..., frank@...2641... Message-ID: <0cc6cc3af4c0436454d844afa725a19c7c50eb92-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Egkhny6fvQg="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: FreeBSD DCO: repair --inactive List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ralf_lici , flichtenheld , plaisthos , openvpn-devel --Egkhny6fvQg= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/13= 51?usp=3Demail ) Change subject: FreeBSD DCO: repair --inactive ...................................................................... FreeBSD DCO: repair --inactive --inactive on DCO requires a working DCO counters query function (dco_get_peer_stats(), implemented in the previous commit) and that the DCO implementation in use fills the "tun_{read,write}_bytes" fields for the peer context. FreeBSD DCO only fills the "dco_{read,write}_bytes" counters - which is something we can't fix in OpenVPN, this needs kernel enhancements. So, to make the feature (mostly) work, check the other set of counters on FreeBSD. Caveat: this will count encryption overhead and keepalives, so it will still not work for `--inactive ` without a byte count, or for byte counts with too tight thresholds. Adding the #ifdef to forward.c was considered the least bad alternative. v2: fix rst syntax for manpage addition Github: OpenVPN/openvpn#898 Change-Id: I48c877843d24144450af1282b7524bb3ba18232e Signed-off-by: Gert Doering Acked-by: Ralf Lici Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1351 Message-Id: <20251109084238.11581-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34= 274.html Signed-off-by: Gert Doering --- M doc/man-sections/client-options.rst M src/openvpn/forward.c 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/doc/man-sections/client-options.rst b/doc/man-sections/client-= options.rst index 0aee9e2..e8523d9 100644 --- a/doc/man-sections/client-options.rst +++ b/doc/man-sections/client-options.rst @@ -274,6 +274,11 @@ counted as traffic, as they are used internally by OpenVPN and are not an indication of actual user activity. + NOTE: on FreeBSD with DCO, due to platform limits, the previous paragraph + is not correct. In that case, encapsulation overhead and keepalives are + counted, so using this feature needs a sufficiently-high ``bytes`` value= to + take these extra numbers into account. + --proto-force p When iterating through connection profiles, only consider profiles using protocol ``p`` (:code:`tcp` \| :code:`udp`). diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 5bbac13..c355f66 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -476,13 +476,20 @@ * and the logic needs to change - we permit the event to trigger and check * kernel DCO counters here, returning and rearming the timer if there was * sufficient traffic. + * + * NOTE: FreeBSD DCO does not supply "tun bytes" (=3D decrypted payload) t= oday, + * so "dco bytes" (encrypted bytes, including keepalives) is used instead */ static void check_inactivity_timeout(struct context *c) { if (dco_enabled(&c->options) && dco_get_peer_stats(c, true) =3D=3D 0) { +#ifdef TARGET_FREEBSD + int64_t tot_bytes =3D c->c2.dco_read_bytes + c->c2.dco_write_bytes; +#else int64_t tot_bytes =3D c->c2.tun_read_bytes + c->c2.tun_write_bytes; +#endif int64_t new_bytes =3D tot_bytes - c->c2.inactivity_bytes; if (new_bytes > c->options.inactivity_minimum_bytes) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1351?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: I48c877843d24144450af1282b7524bb3ba18232e Gerrit-Change-Number: 1351 Gerrit-PatchSet: 5 Gerrit-Owner: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: ralf_lici Gerrit-CC: openvpn-devel --Egkhny6fvQg= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

FreeBSD DCO: repair --inactive

--inactive= on DCO requires a working DCO counters query function
(dco_get_peer_sta= ts(), implemented in the previous commit) and
that the DCO implementatio= n in use fills the "tun_{read,write}_bytes"
fields for the pee= r context.

FreeBSD DCO only fills the "dco_{read,write}_bytes&q= uot; counters - which is
something we can't fix in OpenVPN, this nee= ds kernel enhancements.

So, to make the feature (mostly) work, check= the other set of counters
on FreeBSD. Caveat: this will count encrypti= on overhead and keepalives,
so it will still not work for `--inactive &l= t;n>` without a byte count, or
for byte counts with too tight thresho= lds.

Adding the #ifdef to forward.c was considered the least bad alt= ernative.

v2: fix rst syntax for manpage addition

Github: Ope= nVPN/openvpn#898

Change-Id: I48c877843d24144450af1282b7524bb3ba18232= e
Signed-off-by: Gert Doering <gert@...1296...>
Acked-by: Ralf = Lici <ralf@...2726...>
Gerrit URL: https://gerrit.openvpn.net/c/op= envpn/+/1351
Message-Id: <20251109084238.11581-1-gert@...1296...><= br>URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/ms= g34274.html
Signed-off-by: Gert Doering <gert@...1296...>
---M doc/man-sections/client-options.rst
M src/openvpn/forward.c
2 fil= es changed, 12 insertions(+), 0 deletions(-)

diff --git a/doc/man-sections/client-options.rst b/doc/man-sections/clie=
nt-options.rst
index 0aee9e2..e8523d9 100644
--- a/doc/man-sections/client-options.rst
+++ b/doc/man-s= ections/client-options.rst
@@ -274,6 +274,11 @@
<= span> counted as traffic, as they are used internally by OpenVPN and are = not
an indication of actual user activity.

+ NOTE: on Free= BSD with DCO, due to platform limits, the previous paragraph
+ is not correct. In that case, e= ncapsulation overhead and keepalives are
+ counted, so using this feature needs a sufficiently-= high ``bytes`` value to
+ take these extra numbers into account.
+
--proto-force p
= When iterating through connection profiles, only consider profiles using=
protocol ``p`` (:code:`tcp` \| :code:`udp`).
= diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
= index 5bbac13..c355f66 100644
--- a/src/openvpn/forwa= rd.c
+++ b/src/openvpn/forward.c
@@ -476,13= +476,20 @@
* and the logic needs to change - we permit t= he event to trigger and check
* kernel DCO counters here,= returning and rearming the timer if there was
* sufficie= nt traffic.
+ *
+ * NOTE: FreeBSD DCO does= not supply "tun bytes" (=3D decrypted payload) today,
= + * so "dco bytes" (e= ncrypted bytes, including keepalives) is used instead
*/<= /span>
static void
check_inactivity_timeout(stru= ct context *c)
{
if (dco_enabled(&= ;c->options) && dco_get_peer_stats(c, true) =3D=3D 0)
= {
+#ifdef = TARGET_FREEBSD
+ = int64_t tot_bytes =3D c->c2.dco_read_bytes + c->c2.dco_write_bytes= ;
+#else
int64_t tot_bytes =3D c->c2.tun_read_bytes + c->c2.tun_w= rite_bytes;

+#endif
int64_t new_bytes =3D tot_bytes - c->c2.inactivi= ty_bytes;

if (new_bytes > c-&= gt;options.inactivity_minimum_bytes)

To= view, visit change 1351. To unsubscribe, or for help writing mail filters, vis= it settings.=

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I48c877843d24144450af1282b75= 24bb3ba18232e
Gerrit-Change-Number: 1351
Gerrit-PatchSet: 5
Gerrit-Owner: cron2 <gert@...1296...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-Reviewer: ralf_lici <ralf@...2726...= >
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --Egkhny6fvQg=--