[PATCH iproute2-next v3 1/4] ip: ipstats: Iterate all xstats attributes
From: Petr Machata <petrm@nvidia.com>
Date: 2025-06-10 15:54:19
Also in:
bridge
Subsystem:
the rest · Maintainer:
Linus Torvalds
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