From: "cron2 (Code Review)" Date: Sun, 9 Nov 2025 11:00:27 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, ralf@...2726..., frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="KYYYUrqFy/U="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: dco_freebsd: implement dco_get_peer_stats() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ralf_lici , plaisthos , flichtenheld , openvpn-devel --KYYYUrqFy/U= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/13= 50?usp=3Demail ) Change subject: dco_freebsd: implement dco_get_peer_stats() ...................................................................... dco_freebsd: implement dco_get_peer_stats() This is "fetch read/write statistics for a single peer", complementing dco_get_peer_stats_multi() "... for all peers", and it is called in --client mode, and (!) in p2mp mode to check if --inactive thresholds are reached. The FreeBSD DCO module has no "give me stats for a single peer" call, so we just call dco_get_peer_stats_multi() to get all of them - and that function is modified to handle p2p or p2mp mode by checking mode =3D=3D CM_= TOP. (dco_linux does about the same in dco_get_peer*() -> ovpn_handle_peer(), after a few iterations, except that it can query for "just one peer") "--inactive" still does not work on FreeBSD, because the code in forward.c looks at counters that are not set by FreeBSD DCO. v2: on AUTH_FAIL, 'dco' struct is not initialized yet -> SIGSEGV crash, verify that dco_peer_id is >=3D 0 before calling dco_get_peer_stats_multi= () Github: OpenVPN/openvpn#898 Change-Id: I38a040a9bdcb44933d4ca538f746af5c61011d7c Signed-off-by: Gert Doering Acked-by: Ralf Lici Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1350 Message-Id: <20251109084130.11463-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34= 273.html Signed-off-by: Gert Doering --- M src/openvpn/dco_freebsd.c 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index f80b6df..21f0ac0 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -870,8 +870,20 @@ { const nvlist_t *peer =3D nvpeers[i]; uint32_t peerid =3D nvlist_get_number(peer, "peerid"); + const nvlist_t *bytes =3D nvlist_get_nvlist(peer, "bytes"); - dco_update_peer_stat(dco->c->multi, peerid, nvlist_get_nvlist(peer= , "bytes")); + /* we can end here in p2mp mode, or in p2p mode via + * the call to "dco_get_peer_stat()" + */ + if (dco->c->mode =3D=3D CM_TOP) + { + dco_update_peer_stat(dco->c->multi, peerid, bytes); + } + else + { + dco->c->c2.dco_read_bytes =3D nvlist_get_number(bytes, "in"); + dco->c->c2.dco_write_bytes =3D nvlist_get_number(bytes, "out"); + } } nvlist_destroy(nvl); @@ -882,12 +894,26 @@ #pragma GCC diagnostic pop #endif +/* get stats for a single peer + * we can get here for "the peer stats" in p2p client mode, or by + * being queried for a particular peer in p2mp mode, for --inactive + */ int dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err) { - msg(D_DCO_DEBUG, __func__); - /* Not implemented. */ - return 0; + ASSERT(c->c2.tls_multi); + msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, c->c2.tls_multi->dco_peer= _id); + + if (c->c2.tls_multi->dco_peer_id < 0) + { + return -EINVAL; /* DCO not active yet */ + } + + /* unfortunately, the FreeBSD kernel has no peer-specific query - so + * we just get all the stats - and if we're there anyway, we can save = it + * for all peers, too... + */ + return dco_get_peer_stats_multi(&c->c1.tuntap->dco, raise_sigusr1_on_e= rr); } const char * -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1350?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: I38a040a9bdcb44933d4ca538f746af5c61011d7c Gerrit-Change-Number: 1350 Gerrit-PatchSet: 4 Gerrit-Owner: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: ralf_lici Gerrit-CC: openvpn-devel --KYYYUrqFy/U= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

dco_freebsd: implement dco_get_peer_stats()
<= br>This is "fetch read/write statistics for a single peer", compl= ementing
dco_get_peer_stats_multi() "... for all peers", and i= t is called in
--client mode, and (!) in p2mp mode to check if --inactiv= e thresholds
are reached.

The FreeBSD DCO module has no "giv= e me stats for a single peer" call, so
we just call dco_get_peer_st= ats_multi() to get all of them - and that
function is modified to handle= p2p or p2mp mode by checking mode =3D=3D CM_TOP.

(dco_linux does ab= out the same in dco_get_peer*() -> ovpn_handle_peer(),
after a few it= erations, except that it can query for "just one peer")

&q= uot;--inactive" still does not work on FreeBSD, because the code in fo= rward.c
looks at counters that are not set by FreeBSD DCO.

v2: on AUTH_FAIL, 'dco' struct is not initialized yet -> SIGSEGV = crash,
verify that dco_peer_id is >=3D 0 before calling dco_get_pee= r_stats_multi()

Github: OpenVPN/openvpn#898

Change-Id: I38a04= 0a9bdcb44933d4ca538f746af5c61011d7c
Signed-off-by: Gert Doering <gert= @...1296...>
Acked-by: Ralf Lici <ralf@...2726...>
Gerrit UR= L: https://gerrit.openvpn.net/c/openvpn/+/1350
Message-Id: <202511090= 84130.11463-1-gert@...1296...>
URL: https://www.mail-archive.com/open= vpn-devel@lists.sourceforge.net/msg34273.html
Signed-off-by: Gert Doerin= g <gert@...1296...>
---
M src/openvpn/dco_freebsd.c
1 file c= hanged, 30 insertions(+), 4 deletions(-)

diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c
index f80b6df..21f0ac0 100644
--- a/src/openvpn/= dco_freebsd.c
+++ b/src/openvpn/dco_freebsd.c
@@ -870,8 +870,20 @@
{
con= st nvlist_t *peer =3D nvpeers[i];
uint32_t peerid = =3D nvlist_get_number(peer, "peerid");
+ const nvlist_t *bytes =3D nvlist_get_n= vlist(peer, "bytes");

- dco_update_peer_stat(dco->c->mult= i, peerid, nvlist_get_nvlist(peer, "bytes"));
+ /* we can end here in p2mp mode= , or in p2p mode via
= + * the call to "dco_get_peer_stat()"
+ */
+ if (dco->c->mode =3D=3D CM_TOP)
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ dco_update_peer_sta= t(dco->c->multi, peerid, bytes);

+ }
+ else
+ {
+ = dco->c->c2.dco_read_bytes =3D nvlist_get_number(bytes, "in&q= uot;);
+ d= co->c->c2.dco_write_bytes =3D nvlist_get_number(bytes, "out"= ;);
+ }=
}

nvlist_destroy(nvl)= ;
@@ -882,12 +894,26 @@
#pragma GCC diagno= stic pop
#endif

+/* get stats for a single peer
+ * we can get here for "the = peer stats" in p2p client mode, or by
+ * being queried for a particular peer in p2mp mode,= for --inactive
+ */<= /span>
int
dco_get_peer_stats(struct context *c,= const bool raise_sigusr1_on_err)
{
- msg(D_DCO_DEBUG, __func__);
<= span style=3D"color: hsl(0, 100%, 40%);">- /* Not implemented. */
=
- return 0;
+ ASSERT(c->c2.tls_multi);
+ msg(D_DCO_DEBUG, &= quot;%s: peer-id %d", __func__, c->c2.tls_multi->dco_peer_id);
+
+ if (c->c2.tls_multi->dco_peer_= id < 0)
+ {

+ return -EINVAL;= /* DCO not active yet */
+ }
+<= br>+ /* unfortunately, the F= reeBSD kernel has no peer-specific query - so
+ * we just get all the stats - and if we'= re there anyway, we can save it
+ * for all peers, too...
+ */
+ return dco_get_peer_stats_multi(&c->c1.tuntap->dco, = raise_sigusr1_on_err);
}

const char *

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

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38a040a9bdcb44933d4ca538f74= 6af5c61011d7c
Gerrit-Change-Number: 1350
Gerrit-PatchSet: 4
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>
= --KYYYUrqFy/U=--