]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ipstats: Expose bond stats in ipstats
authorPetr Machata <petrm@nvidia.com>
Mon, 9 May 2022 14:00:02 +0000 (16:00 +0200)
committerDavid Ahern <dsahern@kernel.org>
Thu, 12 May 2022 17:08:30 +0000 (11:08 -0600)
Describe xstats and xstats_slave subgroups for bond netdevices.

For example:

 # ip stats show dev swp1 group xstats_slave subgroup bond
 56: swp1: group xstats_slave subgroup bond suite 802.3ad
                     LACPDU Rx 0
                     LACPDU Tx 0
                     LACPDU Unknown type Rx 0
                     LACPDU Illegal Rx 0
                     Marker Rx 0
                     Marker Tx 0
                     Marker response Rx 0
                     Marker response Tx 0
                     Marker unknown type Rx 0

 # ip -j stats show dev swp1 group xstats_slave subgroup bond | jq
 [
   {
     "ifindex": 56,
     "ifname": "swp1",
     "group": "xstats_slave",
     "subgroup": "bond",
     "suite": "802.3ad",
     "802.3ad": {
       "lacpdu_rx": 0,
       "lacpdu_tx": 0,
       "lacpdu_unknown_rx": 0,
       "lacpdu_illegal_rx": 0,
       "marker_rx": 0,
       "marker_tx": 0,
       "marker_response_rx": 0,
       "marker_response_tx": 0,
       "marker_unknown_rx": 0
     }
   }
 ]

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ip_common.h
ip/iplink_bond.c
ip/ipstats.c

index c58f20907b5ad0cfea6605c41b45b14cf69df0f7..ffa633e0997034a2f59873df55d24fa5ecffa3c1 100644 (file)
@@ -145,8 +145,11 @@ int bridge_print_xstats(struct nlmsghdr *n, void *arg);
 extern const struct ipstats_stat_desc ipstats_stat_desc_xstats_bridge_group;
 extern const struct ipstats_stat_desc ipstats_stat_desc_xstats_slave_bridge_group;
 
+/* iplink_bond.c */
 int bond_parse_xstats(struct link_util *lu, int argc, char **argv);
 int bond_print_xstats(struct nlmsghdr *n, void *arg);
+extern const struct ipstats_stat_desc ipstats_stat_desc_xstats_bond_group;
+extern const struct ipstats_stat_desc ipstats_stat_desc_xstats_slave_bond_group;
 
 /* iproute_lwtunnel.c */
 int lwt_parse_encap(struct rtattr *rta, size_t len, int *argcp, char ***argvp,
index 650411fc7de12119b06b1f50919d833ed6d086cb..15db19a3d3c2b0b2ff91474b46d029a92fb648b0 100644 (file)
@@ -15,6 +15,7 @@
 #include <string.h>
 #include <linux/if_bonding.h>
 
+#include "list.h"
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
@@ -761,7 +762,7 @@ static void bond_print_xstats_help(struct link_util *lu, FILE *f)
        fprintf(f, "Usage: ... %s [ 802.3ad ] [ dev DEVICE ]\n", lu->id);
 }
 
-static void bond_print_3ad_stats(struct rtattr *lacpattr)
+static void bond_print_3ad_stats(const struct rtattr *lacpattr)
 {
        struct rtattr *lacptb[BOND_3AD_STAT_MAX+1];
        __u64 val;
@@ -912,7 +913,6 @@ int bond_parse_xstats(struct link_util *lu, int argc, char **argv)
        return 0;
 }
 
-
 struct link_util bond_link_util = {
        .id             = "bond",
        .maxattr        = IFLA_BOND_MAX,
@@ -922,3 +922,54 @@ struct link_util bond_link_util = {
        .parse_ifla_xstats = bond_parse_xstats,
        .print_ifla_xstats = bond_print_xstats,
 };
+
+static const struct ipstats_stat_desc ipstats_stat_desc_bond_tmpl_lacp = {
+       .name = "802.3ad",
+       .kind = IPSTATS_STAT_DESC_KIND_LEAF,
+       .show = &ipstats_stat_desc_show_xstats,
+       .pack = &ipstats_stat_desc_pack_xstats,
+};
+
+static const struct ipstats_stat_desc_xstats
+ipstats_stat_desc_xstats_bond_lacp = {
+       .desc = ipstats_stat_desc_bond_tmpl_lacp,
+       .xstats_at = IFLA_STATS_LINK_XSTATS,
+       .link_type_at = LINK_XSTATS_TYPE_BOND,
+       .inner_max = BOND_XSTATS_MAX,
+       .inner_at = BOND_XSTATS_3AD,
+       .show_cb = &bond_print_3ad_stats,
+};
+
+static const struct ipstats_stat_desc *
+ipstats_stat_desc_xstats_bond_subs[] = {
+       &ipstats_stat_desc_xstats_bond_lacp.desc,
+};
+
+const struct ipstats_stat_desc ipstats_stat_desc_xstats_bond_group = {
+       .name = "bond",
+       .kind = IPSTATS_STAT_DESC_KIND_GROUP,
+       .subs = ipstats_stat_desc_xstats_bond_subs,
+       .nsubs = ARRAY_SIZE(ipstats_stat_desc_xstats_bond_subs),
+};
+
+static const struct ipstats_stat_desc_xstats
+ipstats_stat_desc_xstats_slave_bond_lacp = {
+       .desc = ipstats_stat_desc_bond_tmpl_lacp,
+       .xstats_at = IFLA_STATS_LINK_XSTATS_SLAVE,
+       .link_type_at = LINK_XSTATS_TYPE_BOND,
+       .inner_max = BOND_XSTATS_MAX,
+       .inner_at = BOND_XSTATS_3AD,
+       .show_cb = &bond_print_3ad_stats,
+};
+
+static const struct ipstats_stat_desc *
+ipstats_stat_desc_xstats_slave_bond_subs[] = {
+       &ipstats_stat_desc_xstats_slave_bond_lacp.desc,
+};
+
+const struct ipstats_stat_desc ipstats_stat_desc_xstats_slave_bond_group = {
+       .name = "bond",
+       .kind = IPSTATS_STAT_DESC_KIND_GROUP,
+       .subs = ipstats_stat_desc_xstats_slave_bond_subs,
+       .nsubs = ARRAY_SIZE(ipstats_stat_desc_xstats_slave_bond_subs),
+};
index 1051976d5177e552c433c812908a2c95bb782895..5cdd15ae0e390501e3153783a9d9497cb3548b22 100644 (file)
@@ -606,6 +606,7 @@ int ipstats_stat_desc_show_xstats(struct ipstats_stat_show_attrs *attrs,
 
 static const struct ipstats_stat_desc *ipstats_stat_desc_xstats_subs[] = {
        &ipstats_stat_desc_xstats_bridge_group,
+       &ipstats_stat_desc_xstats_bond_group,
 };
 
 static const struct ipstats_stat_desc ipstats_stat_desc_xstats_group = {
@@ -617,6 +618,7 @@ static const struct ipstats_stat_desc ipstats_stat_desc_xstats_group = {
 
 static const struct ipstats_stat_desc *ipstats_stat_desc_xstats_slave_subs[] = {
        &ipstats_stat_desc_xstats_slave_bridge_group,
+       &ipstats_stat_desc_xstats_slave_bond_group,
 };
 
 static const struct ipstats_stat_desc ipstats_stat_desc_xstats_slave_group = {