netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH] iplink: support JSON in MPLS output
Date: Fri,  9 Dec 2022 19:46:48 -0800	[thread overview]
Message-ID: <20221210034648.90592-1-stephen@networkplumber.org> (raw)

The MPLS statistics did not support oneline or JSON
in current code.

Fixes: 837552b445f5 ("iplink: add support for afstats subcommand")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 ip/iplink.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/ip/iplink.c b/ip/iplink.c
index adb9524c3b93..b8a5284febfb 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1570,7 +1570,7 @@ void print_mpls_link_stats(FILE *fp, const struct mpls_link_stats *stats,
 		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");
+		print_nl();
 
 		fprintf(fp, "%sTX: %*s %*s %*s %*s%s", indent,
 			cols[0] - 4, "bytes", cols[1], "packets",
@@ -1594,9 +1594,11 @@ static void print_mpls_stats(FILE *fp, struct rtattr *attr)
 		return;
 
 	stats = RTA_DATA(mrtb[MPLS_STATS_LINK]);
-	fprintf(fp, "    mpls:\n");
+	print_string(PRINT_FP, NULL, "    mpls:", NULL);
+	print_nl();
 	print_mpls_link_stats(fp, stats, "        ");
-	fprintf(fp, "\n");
+	print_string(PRINT_FP, NULL, "%s", "\n");
+	fflush(fp);
 }
 
 static void print_af_stats_attr(FILE *fp, int ifindex, struct rtattr *attr)
@@ -1612,8 +1614,12 @@ static void print_af_stats_attr(FILE *fp, int ifindex, struct rtattr *attr)
 			continue;
 
 		if (!if_printed) {
-			fprintf(fp, "%u: %s\n", ifindex,
-				ll_index_to_name(ifindex));
+			print_uint(PRINT_ANY, "ifindex",
+				   "%u:", ifindex);
+			print_color_string(PRINT_ANY, COLOR_IFNAME, 
+					   "ifname", "%s",
+					   ll_index_to_name(ifindex));
+			print_nl();
 			if_printed = true;
 		}
 
@@ -1696,6 +1702,8 @@ static int iplink_afstats(int argc, char **argv)
 		}
 	}
 
+	new_json_obj(json);
+
 	if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask,
 				      NULL, NULL) < 0) {
 		perror("Cannont send dump request");
@@ -1707,6 +1715,7 @@ static int iplink_afstats(int argc, char **argv)
 		return 1;
 	}
 
+	delete_json_obj();
 	return 0;
 }
 
-- 
2.35.1


             reply	other threads:[~2022-12-10  3:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-10  3:46 Stephen Hemminger [this message]
2022-12-12 16:40 ` [PATCH] iplink: support JSON in MPLS output 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=20221210034648.90592-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).