From: "cron2 (Code Review)" Date: Sat, 17 May 2025 08:46:39 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., antonio@...2726... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="mCmaoYiuuTw="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: dco_linux: fix peer stats parsing with new ovpn kernel module List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --mCmaoYiuuTw= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#3) to the change originally created by= ordex. ( http://gerrit.openvpn.net/c/openvpn/+/1025?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: dco_linux: fix peer stats parsing with new ovpn kernel modu= le ...................................................................... dco_linux: fix peer stats parsing with new ovpn kernel module The new ovpn kernel module has changed the netlink attribute type of the fields containing the pkt/bytes counters in the peer stats. We moved from uint64 to uint (a dynamic type can be either 32 or 64 bits), therefore the parsing code must be adapted accordingly. While at it, also fix the peer object parsing in the P2P code path. The fix can be verified by enabling --status with verb 6 and watching the counters increasing: 2025-05-16 22:23:56 us=3D649488 dco_get_peer_stats_multi 2025-05-16 22:23:56 us=3D651008 dco_parse_peer_multi: parsing message... 2025-05-16 22:23:56 us=3D651734 dco_update_peer_stat / dco_read_bytes: 116= 280 2025-05-16 22:23:56 us=3D652682 dco_update_peer_stat / dco_write_bytes: 11= 5776 2025-05-16 22:23:56 us=3D653467 dco_update_peer_stat / tun_read_bytes: 900= 48 2025-05-16 22:23:56 us=3D654110 dco_update_peer_stat / tun_write_bytes: 90= 048 Change-Id: I104b4adeb9f65cce3487b82f35470174acba92bc Github: closes OpenVPN/openvpn#746 Signed-off-by: Antonio Quartulli Acked-by: Gert Doering Message-Id: <20250517083231.27977-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31= 666.html Signed-off-by: Gert Doering --- M src/openvpn/dco_linux.c 1 file changed, 21 insertions(+), 10 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/1025/3 diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index a5f9e06..3f7965e 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -908,12 +908,26 @@ return ovpn_nl_recvmsgs(dco, __func__); } +/* libnl < 3.11.0 does not implement nla_get_uint() */ +static uint64_t +ovpn_nla_get_uint(struct nlattr *attr) +{ + if (nla_len(attr) =3D=3D sizeof(uint32_t)) + { + return nla_get_u32(attr); + } + else + { + return nla_get_u64(attr); + } +} + static void dco_update_peer_stat(struct context_2 *c2, struct nlattr *tb[], uint32_t i= d) { if (tb[OVPN_A_PEER_LINK_RX_BYTES]) { - c2->dco_read_bytes =3D nla_get_u64(tb[OVPN_A_PEER_LINK_RX_BYTES]); + c2->dco_read_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_LINK_RX_BY= TES]); msg(D_DCO_DEBUG, "%s / dco_read_bytes: " counter_format, __func__, c2->dco_read_bytes); } @@ -925,7 +939,7 @@ if (tb[OVPN_A_PEER_LINK_TX_BYTES]) { - c2->dco_write_bytes =3D nla_get_u64(tb[OVPN_A_PEER_LINK_TX_BYTES]); + c2->dco_write_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_LINK_TX_B= YTES]); msg(D_DCO_DEBUG, "%s / dco_write_bytes: " counter_format, __func__, c2->dco_write_bytes); } @@ -937,7 +951,7 @@ if (tb[OVPN_A_PEER_VPN_RX_BYTES]) { - c2->tun_read_bytes =3D nla_get_u64(tb[OVPN_A_PEER_VPN_RX_BYTES]); + c2->tun_read_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_VPN_RX_BYT= ES]); msg(D_DCO_DEBUG, "%s / tun_read_bytes: " counter_format, __func__, c2->tun_read_bytes); } @@ -949,7 +963,7 @@ if (tb[OVPN_A_PEER_VPN_TX_BYTES]) { - c2->tun_write_bytes =3D nla_get_u64(tb[OVPN_A_PEER_VPN_TX_BYTES]); + c2->tun_write_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_VPN_TX_BY= TES]); msg(D_DCO_DEBUG, "%s / tun_write_bytes: " counter_format, __func__, c2->tun_write_bytes); } @@ -1028,12 +1042,12 @@ dco_parse_peer(struct nl_msg *msg, void *arg) { struct context *c =3D arg; - struct nlattr *tb[OVPN_A_MAX]; + struct nlattr *tb[OVPN_A_MAX + 1]; struct genlmsghdr *gnlh =3D nlmsg_data(nlmsg_hdr(msg)); msg(D_DCO_DEBUG, "%s: parsing message...", __func__); - nla_parse(tb, OVPN_A_PEER_MAX, genlmsg_attrdata(gnlh, 0), + nla_parse(tb, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); if (!tb[OVPN_A_PEER]) @@ -1043,10 +1057,7 @@ } struct nlattr *tb_peer[OVPN_A_PEER_MAX + 1]; - - nla_parse(tb_peer, OVPN_A_PEER, - nla_data(tb[OVPN_A_PEER]), - nla_len(tb[OVPN_A_PEER]), NULL); + nla_parse_nested(tb_peer, OVPN_A_PEER_MAX, tb[OVPN_A_PEER], NULL); if (!tb_peer[OVPN_A_PEER_ID]) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1025?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I104b4adeb9f65cce3487b82f35470174acba92bc Gerrit-Change-Number: 1025 Gerrit-PatchSet: 3 Gerrit-Owner: ordex Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --mCmaoYiuuTw= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #3 to the change originally cr= eated by ordex.

View Change

The following approvals got outdated an= d were removed: Code-Review+2 by cron2

dco_linux: fix peer stats parsing with new ovpn kern=
el module

The new ovpn kernel module has changed the netlink attribu= te
type of the fields containing the pkt/bytes counters in the
peer s= tats.

We moved from uint64 to uint (a dynamic type can be either
= 32 or 64 bits), therefore the parsing code must be adapted
accordingly.<= br>
While at it, also fix the peer object parsing in the P2P code path.<= br>
The fix can be verified by enabling --status with verb 6 and
watc= hing the counters increasing:

2025-05-16 22:23:56 us=3D649488 dco_g= et_peer_stats_multi
2025-05-16 22:23:56 us=3D651008 dco_parse_peer_mult= i: parsing message...
2025-05-16 22:23:56 us=3D651734 dco_update_peer_s= tat / dco_read_bytes: 116280
2025-05-16 22:23:56 us=3D652682 dco_update= _peer_stat / dco_write_bytes: 115776
2025-05-16 22:23:56 us=3D653467 dc= o_update_peer_stat / tun_read_bytes: 90048
2025-05-16 22:23:56 us=3D654= 110 dco_update_peer_stat / tun_write_bytes: 90048

Change-Id: I104b4a= deb9f65cce3487b82f35470174acba92bc
Github: closes OpenVPN/openvpn#746Signed-off-by: Antonio Quartulli <antonio@...2726...>
Acked-by: G= ert Doering <gert@...1296...>
Message-Id: <20250517083231.27977= -1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@...465...= ists.sourceforge.net/msg31666.html
Signed-off-by: Gert Doering <gert@= ...1296...>
---
M src/openvpn/dco_linux.c
1 file changed, 21 in= sertions(+), 10 deletions(-)

git pull ssh://gerrit.openvpn.net:29=
418/openvpn refs/changes/25/1025/3
diff --git a/src/openvpn/dco_lin=
ux.c b/src/openvpn/dco_linux.c
index a5f9e06..3f7965e 10064= 4
--- a/src/openvpn/dco_linux.c
+++ b/src/o= penvpn/dco_linux.c
@@ -908,12 +908,26 @@
= return ovpn_nl_recvmsgs(dco, __func__);
}

+/* libnl < 3= .11.0 does not implement nla_get_uint() */
+static uint64_t
+ovpn_nla_get_uint(struct nlattr *attr)
+{
+ if (nla_len(attr) =3D=3D sizeof(uint32_t))+ {
+ return nla_get_u32(attr);<= br>+ }
+ else
+ {
+ return nla_get_u64(attr);
+ }
+}
+ static void
dco_update_peer_stat(struct context_2= *c2, struct nlattr *tb[], uint32_t id)
{
= if (tb[OVPN_A_PEER_LINK_RX_BYTES])
{
- c2->dco_read_bytes =3D = nla_get_u64(tb[OVPN_A_PEER_LINK_RX_BYTES]);
+ c2->dco_read_bytes =3D ovpn_nla_get_uint= (tb[OVPN_A_PEER_LINK_RX_BYTES]);
msg(D_DCO_DEBUG, = "%s / dco_read_bytes: " counter_format, __func__,
c2->dco_read_bytes);
}
@@ -925,7 +939,7 @@

if (tb[OVPN_A_= PEER_LINK_TX_BYTES])
{
- c2->dco_write_bytes =3D nla_get_u64(tb[OVP= N_A_PEER_LINK_TX_BYTES]);
+ c2->dco_write_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_L= INK_TX_BYTES]);
msg(D_DCO_DEBUG, "%s / dco_wr= ite_bytes: " counter_format, __func__,
c2= ->dco_write_bytes);
}
@@ -937,7 +95= 1,7 @@

if (tb[OVPN_A_PEER_VPN_RX_BYT= ES])
{
- c2->tun_read_bytes =3D nla_get_u64(tb[OVPN_A_PEER_VPN_RX_B= YTES]);
+ c2-&= gt;tun_read_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_VPN_RX_BYTES]);

msg(D_DCO_DEBUG, "%s / tun_read_bytes: " cou= nter_format, __func__,
c2->tun_read_bytes);=
}
@@ -949,7 +963,7 @@

if (tb[OVPN_A_PEER_VPN_TX_BYTES])
= {
- c2->t= un_write_bytes =3D nla_get_u64(tb[OVPN_A_PEER_VPN_TX_BYTES]);
+ c2->tun_write_bytes = =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_VPN_TX_BYTES]);
= msg(D_DCO_DEBUG, "%s / tun_write_bytes: " counter_format, __fu= nc__,
c2->tun_write_bytes);
}
@@ -1028,12 +1042,12 @@
dco_parse_= peer(struct nl_msg *msg, void *arg)
{
= struct context *c =3D arg;
- struct nlattr *tb[OVPN_A_MAX];
+ struct nlattr *tb[OVPN_A_MAX + 1];
struct genlmsghdr *gnlh =3D nlmsg_data(nlmsg_hdr(msg));

msg(D_DCO_DEBUG, "%s: parsing message...&quo= t;, __func__);

- nla_parse(tb, OVPN_A_PEER_MAX, genlmsg_attrdata(gnlh, 0),

+ nla_parse(tb, OVPN= _A_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_a= ttrlen(gnlh, 0), NULL);

if (!tb[OVPN= _A_PEER])
@@ -1043,10 +1057,7 @@
}


struct nlattr *tb_peer[OVPN_A_PEER_MAX = + 1];
-
- nla_parse(tb_peer, OVPN_A_PEER,
- nla_data(= tb[OVPN_A_PEER]),
- = nla_len(tb[OVPN_A_PEER]), NULL);
+ nla_parse_nested(tb_peer, OVPN_A_PEER_MAX, tb[OV= PN_A_PEER], NULL);

if (!tb_peer[OVPN= _A_PEER_ID])
{

To = view, visit change 1025. To unsubscribe, or for help writing mail filters, visi= t settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I104b4adeb9f65cce3487b82f354= 70174acba92bc
Gerrit-Change-Number: 1025
Gerrit-PatchSet: 3
Gerrit-Owner: ordex <antonio@...2726...>=
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--mCmaoYiuuTw=--