]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: ipstats: Iterate all xstats attributes
authorPetr Machata <petrm@nvidia.com>
Tue, 10 Jun 2025 15:51:24 +0000 (17:51 +0200)
committerDavid Ahern <dsahern@kernel.org>
Mon, 16 Jun 2025 02:14:07 +0000 (02:14 +0000)
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>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ipstats.c

index cb9d9cbbe7f1a4dc25c2faea7c6f5d8b171f5805..f0f8dcdcbd2a9e1c83eed6ca54df28b91c058d9c 100644 (file)
@@ -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;
 }