All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats
@ 2022-05-09 13:59 Petr Machata
  2022-05-09 13:59 ` [PATCH iproute2-next 01/10] iplink: Fix formatting of MPLS stats Petr Machata
                   ` (10 more replies)
  0 siblings, 11 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-09 13:59 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

The RTM_GETSTATS response attributes IFLA_STATS_LINK_XSTATS and
IFLA_STATS_LINK_XSTATS_SLAVE are used to carry statistics related to,
respectively, netdevices of a certain type, and netdevices enslaved to
netdevices of a certain type. IFLA_STATS_AF_SPEC are similarly used to
carry statistics specific to a certain address family.

In this patch set, add support for three new stats groups that cover the
above attributes: xstats, xstats_slave and afstats. Add bridge and bond
subgroups to the former two groups, and mpls subgroup to the latter one.

Now "group" is used for selecting the top-level attribute, and subgroup
for the link-type or address-family nest below it (bridge, bond, mpls in
this patchset). But xstats (both master and slave) are further
subdivided. E.g. in the case of bridge statistics, the two subdivisions
are called "stp" and "mcast". To make it possible to pick these sets,
add to the two selector levels of group and subgroup a third level,
suite, which is filtered in the userspace.

The patchset progresses as follows:

- Patches #1 and #2 fix up MPLS stats formatting and expose the helpers
  for reuse.
- Patch #3 adds ip stats group afstats and a subgroup mpls
- Patch #4 adds support for JSON formatting to MPLS

- Patch #5 adds support for the selector level "suite"
- Patch #6 adds groups "xstats" and "xstats_slave"
- Patches #7 and #8 first prepare helpers, then add support for the
  "bridge" subgroup of the xstats groups.
- Patch #9 adds the "bond" subgroup.

- Patch #10 adds manual page coverage.

Petr Machata (10):
  iplink: Fix formatting of MPLS stats
  iplink: Publish a function to format MPLS stats
  ipstats: Add a group "afstats", subgroup "mpls"
  iplink: Add JSON support to MPLS stats formatter
  ipstats: Add a third level of stats hierarchy, a "suite"
  ipstats: Add groups "xstats", "xstats_slave"
  iplink_bridge: Split bridge_print_stats_attr()
  ipstats: Expose bridge stats in ipstats
  ipstats: Expose bond stats in ipstats
  man: ip-stats.8: Describe groups xstats, xstats_slave and afstats

 ip/ip_common.h      |  22 +++
 ip/iplink.c         |  75 ++++++++--
 ip/iplink_bond.c    |  55 +++++++-
 ip/iplink_bridge.c  | 334 ++++++++++++++++++++++++++++----------------
 ip/ipstats.c        | 126 ++++++++++++++++-
 man/man8/ip-stats.8 |  50 ++++++-
 6 files changed, 522 insertions(+), 140 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH iproute2-next 01/10] iplink: Fix formatting of MPLS stats
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
@ 2022-05-09 13:59 ` Petr Machata
  2022-05-09 13:59 ` [PATCH iproute2-next 02/10] iplink: Publish a function to format " Petr Machata
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-09 13:59 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

Currently, MPLS stats are formatted this way:

 # ip -n ns0-DBZpxj8I link afstats dev veth01
 3: veth01
     mpls:
         RX: bytes  packets  errors  dropped  noroute
                  0        0       0        0       0
         TX: bytes  packets  errors  dropped
                216        2       0       0

Note how most numbers are not aligned properly under their column headers.
Fix by converting the code to use size_columns() to dynamically determine
the necessary width of individual columns, which also takes care of
formatting the table properly in case the counter values are high.
After the fix, the formatting looks as follows:

 # ip -n ns0-Y1PyEc55 link afstats dev veth01
 3: veth01
     mpls:
         RX: bytes packets errors dropped noroute
                 0       0      0       0       0
         TX: bytes packets errors dropped
               108       1      0       0

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 ip/iplink.c | 44 ++++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 12 deletions(-)

diff --git a/ip/iplink.c b/ip/iplink.c
index 23eb6c6e..b87d9bcd 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1521,6 +1521,13 @@ static void print_mpls_stats(FILE *fp, struct rtattr *attr)
 {
 	struct rtattr *mrtb[MPLS_STATS_MAX+1];
 	struct mpls_link_stats *stats;
+	unsigned int cols[] = {
+		strlen("*X: bytes"),
+		strlen("packets"),
+		strlen("errors"),
+		strlen("dropped"),
+		strlen("noroute"),
+	};
 
 	parse_rtattr(mrtb, MPLS_STATS_MAX, RTA_DATA(attr),
 		     RTA_PAYLOAD(attr));
@@ -1528,22 +1535,35 @@ static void print_mpls_stats(FILE *fp, struct rtattr *attr)
 		return;
 
 	stats = RTA_DATA(mrtb[MPLS_STATS_LINK]);
-
 	fprintf(fp, "    mpls:\n");
-	fprintf(fp, "        RX: bytes  packets  errors  dropped  noroute\n");
+
+	size_columns(cols, ARRAY_SIZE(cols),
+		     stats->rx_bytes, stats->rx_packets, stats->rx_errors,
+		     stats->rx_dropped, stats->rx_noroute);
+	size_columns(cols, ARRAY_SIZE(cols),
+		     stats->tx_bytes, stats->tx_packets, stats->tx_errors,
+		     stats->tx_dropped, 0);
+
+	fprintf(fp, "        RX: %*s %*s %*s %*s %*s%s",
+		cols[0] - 4, "bytes", cols[1], "packets",
+		cols[2], "errors", cols[3], "dropped",
+		cols[4], "noroute", _SL_);
 	fprintf(fp, "        ");
-	print_num(fp, 10, stats->rx_bytes);
-	print_num(fp, 8, stats->rx_packets);
-	print_num(fp, 7, stats->rx_errors);
-	print_num(fp, 8, stats->rx_dropped);
-	print_num(fp, 7, stats->rx_noroute);
+	print_num(fp, cols[0], stats->rx_bytes);
+	print_num(fp, cols[1], stats->rx_packets);
+	print_num(fp, cols[2], stats->rx_errors);
+	print_num(fp, cols[3], stats->rx_dropped);
+	print_num(fp, cols[4], stats->rx_noroute);
 	fprintf(fp, "\n");
-	fprintf(fp, "        TX: bytes  packets  errors  dropped\n");
+
+	fprintf(fp, "        TX: %*s %*s %*s %*s%s",
+		cols[0] - 4, "bytes", cols[1], "packets",
+		cols[2], "errors", cols[3], "dropped", _SL_);
 	fprintf(fp, "        ");
-	print_num(fp, 10, stats->tx_bytes);
-	print_num(fp, 8, stats->tx_packets);
-	print_num(fp, 7, stats->tx_errors);
-	print_num(fp, 7, stats->tx_dropped);
+	print_num(fp, cols[0], stats->tx_bytes);
+	print_num(fp, cols[1], stats->tx_packets);
+	print_num(fp, cols[2], stats->tx_errors);
+	print_num(fp, cols[3], stats->tx_dropped);
 	fprintf(fp, "\n");
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH iproute2-next 02/10] iplink: Publish a function to format MPLS stats
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
  2022-05-09 13:59 ` [PATCH iproute2-next 01/10] iplink: Fix formatting of MPLS stats Petr Machata
@ 2022-05-09 13:59 ` Petr Machata
  2022-05-09 13:59 ` [PATCH iproute2-next 03/10] ipstats: Add a group "afstats", subgroup "mpls" Petr Machata
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-09 13:59 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

Extract from print_mpls_stats() a new function, print_mpls_link_stats(),
make it non-static and publish in the header file.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 ip/ip_common.h |  3 +++
 ip/iplink.c    | 36 +++++++++++++++++++++---------------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/ip/ip_common.h b/ip/ip_common.h
index 9eeeb387..63618f0f 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -3,6 +3,7 @@
 #define _IP_COMMON_H_
 
 #include <stdbool.h>
+#include <linux/mpls.h>
 
 #include "json_print.h"
 
@@ -202,4 +203,6 @@ void print_rta_gateway(FILE *fp, unsigned char family,
 void size_columns(unsigned int cols[], unsigned int n, ...);
 void print_stats64(FILE *fp, struct rtnl_link_stats64 *s,
 		   const struct rtattr *carrier_changes, const char *what);
+void print_mpls_link_stats(FILE *fp, const struct mpls_link_stats *stats,
+			   const char *indent);
 #endif /* _IP_COMMON_H_ */
diff --git a/ip/iplink.c b/ip/iplink.c
index b87d9bcd..c3ff8a5a 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1517,10 +1517,9 @@ static int do_set(int argc, char **argv)
 }
 #endif /* IPLINK_IOCTL_COMPAT */
 
-static void print_mpls_stats(FILE *fp, struct rtattr *attr)
+void print_mpls_link_stats(FILE *fp, const struct mpls_link_stats *stats,
+			   const char *indent)
 {
-	struct rtattr *mrtb[MPLS_STATS_MAX+1];
-	struct mpls_link_stats *stats;
 	unsigned int cols[] = {
 		strlen("*X: bytes"),
 		strlen("packets"),
@@ -1529,14 +1528,6 @@ static void print_mpls_stats(FILE *fp, struct rtattr *attr)
 		strlen("noroute"),
 	};
 
-	parse_rtattr(mrtb, MPLS_STATS_MAX, RTA_DATA(attr),
-		     RTA_PAYLOAD(attr));
-	if (!mrtb[MPLS_STATS_LINK])
-		return;
-
-	stats = RTA_DATA(mrtb[MPLS_STATS_LINK]);
-	fprintf(fp, "    mpls:\n");
-
 	size_columns(cols, ARRAY_SIZE(cols),
 		     stats->rx_bytes, stats->rx_packets, stats->rx_errors,
 		     stats->rx_dropped, stats->rx_noroute);
@@ -1544,11 +1535,11 @@ static void print_mpls_stats(FILE *fp, struct rtattr *attr)
 		     stats->tx_bytes, stats->tx_packets, stats->tx_errors,
 		     stats->tx_dropped, 0);
 
-	fprintf(fp, "        RX: %*s %*s %*s %*s %*s%s",
+	fprintf(fp, "%sRX: %*s %*s %*s %*s %*s%s", indent,
 		cols[0] - 4, "bytes", cols[1], "packets",
 		cols[2], "errors", cols[3], "dropped",
 		cols[4], "noroute", _SL_);
-	fprintf(fp, "        ");
+	fprintf(fp, "%s", indent);
 	print_num(fp, cols[0], stats->rx_bytes);
 	print_num(fp, cols[1], stats->rx_packets);
 	print_num(fp, cols[2], stats->rx_errors);
@@ -1556,10 +1547,10 @@ static void print_mpls_stats(FILE *fp, struct rtattr *attr)
 	print_num(fp, cols[4], stats->rx_noroute);
 	fprintf(fp, "\n");
 
-	fprintf(fp, "        TX: %*s %*s %*s %*s%s",
+	fprintf(fp, "%sTX: %*s %*s %*s %*s%s", indent,
 		cols[0] - 4, "bytes", cols[1], "packets",
 		cols[2], "errors", cols[3], "dropped", _SL_);
-	fprintf(fp, "        ");
+	fprintf(fp, "%s", indent);
 	print_num(fp, cols[0], stats->tx_bytes);
 	print_num(fp, cols[1], stats->tx_packets);
 	print_num(fp, cols[2], stats->tx_errors);
@@ -1567,6 +1558,21 @@ static void print_mpls_stats(FILE *fp, struct rtattr *attr)
 	fprintf(fp, "\n");
 }
 
+static void print_mpls_stats(FILE *fp, struct rtattr *attr)
+{
+	struct rtattr *mrtb[MPLS_STATS_MAX+1];
+	struct mpls_link_stats *stats;
+
+	parse_rtattr(mrtb, MPLS_STATS_MAX, RTA_DATA(attr),
+		     RTA_PAYLOAD(attr));
+	if (!mrtb[MPLS_STATS_LINK])
+		return;
+
+	stats = RTA_DATA(mrtb[MPLS_STATS_LINK]);
+	fprintf(fp, "    mpls:\n");
+	print_mpls_link_stats(fp, stats, "        ");
+}
+
 static void print_af_stats_attr(FILE *fp, int ifindex, struct rtattr *attr)
 {
 	bool if_printed = false;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH iproute2-next 03/10] ipstats: Add a group "afstats", subgroup "mpls"
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
  2022-05-09 13:59 ` [PATCH iproute2-next 01/10] iplink: Fix formatting of MPLS stats Petr Machata
  2022-05-09 13:59 ` [PATCH iproute2-next 02/10] iplink: Publish a function to format " Petr Machata
@ 2022-05-09 13:59 ` Petr Machata
  2022-05-09 13:59 ` [PATCH iproute2-next 04/10] iplink: Add JSON support to MPLS stats formatter Petr Machata
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-09 13:59 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

Add a new group, "afstats", for showing counters from the
IFLA_STATS_AF_SPEC nest, and a subgroup "mpls" for the AF_MPLS
specifically.

For example:

 # ip -n ns0-NrdgY9sx stats show dev veth01 group afstats
 3: veth01: group afstats subgroup mpls
     RX: bytes packets errors dropped noroute
             0       0      0       0       0
     TX: bytes packets errors dropped
           108       1      0       0

Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 ip/iplink.c  |  2 +-
 ip/ipstats.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/ip/iplink.c b/ip/iplink.c
index c3ff8a5a..d6662343 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1555,7 +1555,6 @@ void print_mpls_link_stats(FILE *fp, const struct mpls_link_stats *stats,
 	print_num(fp, cols[1], stats->tx_packets);
 	print_num(fp, cols[2], stats->tx_errors);
 	print_num(fp, cols[3], stats->tx_dropped);
-	fprintf(fp, "\n");
 }
 
 static void print_mpls_stats(FILE *fp, struct rtattr *attr)
@@ -1571,6 +1570,7 @@ static void print_mpls_stats(FILE *fp, struct rtattr *attr)
 	stats = RTA_DATA(mrtb[MPLS_STATS_LINK]);
 	fprintf(fp, "    mpls:\n");
 	print_mpls_link_stats(fp, stats, "        ");
+	fprintf(fp, "\n");
 }
 
 static void print_af_stats_attr(FILE *fp, int ifindex, struct rtattr *attr)
diff --git a/ip/ipstats.c b/ip/ipstats.c
index 5b9689f4..5b9333e3 100644
--- a/ip/ipstats.c
+++ b/ip/ipstats.c
@@ -589,9 +589,63 @@ static const struct ipstats_stat_desc ipstats_stat_desc_toplev_link = {
 	.show = &ipstats_stat_desc_show_link,
 };
 
+static const struct ipstats_stat_desc ipstats_stat_desc_afstats_group;
+
+static void
+ipstats_stat_desc_pack_afstats(struct ipstats_stat_dump_filters *filters,
+			       const struct ipstats_stat_desc *desc)
+{
+	ipstats_stat_desc_enable_bit(filters, IFLA_STATS_AF_SPEC, 0);
+}
+
+static int
+ipstats_stat_desc_show_afstats_mpls(struct ipstats_stat_show_attrs *attrs,
+				    const struct ipstats_stat_desc *desc)
+{
+	struct rtattr *mrtb[MPLS_STATS_MAX+1];
+	struct mpls_link_stats stats;
+	const struct rtattr *at;
+	int err;
+
+	at = ipstats_stat_show_get_attr(attrs, IFLA_STATS_AF_SPEC,
+					AF_MPLS, &err);
+	if (at == NULL)
+		return err;
+
+	parse_rtattr_nested(mrtb, MPLS_STATS_MAX, at);
+	if (mrtb[MPLS_STATS_LINK] == NULL)
+		return -ENOENT;
+
+	IPSTATS_RTA_PAYLOAD(stats, mrtb[MPLS_STATS_LINK]);
+
+	print_nl();
+	open_json_object("mpls_stats");
+	print_mpls_link_stats(stdout, &stats, "    ");
+	close_json_object();
+	return 0;
+}
+
+static const struct ipstats_stat_desc ipstats_stat_desc_afstats_mpls = {
+	.name = "mpls",
+	.kind = IPSTATS_STAT_DESC_KIND_LEAF,
+	.pack = &ipstats_stat_desc_pack_afstats,
+	.show = &ipstats_stat_desc_show_afstats_mpls,
+};
+
+static const struct ipstats_stat_desc *ipstats_stat_desc_afstats_subs[] = {
+	&ipstats_stat_desc_afstats_mpls,
+};
+
+static const struct ipstats_stat_desc ipstats_stat_desc_afstats_group = {
+	.name = "afstats",
+	.kind = IPSTATS_STAT_DESC_KIND_GROUP,
+	.subs = ipstats_stat_desc_afstats_subs,
+	.nsubs = ARRAY_SIZE(ipstats_stat_desc_afstats_subs),
+};
 static const struct ipstats_stat_desc *ipstats_stat_desc_toplev_subs[] = {
 	&ipstats_stat_desc_toplev_link,
 	&ipstats_stat_desc_offload_group,
+	&ipstats_stat_desc_afstats_group,
 };
 
 static const struct ipstats_stat_desc ipstats_stat_desc_toplev_group = {
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH iproute2-next 04/10] iplink: Add JSON support to MPLS stats formatter
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
                   ` (2 preceding siblings ...)
  2022-05-09 13:59 ` [PATCH iproute2-next 03/10] ipstats: Add a group "afstats", subgroup "mpls" Petr Machata
@ 2022-05-09 13:59 ` Petr Machata
  2022-05-09 13:59 ` [PATCH iproute2-next 05/10] ipstats: Add a third level of stats hierarchy, a "suite" Petr Machata
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-09 13:59 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

MPLS stats currently do not support dumping in JSON format. Recognize when
JSON is requested and dump in an obvious manner:

 # ip -n ns0-2G8Ozd9z -j stats show dev veth01 group afstats | jq
 [
   {
     "ifindex": 3,
     "ifname": "veth01",
     "group": "afstats",
     "subgroup": "mpls",
     "mpls_stats": {
       "rx": {
         "bytes": 0,
         "packets": 0,
         "errors": 0,
         "dropped": 0,
         "noroute": 0
       },
       "tx": {
         "bytes": 216,
         "packets": 2,
         "errors": 0,
         "dropped": 0
       }
     }
   }
 ]

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 ip/iplink.c | 69 ++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 44 insertions(+), 25 deletions(-)

diff --git a/ip/iplink.c b/ip/iplink.c
index d6662343..fbdf542a 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1528,33 +1528,52 @@ void print_mpls_link_stats(FILE *fp, const struct mpls_link_stats *stats,
 		strlen("noroute"),
 	};
 
-	size_columns(cols, ARRAY_SIZE(cols),
-		     stats->rx_bytes, stats->rx_packets, stats->rx_errors,
-		     stats->rx_dropped, stats->rx_noroute);
-	size_columns(cols, ARRAY_SIZE(cols),
-		     stats->tx_bytes, stats->tx_packets, stats->tx_errors,
-		     stats->tx_dropped, 0);
+	if (is_json_context()) {
+		/* RX stats */
+		open_json_object("rx");
+		print_u64(PRINT_JSON, "bytes", NULL, stats->rx_bytes);
+		print_u64(PRINT_JSON, "packets", NULL, stats->rx_packets);
+		print_u64(PRINT_JSON, "errors", NULL, stats->rx_errors);
+		print_u64(PRINT_JSON, "dropped", NULL, stats->rx_dropped);
+		print_u64(PRINT_JSON, "noroute", NULL, stats->rx_noroute);
+		close_json_object();
 
-	fprintf(fp, "%sRX: %*s %*s %*s %*s %*s%s", indent,
-		cols[0] - 4, "bytes", cols[1], "packets",
-		cols[2], "errors", cols[3], "dropped",
-		cols[4], "noroute", _SL_);
-	fprintf(fp, "%s", indent);
-	print_num(fp, cols[0], stats->rx_bytes);
-	print_num(fp, cols[1], stats->rx_packets);
-	print_num(fp, cols[2], stats->rx_errors);
-	print_num(fp, cols[3], stats->rx_dropped);
-	print_num(fp, cols[4], stats->rx_noroute);
-	fprintf(fp, "\n");
+		/* TX stats */
+		open_json_object("tx");
+		print_u64(PRINT_JSON, "bytes", NULL, stats->tx_bytes);
+		print_u64(PRINT_JSON, "packets", NULL, stats->tx_packets);
+		print_u64(PRINT_JSON, "errors", NULL, stats->tx_errors);
+		print_u64(PRINT_JSON, "dropped", NULL, stats->tx_dropped);
+		close_json_object();
+	} else {
+		size_columns(cols, ARRAY_SIZE(cols), stats->rx_bytes,
+			     stats->rx_packets, stats->rx_errors,
+			     stats->rx_dropped, stats->rx_noroute);
+		size_columns(cols, ARRAY_SIZE(cols), stats->tx_bytes,
+			     stats->tx_packets, stats->tx_errors,
+			     stats->tx_dropped, 0);
 
-	fprintf(fp, "%sTX: %*s %*s %*s %*s%s", indent,
-		cols[0] - 4, "bytes", cols[1], "packets",
-		cols[2], "errors", cols[3], "dropped", _SL_);
-	fprintf(fp, "%s", indent);
-	print_num(fp, cols[0], stats->tx_bytes);
-	print_num(fp, cols[1], stats->tx_packets);
-	print_num(fp, cols[2], stats->tx_errors);
-	print_num(fp, cols[3], stats->tx_dropped);
+		fprintf(fp, "%sRX: %*s %*s %*s %*s %*s%s", indent,
+			cols[0] - 4, "bytes", cols[1], "packets",
+			cols[2], "errors", cols[3], "dropped",
+			cols[4], "noroute", _SL_);
+		fprintf(fp, "%s", indent);
+		print_num(fp, cols[0], stats->rx_bytes);
+		print_num(fp, cols[1], stats->rx_packets);
+		print_num(fp, cols[2], stats->rx_errors);
+		print_num(fp, cols[3], stats->rx_dropped);
+		print_num(fp, cols[4], stats->rx_noroute);
+		fprintf(fp, "\n");
+
+		fprintf(fp, "%sTX: %*s %*s %*s %*s%s", indent,
+			cols[0] - 4, "bytes", cols[1], "packets",
+			cols[2], "errors", cols[3], "dropped", _SL_);
+		fprintf(fp, "%s", indent);
+		print_num(fp, cols[0], stats->tx_bytes);
+		print_num(fp, cols[1], stats->tx_packets);
+		print_num(fp, cols[2], stats->tx_errors);
+		print_num(fp, cols[3], stats->tx_dropped);
+	}
 }
 
 static void print_mpls_stats(FILE *fp, struct rtattr *attr)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH iproute2-next 05/10] ipstats: Add a third level of stats hierarchy, a "suite"
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
                   ` (3 preceding siblings ...)
  2022-05-09 13:59 ` [PATCH iproute2-next 04/10] iplink: Add JSON support to MPLS stats formatter Petr Machata
@ 2022-05-09 13:59 ` Petr Machata
  2022-05-09 13:59 ` [PATCH iproute2-next 06/10] ipstats: Add groups "xstats", "xstats_slave" Petr Machata
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-09 13:59 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

To show statistics nested under IFLA_STATS_LINK_XSTATS_SLAVE or
IFLA_STATS_LINK_XSTATS, one would use "group" to select the top-level
attribute, then "subgroup" to select the link type, which is itself a nest,
and then would lack a way to denote which attribute to select out of the
link-type nest.

To that end, add the selector level "suite", which is filtered in the
userspace.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 ip/ipstats.c        | 9 ++++++++-
 man/man8/ip-stats.8 | 3 ++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/ip/ipstats.c b/ip/ipstats.c
index 5b9333e3..0e7f2b3c 100644
--- a/ip/ipstats.c
+++ b/ip/ipstats.c
@@ -34,6 +34,7 @@ struct ipstats_stat_show_attrs {
 static const char *const ipstats_levels[] = {
 	"group",
 	"subgroup",
+	"suite",
 };
 
 enum {
@@ -1024,7 +1025,7 @@ static int do_help(void)
 
 	fprintf(stderr,
 		"Usage: ip stats help\n"
-		"       ip stats show [ dev DEV ] [ group GROUP [ subgroup SUBGROUP ] ... ] ...\n"
+		"       ip stats show [ dev DEV ] [ group GROUP [ subgroup SUBGROUP [ suite SUITE ] ... ] ... ] ...\n"
 		"       ip stats set dev DEV l3_stats { on | off }\n"
 		);
 
@@ -1048,6 +1049,8 @@ static int do_help(void)
 			continue;
 
 		for (j = 0; j < desc->nsubs; j++) {
+			size_t k;
+
 			if (j == 0)
 				fprintf(stderr, "%s SUBGROUP := {", desc->name);
 			else
@@ -1057,6 +1060,10 @@ static int do_help(void)
 
 			if (desc->subs[j]->kind != IPSTATS_STAT_DESC_KIND_GROUP)
 				continue;
+
+			for (k = 0; k < desc->subs[j]->nsubs; k++)
+				fprintf(stderr, " [ suite %s ]",
+					desc->subs[j]->subs[k]->name);
 		}
 		if (opened)
 			fprintf(stderr, " }\n");
diff --git a/man/man8/ip-stats.8 b/man/man8/ip-stats.8
index 7eaaf122..a82fe9f7 100644
--- a/man/man8/ip-stats.8
+++ b/man/man8/ip-stats.8
@@ -19,7 +19,8 @@ ip-stats \- manage and show interface statistics
 .RB "[ " group
 .IR GROUP " [ "
 .BI subgroup " SUBGROUP"
-.R " ] ... ] ..."
+.RB " [ " suite
+.IR " SUITE" " ] ... ] ... ] ..."
 
 .ti -8
 .BR "ip stats set"
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH iproute2-next 06/10] ipstats: Add groups "xstats", "xstats_slave"
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
                   ` (4 preceding siblings ...)
  2022-05-09 13:59 ` [PATCH iproute2-next 05/10] ipstats: Add a third level of stats hierarchy, a "suite" Petr Machata
@ 2022-05-09 13:59 ` Petr Machata
  2022-05-09 14:00 ` [PATCH iproute2-next 07/10] iplink_bridge: Split bridge_print_stats_attr() Petr Machata
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-09 13:59 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

The RTM_GETSTATS response attributes IFLA_STATS_LINK_XSTATS and
IFLA_STATS_LINK_XSTATS_SLAVE are used to carry statistics related to,
respectively, netdevices of a certain type, and netdevices enslaved to
netdevices of a certain type. Inside the nest is then link-type specific
attribute (e.g. LINK_XSTATS_TYPE_BRIDGE), and inside that nest further
attributes for individual type-specific statistical suites.

Under the "ip stats" model, that corresponds to groups "xstats" and
"xstats_slave", link-type specific subgroup, e.g. "bridge", and one or more
link-type specific suites, such as "stp".

Link-type specific stats are currently supported through struct link_util
and in particular the callbacks parse_ifla_xstats and print_ifla_xstats.

The role of parse_ifla_xstats is to establish which statistical suite to
display, and on which device. "ip stats" has framework for both of these
tasks, which obviates the need for custom parsing. Therefore the module
should instead provide a subgroup descriptor, which "ip stats" will then
use as any other.

The second link_util callback, print_ifla_xstats, is for response
dissection. In "ip stats" model, this belongs to leaf descriptors.

Eventually, the link-specific leaf descriptors will be similar to each
other: either master or slave top-level nest needs to be parsed, and
link-type attribute underneath that, and suite attribute underneath that.

To support this commonality, add struct ipstats_stat_desc_xstats to
describe the xstats suites. Further, expose ipstats_stat_desc_pack_xstats()
and ipstats_stat_desc_show_xstats(), which can be used at leaf descriptors
and do the appropriate thing according to the configuration in
ipstats_stat_desc_xstats.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 ip/ip_common.h | 14 ++++++++++++
 ip/ipstats.c   | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)

diff --git a/ip/ip_common.h b/ip/ip_common.h
index 63618f0f..8b7ec645 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -186,6 +186,20 @@ struct ipstats_stat_desc {
 	};
 };
 
+struct ipstats_stat_desc_xstats {
+	const struct ipstats_stat_desc desc;
+	int xstats_at;
+	int link_type_at;
+	int inner_max;
+	int inner_at;
+	void (*show_cb)(const struct rtattr *at);
+};
+
+void ipstats_stat_desc_pack_xstats(struct ipstats_stat_dump_filters *filters,
+				   const struct ipstats_stat_desc *desc);
+int ipstats_stat_desc_show_xstats(struct ipstats_stat_show_attrs *attrs,
+				  const struct ipstats_stat_desc *desc);
+
 #ifndef	INFINITY_LIFE_TIME
 #define     INFINITY_LIFE_TIME      0xFFFFFFFFU
 #endif
diff --git a/ip/ipstats.c b/ip/ipstats.c
index 0e7f2b3c..0691a3f0 100644
--- a/ip/ipstats.c
+++ b/ip/ipstats.c
@@ -2,6 +2,7 @@
 #include <assert.h>
 #include <errno.h>
 
+#include "list.h"
 #include "utils.h"
 #include "ip_common.h"
 
@@ -567,6 +568,62 @@ static const struct ipstats_stat_desc ipstats_stat_desc_offload_group = {
 	.nsubs = ARRAY_SIZE(ipstats_stat_desc_offload_subs),
 };
 
+void ipstats_stat_desc_pack_xstats(struct ipstats_stat_dump_filters *filters,
+				   const struct ipstats_stat_desc *desc)
+{
+	struct ipstats_stat_desc_xstats *xdesc;
+
+	xdesc = container_of(desc, struct ipstats_stat_desc_xstats, desc);
+	ipstats_stat_desc_enable_bit(filters, xdesc->xstats_at, 0);
+}
+
+int ipstats_stat_desc_show_xstats(struct ipstats_stat_show_attrs *attrs,
+				  const struct ipstats_stat_desc *desc)
+{
+	struct ipstats_stat_desc_xstats *xdesc;
+	const struct rtattr *at;
+	struct rtattr **tb;
+	int err;
+
+	xdesc = container_of(desc, struct ipstats_stat_desc_xstats, desc);
+	at = ipstats_stat_show_get_attr(attrs,
+					xdesc->xstats_at,
+					xdesc->link_type_at, &err);
+	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]);
+	}
+	return 0;
+}
+
+static const struct ipstats_stat_desc *ipstats_stat_desc_xstats_subs[] = {
+};
+
+static const struct ipstats_stat_desc ipstats_stat_desc_xstats_group = {
+	.name = "xstats",
+	.kind = IPSTATS_STAT_DESC_KIND_GROUP,
+	.subs = ipstats_stat_desc_xstats_subs,
+	.nsubs = ARRAY_SIZE(ipstats_stat_desc_xstats_subs),
+};
+
+static const struct ipstats_stat_desc *ipstats_stat_desc_xstats_slave_subs[] = {
+};
+
+static const struct ipstats_stat_desc ipstats_stat_desc_xstats_slave_group = {
+	.name = "xstats_slave",
+	.kind = IPSTATS_STAT_DESC_KIND_GROUP,
+	.subs = ipstats_stat_desc_xstats_slave_subs,
+	.nsubs = ARRAY_SIZE(ipstats_stat_desc_xstats_slave_subs),
+};
+
 static void
 ipstats_stat_desc_pack_link(struct ipstats_stat_dump_filters *filters,
 			    const struct ipstats_stat_desc *desc)
@@ -645,6 +702,8 @@ static const struct ipstats_stat_desc ipstats_stat_desc_afstats_group = {
 };
 static const struct ipstats_stat_desc *ipstats_stat_desc_toplev_subs[] = {
 	&ipstats_stat_desc_toplev_link,
+	&ipstats_stat_desc_xstats_group,
+	&ipstats_stat_desc_xstats_slave_group,
 	&ipstats_stat_desc_offload_group,
 	&ipstats_stat_desc_afstats_group,
 };
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH iproute2-next 07/10] iplink_bridge: Split bridge_print_stats_attr()
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
                   ` (5 preceding siblings ...)
  2022-05-09 13:59 ` [PATCH iproute2-next 06/10] ipstats: Add groups "xstats", "xstats_slave" Petr Machata
@ 2022-05-09 14:00 ` Petr Machata
  2022-05-09 14:00 ` [PATCH iproute2-next 08/10] ipstats: Expose bridge stats in ipstats Petr Machata
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-09 14:00 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

Extract from bridge_print_stats_attr() two helpers, one for dumping the
multicast attribute, one for dumping the STP attribute.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 ip/iplink_bridge.c | 254 ++++++++++++++++++++++++---------------------
 1 file changed, 133 insertions(+), 121 deletions(-)

diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index c2e63f6e..493be6fe 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -714,11 +714,140 @@ static void bridge_print_xstats_help(struct link_util *lu, FILE *f)
 	fprintf(f, "Usage: ... %s [ igmp ] [ dev DEVICE ]\n", lu->id);
 }
 
+static void bridge_print_stats_mcast(const struct rtattr *attr)
+{
+	struct br_mcast_stats *mstats;
+
+	mstats = RTA_DATA(attr);
+	open_json_object("multicast");
+	open_json_object("igmp_queries");
+	print_string(PRINT_FP, NULL,
+		     "%-16s    IGMP queries:\n", "");
+	print_string(PRINT_FP, NULL, "%-16s      ", "");
+	print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
+		  mstats->igmp_v1queries[BR_MCAST_DIR_RX]);
+	print_u64(PRINT_ANY, "rx_v2", "v2 %llu ",
+		  mstats->igmp_v2queries[BR_MCAST_DIR_RX]);
+	print_u64(PRINT_ANY, "rx_v3", "v3 %llu\n",
+		  mstats->igmp_v3queries[BR_MCAST_DIR_RX]);
+	print_string(PRINT_FP, NULL, "%-16s      ", "");
+	print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
+		  mstats->igmp_v1queries[BR_MCAST_DIR_TX]);
+	print_u64(PRINT_ANY, "tx_v2", "v2 %llu ",
+		  mstats->igmp_v2queries[BR_MCAST_DIR_TX]);
+	print_u64(PRINT_ANY, "tx_v3", "v3 %llu\n",
+		  mstats->igmp_v3queries[BR_MCAST_DIR_TX]);
+	close_json_object();
+
+	open_json_object("igmp_reports");
+	print_string(PRINT_FP, NULL,
+		     "%-16s    IGMP reports:\n", "");
+	print_string(PRINT_FP, NULL, "%-16s      ", "");
+	print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
+		  mstats->igmp_v1reports[BR_MCAST_DIR_RX]);
+	print_u64(PRINT_ANY, "rx_v2", "v2 %llu ",
+		  mstats->igmp_v2reports[BR_MCAST_DIR_RX]);
+	print_u64(PRINT_ANY, "rx_v3", "v3 %llu\n",
+		  mstats->igmp_v3reports[BR_MCAST_DIR_RX]);
+	print_string(PRINT_FP, NULL, "%-16s      ", "");
+	print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
+		  mstats->igmp_v1reports[BR_MCAST_DIR_TX]);
+	print_u64(PRINT_ANY, "tx_v2", "v2 %llu ",
+		  mstats->igmp_v2reports[BR_MCAST_DIR_TX]);
+	print_u64(PRINT_ANY, "tx_v3", "v3 %llu\n",
+		  mstats->igmp_v3reports[BR_MCAST_DIR_TX]);
+	close_json_object();
+
+	open_json_object("igmp_leaves");
+	print_string(PRINT_FP, NULL,
+		     "%-16s    IGMP leaves: ", "");
+	print_u64(PRINT_ANY, "rx", "RX: %llu ",
+		  mstats->igmp_leaves[BR_MCAST_DIR_RX]);
+	print_u64(PRINT_ANY, "tx", "TX: %llu\n",
+		  mstats->igmp_leaves[BR_MCAST_DIR_TX]);
+	close_json_object();
+
+	print_string(PRINT_FP, NULL,
+		     "%-16s    IGMP parse errors: ", "");
+	print_u64(PRINT_ANY, "igmp_parse_errors", "%llu\n",
+		  mstats->igmp_parse_errors);
+
+	open_json_object("mld_queries");
+	print_string(PRINT_FP, NULL,
+		     "%-16s    MLD queries:\n", "");
+	print_string(PRINT_FP, NULL, "%-16s      ", "");
+	print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
+		  mstats->mld_v1queries[BR_MCAST_DIR_RX]);
+	print_u64(PRINT_ANY, "rx_v2", "v2 %llu\n",
+		  mstats->mld_v2queries[BR_MCAST_DIR_RX]);
+	print_string(PRINT_FP, NULL, "%-16s      ", "");
+	print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
+		  mstats->mld_v1queries[BR_MCAST_DIR_TX]);
+	print_u64(PRINT_ANY, "tx_v2", "v2 %llu\n",
+		  mstats->mld_v2queries[BR_MCAST_DIR_TX]);
+	close_json_object();
+
+	open_json_object("mld_reports");
+	print_string(PRINT_FP, NULL,
+		     "%-16s    MLD reports:\n", "");
+	print_string(PRINT_FP, NULL, "%-16s      ", "");
+	print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
+		  mstats->mld_v1reports[BR_MCAST_DIR_RX]);
+	print_u64(PRINT_ANY, "rx_v2", "v2 %llu\n",
+		  mstats->mld_v2reports[BR_MCAST_DIR_RX]);
+	print_string(PRINT_FP, NULL, "%-16s      ", "");
+	print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
+		  mstats->mld_v1reports[BR_MCAST_DIR_TX]);
+	print_u64(PRINT_ANY, "tx_v2", "v2 %llu\n",
+		  mstats->mld_v2reports[BR_MCAST_DIR_TX]);
+	close_json_object();
+
+	open_json_object("mld_leaves");
+	print_string(PRINT_FP, NULL,
+		     "%-16s    MLD leaves: ", "");
+	print_u64(PRINT_ANY, "rx", "RX: %llu ",
+		  mstats->mld_leaves[BR_MCAST_DIR_RX]);
+	print_u64(PRINT_ANY, "tx", "TX: %llu\n",
+		  mstats->mld_leaves[BR_MCAST_DIR_TX]);
+	close_json_object();
+
+	print_string(PRINT_FP, NULL,
+		     "%-16s    MLD parse errors: ", "");
+	print_u64(PRINT_ANY, "mld_parse_errors", "%llu\n",
+		  mstats->mld_parse_errors);
+	close_json_object();
+}
+
+static void bridge_print_stats_stp(const struct rtattr *attr)
+{
+	struct bridge_stp_xstats *sstats;
+
+	sstats = RTA_DATA(attr);
+	open_json_object("stp");
+	print_string(PRINT_FP, NULL,
+		     "%-16s    STP BPDU:  ", "");
+	print_u64(PRINT_ANY, "rx_bpdu", "RX: %llu ",
+		  sstats->rx_bpdu);
+	print_u64(PRINT_ANY, "tx_bpdu", "TX: %llu\n",
+		  sstats->tx_bpdu);
+	print_string(PRINT_FP, NULL,
+		     "%-16s    STP TCN:   ", "");
+	print_u64(PRINT_ANY, "rx_tcn", "RX: %llu ",
+		  sstats->rx_tcn);
+	print_u64(PRINT_ANY, "tx_tcn", "TX: %llu\n",
+		  sstats->tx_tcn);
+	print_string(PRINT_FP, NULL,
+		     "%-16s    STP Transitions: ", "");
+	print_u64(PRINT_ANY, "transition_blk", "Blocked: %llu ",
+		  sstats->transition_blk);
+	print_u64(PRINT_ANY, "transition_fwd", "Forwarding: %llu\n",
+		  sstats->transition_fwd);
+	close_json_object();
+}
+
 static void bridge_print_stats_attr(struct rtattr *attr, int ifindex)
 {
 	struct rtattr *brtb[LINK_XSTATS_TYPE_MAX+1];
-	struct bridge_stp_xstats *sstats;
-	struct br_mcast_stats *mstats;
 	struct rtattr *i, *list;
 	const char *ifname = "";
 	int rem;
@@ -738,127 +867,10 @@ static void bridge_print_stats_attr(struct rtattr *attr, int ifindex)
 			continue;
 		switch (i->rta_type) {
 		case BRIDGE_XSTATS_MCAST:
-			mstats = RTA_DATA(i);
-			open_json_object("multicast");
-			open_json_object("igmp_queries");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    IGMP queries:\n", "");
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
-				  mstats->igmp_v1queries[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v2", "v2 %llu ",
-				  mstats->igmp_v2queries[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v3", "v3 %llu\n",
-				  mstats->igmp_v3queries[BR_MCAST_DIR_RX]);
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
-				  mstats->igmp_v1queries[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v2", "v2 %llu ",
-				  mstats->igmp_v2queries[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v3", "v3 %llu\n",
-				  mstats->igmp_v3queries[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			open_json_object("igmp_reports");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    IGMP reports:\n", "");
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
-				  mstats->igmp_v1reports[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v2", "v2 %llu ",
-				  mstats->igmp_v2reports[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v3", "v3 %llu\n",
-				  mstats->igmp_v3reports[BR_MCAST_DIR_RX]);
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
-				  mstats->igmp_v1reports[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v2", "v2 %llu ",
-				  mstats->igmp_v2reports[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v3", "v3 %llu\n",
-				  mstats->igmp_v3reports[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			open_json_object("igmp_leaves");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    IGMP leaves: ", "");
-			print_u64(PRINT_ANY, "rx", "RX: %llu ",
-				  mstats->igmp_leaves[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "tx", "TX: %llu\n",
-				  mstats->igmp_leaves[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			print_string(PRINT_FP, NULL,
-				     "%-16s    IGMP parse errors: ", "");
-			print_u64(PRINT_ANY, "igmp_parse_errors", "%llu\n",
-				  mstats->igmp_parse_errors);
-
-			open_json_object("mld_queries");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    MLD queries:\n", "");
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
-				  mstats->mld_v1queries[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v2", "v2 %llu\n",
-				  mstats->mld_v2queries[BR_MCAST_DIR_RX]);
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
-				  mstats->mld_v1queries[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v2", "v2 %llu\n",
-				  mstats->mld_v2queries[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			open_json_object("mld_reports");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    MLD reports:\n", "");
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
-				  mstats->mld_v1reports[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v2", "v2 %llu\n",
-				  mstats->mld_v2reports[BR_MCAST_DIR_RX]);
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
-				  mstats->mld_v1reports[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v2", "v2 %llu\n",
-				  mstats->mld_v2reports[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			open_json_object("mld_leaves");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    MLD leaves: ", "");
-			print_u64(PRINT_ANY, "rx", "RX: %llu ",
-				  mstats->mld_leaves[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "tx", "TX: %llu\n",
-				  mstats->mld_leaves[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			print_string(PRINT_FP, NULL,
-				     "%-16s    MLD parse errors: ", "");
-			print_u64(PRINT_ANY, "mld_parse_errors", "%llu\n",
-				  mstats->mld_parse_errors);
-			close_json_object();
+			bridge_print_stats_mcast(i);
 			break;
 		case BRIDGE_XSTATS_STP:
-			sstats = RTA_DATA(i);
-			open_json_object("stp");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    STP BPDU:  ", "");
-			print_u64(PRINT_ANY, "rx_bpdu", "RX: %llu ",
-				  sstats->rx_bpdu);
-			print_u64(PRINT_ANY, "tx_bpdu", "TX: %llu\n",
-				  sstats->tx_bpdu);
-			print_string(PRINT_FP, NULL,
-				     "%-16s    STP TCN:   ", "");
-			print_u64(PRINT_ANY, "rx_tcn", "RX: %llu ",
-				  sstats->rx_tcn);
-			print_u64(PRINT_ANY, "tx_tcn", "TX: %llu\n",
-				  sstats->tx_tcn);
-			print_string(PRINT_FP, NULL,
-				     "%-16s    STP Transitions: ", "");
-			print_u64(PRINT_ANY, "transition_blk", "Blocked: %llu ",
-				  sstats->transition_blk);
-			print_u64(PRINT_ANY, "transition_fwd", "Forwarding: %llu\n",
-				  sstats->transition_fwd);
-			close_json_object();
+			bridge_print_stats_stp(i);
 			break;
 		}
 	}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH iproute2-next 08/10] ipstats: Expose bridge stats in ipstats
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
                   ` (6 preceding siblings ...)
  2022-05-09 14:00 ` [PATCH iproute2-next 07/10] iplink_bridge: Split bridge_print_stats_attr() Petr Machata
@ 2022-05-09 14:00 ` Petr Machata
  2022-05-09 14:00 ` [PATCH iproute2-next 09/10] ipstats: Expose bond " Petr Machata
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-09 14:00 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

Bridge supports two suites, STP and IGMP, carried by attributes
BRIDGE_XSTATS_STP and BRIDGE_XSTATS_MCAST. Expose them as suites "stp" and
"mcast" (to correspond to the attribute name).

For example:

 # ip stats show dev swp1 group xstats_slave subgroup bridge
 56: swp1: group xstats_slave subgroup bridge suite mcast
                     IGMP queries:
                       RX: v1 0 v2 0 v3 0
                       TX: v1 0 v2 0 v3 0
                     IGMP reports:
                       RX: v1 0 v2 0 v3 0
                       TX: v1 0 v2 0 v3 0
                     IGMP leaves: RX: 0 TX: 0
                     IGMP parse errors: 0
                     MLD queries:
                       RX: v1 0 v2 0
                       TX: v1 0 v2 0
                     MLD reports:
                       RX: v1 0 v2 0
                       TX: v1 0 v2 0
                     MLD leaves: RX: 0 TX: 0
                     MLD parse errors: 0

 56: swp1: group xstats_slave subgroup bridge suite stp
                     STP BPDU:  RX: 0 TX: 0
                     STP TCN:   RX: 0 TX: 0
                     STP Transitions: Blocked: 1 Forwarding: 0

 # ip -j stats show dev swp1 group xstats_slave subgroup bridge | jq
 [
   {
     "ifindex": 56,
     "ifname": "swp1",
     "group": "xstats_slave",
     "subgroup": "bridge",
     "suite": "mcast",
     "multicast": {
       "igmp_queries": {
         "rx_v1": 0,
         "rx_v2": 0,
         "rx_v3": 0,
         "tx_v1": 0,
         "tx_v2": 0,
         "tx_v3": 0
       },
       "igmp_reports": {
         "rx_v1": 0,
         "rx_v2": 0,
         "rx_v3": 0,
         "tx_v1": 0,
         "tx_v2": 0,
         "tx_v3": 0
       },
       "igmp_leaves": {
         "rx": 0,
         "tx": 0
       },
       "igmp_parse_errors": 0,
       "mld_queries": {
         "rx_v1": 0,
         "rx_v2": 0,
         "tx_v1": 0,
         "tx_v2": 0
       },
       "mld_reports": {
         "rx_v1": 0,
         "rx_v2": 0,
         "tx_v1": 0,
         "tx_v2": 0
       },
       "mld_leaves": {
         "rx": 0,
         "tx": 0
       },
       "mld_parse_errors": 0
     }
   },
   {
     "ifindex": 56,
     "ifname": "swp1",
     "group": "xstats_slave",
     "subgroup": "bridge",
     "suite": "stp",
     "stp": {
       "rx_bpdu": 0,
       "tx_bpdu": 0,
       "rx_tcn": 0,
       "tx_tcn": 0,
       "transition_blk": 1,
       "transition_fwd": 0
     }
   }
 ]

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 ip/ip_common.h     |  2 ++
 ip/iplink_bridge.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++
 ip/ipstats.c       |  2 ++
 3 files changed, 84 insertions(+)

diff --git a/ip/ip_common.h b/ip/ip_common.h
index 8b7ec645..c58f2090 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -142,6 +142,8 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type);
 void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len);
 int bridge_parse_xstats(struct link_util *lu, int argc, char **argv);
 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;
 
 int bond_parse_xstats(struct link_util *lu, int argc, char **argv);
 int bond_print_xstats(struct nlmsghdr *n, void *arg);
diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index 493be6fe..3feb6109 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -936,3 +936,83 @@ struct link_util bridge_link_util = {
 	.parse_ifla_xstats = bridge_parse_xstats,
 	.print_ifla_xstats = bridge_print_xstats,
 };
+
+static const struct ipstats_stat_desc ipstats_stat_desc_bridge_tmpl_stp = {
+	.name = "stp",
+	.kind = IPSTATS_STAT_DESC_KIND_LEAF,
+	.show = &ipstats_stat_desc_show_xstats,
+	.pack = &ipstats_stat_desc_pack_xstats,
+};
+
+static const struct ipstats_stat_desc ipstats_stat_desc_bridge_tmpl_mcast = {
+	.name = "mcast",
+	.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_bridge_stp = {
+	.desc = ipstats_stat_desc_bridge_tmpl_stp,
+	.xstats_at = IFLA_STATS_LINK_XSTATS,
+	.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
+	.inner_max = BRIDGE_XSTATS_MAX,
+	.inner_at = BRIDGE_XSTATS_STP,
+	.show_cb = &bridge_print_stats_stp,
+};
+
+static const struct ipstats_stat_desc_xstats
+ipstats_stat_desc_xstats_bridge_mcast = {
+	.desc = ipstats_stat_desc_bridge_tmpl_mcast,
+	.xstats_at = IFLA_STATS_LINK_XSTATS,
+	.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
+	.inner_max = BRIDGE_XSTATS_MAX,
+	.inner_at = BRIDGE_XSTATS_MCAST,
+	.show_cb = &bridge_print_stats_mcast,
+};
+
+static const struct ipstats_stat_desc *
+ipstats_stat_desc_xstats_bridge_subs[] = {
+	&ipstats_stat_desc_xstats_bridge_stp.desc,
+	&ipstats_stat_desc_xstats_bridge_mcast.desc,
+};
+
+const struct ipstats_stat_desc ipstats_stat_desc_xstats_bridge_group = {
+	.name = "bridge",
+	.kind = IPSTATS_STAT_DESC_KIND_GROUP,
+	.subs = ipstats_stat_desc_xstats_bridge_subs,
+	.nsubs = ARRAY_SIZE(ipstats_stat_desc_xstats_bridge_subs),
+};
+
+static const struct ipstats_stat_desc_xstats
+ipstats_stat_desc_xstats_slave_bridge_stp = {
+	.desc = ipstats_stat_desc_bridge_tmpl_stp,
+	.xstats_at = IFLA_STATS_LINK_XSTATS_SLAVE,
+	.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
+	.inner_max = BRIDGE_XSTATS_MAX,
+	.inner_at = BRIDGE_XSTATS_STP,
+	.show_cb = &bridge_print_stats_stp,
+};
+
+static const struct ipstats_stat_desc_xstats
+ipstats_stat_desc_xstats_slave_bridge_mcast = {
+	.desc = ipstats_stat_desc_bridge_tmpl_mcast,
+	.xstats_at = IFLA_STATS_LINK_XSTATS_SLAVE,
+	.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
+	.inner_max = BRIDGE_XSTATS_MAX,
+	.inner_at = BRIDGE_XSTATS_MCAST,
+	.show_cb = &bridge_print_stats_mcast,
+};
+
+static const struct ipstats_stat_desc *
+ipstats_stat_desc_xstats_slave_bridge_subs[] = {
+	&ipstats_stat_desc_xstats_slave_bridge_stp.desc,
+	&ipstats_stat_desc_xstats_slave_bridge_mcast.desc,
+};
+
+const struct ipstats_stat_desc ipstats_stat_desc_xstats_slave_bridge_group = {
+	.name = "bridge",
+	.kind = IPSTATS_STAT_DESC_KIND_GROUP,
+	.subs = ipstats_stat_desc_xstats_slave_bridge_subs,
+	.nsubs = ARRAY_SIZE(ipstats_stat_desc_xstats_slave_bridge_subs),
+};
diff --git a/ip/ipstats.c b/ip/ipstats.c
index 0691a3f0..1051976d 100644
--- a/ip/ipstats.c
+++ b/ip/ipstats.c
@@ -605,6 +605,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,
 };
 
 static const struct ipstats_stat_desc ipstats_stat_desc_xstats_group = {
@@ -615,6 +616,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,
 };
 
 static const struct ipstats_stat_desc ipstats_stat_desc_xstats_slave_group = {
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH iproute2-next 09/10] ipstats: Expose bond stats in ipstats
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
                   ` (7 preceding siblings ...)
  2022-05-09 14:00 ` [PATCH iproute2-next 08/10] ipstats: Expose bridge stats in ipstats Petr Machata
@ 2022-05-09 14:00 ` Petr Machata
  2022-05-27  0:13   ` Stephen Hemminger
  2022-05-09 14:00 ` [PATCH iproute2-next 10/10] man: ip-stats.8: Describe groups xstats, xstats_slave and afstats Petr Machata
  2022-05-12 17:20 ` [PATCH iproute2-next 00/10] ip stats: Support for xstats " patchwork-bot+netdevbpf
  10 siblings, 1 reply; 14+ messages in thread
From: Petr Machata @ 2022-05-09 14:00 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

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>
---
 ip/ip_common.h   |  3 +++
 ip/iplink_bond.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++--
 ip/ipstats.c     |  2 ++
 3 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/ip/ip_common.h b/ip/ip_common.h
index c58f2090..ffa633e0 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -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,
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
index 650411fc..15db19a3 100644
--- a/ip/iplink_bond.c
+++ b/ip/iplink_bond.c
@@ -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),
+};
diff --git a/ip/ipstats.c b/ip/ipstats.c
index 1051976d..5cdd15ae 100644
--- a/ip/ipstats.c
+++ b/ip/ipstats.c
@@ -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 = {
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH iproute2-next 10/10] man: ip-stats.8: Describe groups xstats, xstats_slave and afstats
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
                   ` (8 preceding siblings ...)
  2022-05-09 14:00 ` [PATCH iproute2-next 09/10] ipstats: Expose bond " Petr Machata
@ 2022-05-09 14:00 ` Petr Machata
  2022-05-12 17:20 ` [PATCH iproute2-next 00/10] ip stats: Support for xstats " patchwork-bot+netdevbpf
  10 siblings, 0 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-09 14:00 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Ido Schimmel, Petr Machata

Add description of the newly-added statistics groups.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 man/man8/ip-stats.8 | 47 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/man/man8/ip-stats.8 b/man/man8/ip-stats.8
index a82fe9f7..26336454 100644
--- a/man/man8/ip-stats.8
+++ b/man/man8/ip-stats.8
@@ -68,6 +68,20 @@ The following groups are recognized:
 - A group that contains a number of HW-oriented statistics. See below for
 individual subgroups within this group.
 
+.ti 14
+.B group xstats
+- Extended statistics. A subgroup identifies the type of netdevice to show the
+statistics for.
+
+.ti 14
+.B group xstats_slave
+- Extended statistics for the slave of a netdevice of a given type. A subgroup
+identifies the type of master netdevice.
+
+.ti 14
+.B group afstats
+- A group for address-family specific netdevice statistics.
+
 .TQ
 .BR "group offload " subgroups:
 .in 21
@@ -133,6 +147,39 @@ For example:
 
 Note how the l3_stats_info for the selected group is also part of the dump.
 
+.TQ
+.BR "group xstats " and " group xstats_slave " subgroups:
+.in 21
+
+.ti 14
+.B subgroup bridge \fR[\fB suite stp \fR] [\fB suite mcast \fR]
+- Statistics for STP and, respectively, IGMP / MLD (under the keyword
+\fBmcast\fR) traffic on bridges and their slaves.
+
+.ti 14
+.B subgroup bond \fR[\fB suite 802.3ad \fR]
+- Statistics for LACP traffic on bond devices and their slaves.
+
+.TQ
+.BR "group afstats " subgroups:
+.in 21
+
+.ti 14
+.B subgroup mpls
+- Statistics for MPLS traffic seen on the netdevice. For example:
+
+# ip stats show dev veth01 group afstats subgroup mpls
+.br
+3: veth01: group afstats subgroup mpls
+.br
+    RX: bytes packets errors dropped noroute
+.br
+            0       0      0       0       0
+.br
+    TX: bytes packets errors dropped
+.br
+          216       2      0       0
+
 .SH EXAMPLES
 .PP
 # ip stats set dev swp1 l3_stats on
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats
  2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
                   ` (9 preceding siblings ...)
  2022-05-09 14:00 ` [PATCH iproute2-next 10/10] man: ip-stats.8: Describe groups xstats, xstats_slave and afstats Petr Machata
@ 2022-05-12 17:20 ` patchwork-bot+netdevbpf
  10 siblings, 0 replies; 14+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-05-12 17:20 UTC (permalink / raw)
  To: Petr Machata; +Cc: netdev, dsahern, idosch

Hello:

This series was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:

On Mon, 9 May 2022 15:59:53 +0200 you wrote:
> The RTM_GETSTATS response attributes IFLA_STATS_LINK_XSTATS and
> IFLA_STATS_LINK_XSTATS_SLAVE are used to carry statistics related to,
> respectively, netdevices of a certain type, and netdevices enslaved to
> netdevices of a certain type. IFLA_STATS_AF_SPEC are similarly used to
> carry statistics specific to a certain address family.
> 
> In this patch set, add support for three new stats groups that cover the
> above attributes: xstats, xstats_slave and afstats. Add bridge and bond
> subgroups to the former two groups, and mpls subgroup to the latter one.
> 
> [...]

Here is the summary with links:
  - [iproute2-next,01/10] iplink: Fix formatting of MPLS stats
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=72623b73c4ea
  - [iproute2-next,02/10] iplink: Publish a function to format MPLS stats
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=dff392fd86ee
  - [iproute2-next,03/10] ipstats: Add a group "afstats", subgroup "mpls"
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=5ed8fd9d5144
  - [iproute2-next,04/10] iplink: Add JSON support to MPLS stats formatter
    (no matching commit)
  - [iproute2-next,05/10] ipstats: Add a third level of stats hierarchy, a "suite"
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=c6900b79b13d
  - [iproute2-next,06/10] ipstats: Add groups "xstats", "xstats_slave"
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=1247ed51e924
  - [iproute2-next,07/10] iplink_bridge: Split bridge_print_stats_attr()
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=79f5ad95c17c
  - [iproute2-next,08/10] ipstats: Expose bridge stats in ipstats
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=36e10429dafc
  - [iproute2-next,09/10] ipstats: Expose bond stats in ipstats
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=d9976d671c37
  - [iproute2-next,10/10] man: ip-stats.8: Describe groups xstats, xstats_slave and afstats
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=5a1ad9f8c1e6

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH iproute2-next 09/10] ipstats: Expose bond stats in ipstats
  2022-05-09 14:00 ` [PATCH iproute2-next 09/10] ipstats: Expose bond " Petr Machata
@ 2022-05-27  0:13   ` Stephen Hemminger
  2022-05-27 14:50     ` Petr Machata
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen Hemminger @ 2022-05-27  0:13 UTC (permalink / raw)
  To: Petr Machata; +Cc: netdev, David Ahern, Ido Schimmel

On Mon, 9 May 2022 16:00:02 +0200
Petr Machata <petrm@nvidia.com> wrote:

> 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>
> ---
>  ip/ip_common.h   |  3 +++
>  ip/iplink_bond.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++--
>  ip/ipstats.c     |  2 ++
>  3 files changed, 58 insertions(+), 2 deletions(-)

This change won't build if clang is used to build iproute2.
It has valid warning:

    CC       iplink_bond.o
iplink_bond.c:935:10: error: initializer element is not a compile-time constant
        .desc = ipstats_stat_desc_bond_tmpl_lacp,
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
iplink_bond.c:957:10: error: initializer element is not a compile-time constant
        .desc = ipstats_stat_desc_bond_tmpl_lacp,
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

Since desc is a structure, you can't just assign an existing data structure
to the new initializer.  It needs to be a pointer or macro.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH iproute2-next 09/10] ipstats: Expose bond stats in ipstats
  2022-05-27  0:13   ` Stephen Hemminger
@ 2022-05-27 14:50     ` Petr Machata
  0 siblings, 0 replies; 14+ messages in thread
From: Petr Machata @ 2022-05-27 14:50 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Petr Machata, netdev, David Ahern, Ido Schimmel


Stephen Hemminger <stephen@networkplumber.org> writes:

> This change won't build if clang is used to build iproute2.
> It has valid warning:
>
>     CC       iplink_bond.o
> iplink_bond.c:935:10: error: initializer element is not a compile-time constant
>         .desc = ipstats_stat_desc_bond_tmpl_lacp,
>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> iplink_bond.c:957:10: error: initializer element is not a compile-time constant
>         .desc = ipstats_stat_desc_bond_tmpl_lacp,
>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 2 errors generated.
>
> Since desc is a structure, you can't just assign an existing data structure
> to the new initializer.  It needs to be a pointer or macro.

Yeah, it has to be a macro. I'll send a patch probably next week.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-05-27 14:51 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09 13:59 [PATCH iproute2-next 00/10] ip stats: Support for xstats and afstats Petr Machata
2022-05-09 13:59 ` [PATCH iproute2-next 01/10] iplink: Fix formatting of MPLS stats Petr Machata
2022-05-09 13:59 ` [PATCH iproute2-next 02/10] iplink: Publish a function to format " Petr Machata
2022-05-09 13:59 ` [PATCH iproute2-next 03/10] ipstats: Add a group "afstats", subgroup "mpls" Petr Machata
2022-05-09 13:59 ` [PATCH iproute2-next 04/10] iplink: Add JSON support to MPLS stats formatter Petr Machata
2022-05-09 13:59 ` [PATCH iproute2-next 05/10] ipstats: Add a third level of stats hierarchy, a "suite" Petr Machata
2022-05-09 13:59 ` [PATCH iproute2-next 06/10] ipstats: Add groups "xstats", "xstats_slave" Petr Machata
2022-05-09 14:00 ` [PATCH iproute2-next 07/10] iplink_bridge: Split bridge_print_stats_attr() Petr Machata
2022-05-09 14:00 ` [PATCH iproute2-next 08/10] ipstats: Expose bridge stats in ipstats Petr Machata
2022-05-09 14:00 ` [PATCH iproute2-next 09/10] ipstats: Expose bond " Petr Machata
2022-05-27  0:13   ` Stephen Hemminger
2022-05-27 14:50     ` Petr Machata
2022-05-09 14:00 ` [PATCH iproute2-next 10/10] man: ip-stats.8: Describe groups xstats, xstats_slave and afstats Petr Machata
2022-05-12 17:20 ` [PATCH iproute2-next 00/10] ip stats: Support for xstats " patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.