From: Petr Machata <petrm@nvidia.com>
To: David Ahern <dsahern@gmail.com>, <netdev@vger.kernel.org>
Cc: Ido Schimmel <idosch@nvidia.com>,
Nikolay Aleksandrov <razor@blackwall.org>,
<bridge@lists.linux-foundation.org>,
Petr Machata <petrm@nvidia.com>
Subject: [PATCH iproute2-next v3 1/4] ip: ipstats: Iterate all xstats attributes
Date: Tue, 10 Jun 2025 17:51:24 +0200 [thread overview]
Message-ID: <c09ea07d23bd11cb906e9a48595f0347a18f9117.1749567243.git.petrm@nvidia.com> (raw)
In-Reply-To: <cover.1749567243.git.petrm@nvidia.com>
ipstats_stat_desc_show_xstats() operates by first parsing the attribute
stream into a type-indexed table, and then accessing the right attribute.
But bridge VLAN stats are given as several BRIDGE_XSTATS_VLAN attributes,
one per VLAN. With the above approach to parsing, only one of these
attributes would be shown. Instead, iterate the stream of attributes and
call the show_cb for each one with a matching type.
Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
---
Notes:
v2:
- Use rtattr_for_each_nested
- Drop #include <alloca.h>, it's not used anymore
ip/ipstats.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/ip/ipstats.c b/ip/ipstats.c
index cb9d9cbb..f0f8dcdc 100644
--- a/ip/ipstats.c
+++ b/ip/ipstats.c
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: GPL-2.0+
-#include <alloca.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
@@ -590,7 +589,7 @@ int ipstats_stat_desc_show_xstats(struct ipstats_stat_show_attrs *attrs,
{
struct ipstats_stat_desc_xstats *xdesc;
const struct rtattr *at;
- struct rtattr **tb;
+ const struct rtattr *i;
int err;
xdesc = container_of(desc, struct ipstats_stat_desc_xstats, desc);
@@ -600,15 +599,13 @@ int ipstats_stat_desc_show_xstats(struct ipstats_stat_show_attrs *attrs,
if (at == NULL)
return err;
- tb = alloca(sizeof(*tb) * (xdesc->inner_max + 1));
- err = parse_rtattr_nested(tb, xdesc->inner_max, at);
- if (err != 0)
- return err;
-
- if (tb[xdesc->inner_at] != NULL) {
- print_nl();
- xdesc->show_cb(tb[xdesc->inner_at]);
+ rtattr_for_each_nested(i, at) {
+ if (i->rta_type == xdesc->inner_at) {
+ print_nl();
+ xdesc->show_cb(i);
+ }
}
+
return 0;
}
--
2.49.0
next prev parent reply other threads:[~2025-06-10 15:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 15:51 [PATCH iproute2-next v3 0/4] ip: Support bridge VLAN stats in `ip stats' Petr Machata
2025-06-10 15:51 ` Petr Machata [this message]
2025-06-10 15:51 ` [PATCH iproute2-next v3 2/4] ip: ip_common: Drop ipstats_stat_desc_xstats::inner_max Petr Machata
2025-06-10 15:51 ` [PATCH iproute2-next v3 3/4] lib: bridge: Add a module for bridge-related helpers Petr Machata
2025-06-10 15:51 ` [PATCH iproute2-next v3 4/4] ip: iplink_bridge: Support bridge VLAN stats in `ip stats' Petr Machata
2025-06-10 16:13 ` Ido Schimmel
2025-06-16 2:25 ` [PATCH iproute2-next v3 0/4] ip: " David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c09ea07d23bd11cb906e9a48595f0347a18f9117.1749567243.git.petrm@nvidia.com \
--to=petrm@nvidia.com \
--cc=bridge@lists.linux-foundation.org \
--cc=dsahern@gmail.com \
--cc=idosch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=razor@blackwall.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox