All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Machata <petrm@nvidia.com>
To: <netdev@vger.kernel.org>
Cc: David Ahern <dsahern@gmail.com>, Ido Schimmel <idosch@nvidia.com>,
	"Petr Machata" <petrm@nvidia.com>
Subject: [PATCH iproute2-next 02/10] iplink: Publish a function to format MPLS stats
Date: Mon, 9 May 2022 15:59:55 +0200	[thread overview]
Message-ID: <8c523ff76968b72df235c76a27fa9c3d96cf3b2b.1652104101.git.petrm@nvidia.com> (raw)
In-Reply-To: <cover.1652104101.git.petrm@nvidia.com>

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


  parent reply	other threads:[~2022-05-09 14:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=8c523ff76968b72df235c76a27fa9c3d96cf3b2b.1652104101.git.petrm@nvidia.com \
    --to=petrm@nvidia.com \
    --cc=dsahern@gmail.com \
    --cc=idosch@nvidia.com \
    --cc=netdev@vger.kernel.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 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.