git: ae4fb190fd4a - main - netstat: split ipsec and ipsec6 statistics in libxo

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Tue, 05 Oct 2021 09:44:40 UTC
The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=ae4fb190fd4a21649c4562fc6cd81bba4da222a4

commit ae4fb190fd4a21649c4562fc6cd81bba4da222a4
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2021-10-05 09:42:58 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2021-10-05 09:42:58 +0000

    netstat: split ipsec and ipsec6 statistics in libxo
    
    In particular fixes --libxo json
    
    PR:             254673
    Reported by:    j.vandeville@gmail.com
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 usr.bin/netstat/ipsec.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/usr.bin/netstat/ipsec.c b/usr.bin/netstat/ipsec.c
index e57d7f4905b5..029dd64f3b35 100644
--- a/usr.bin/netstat/ipsec.c
+++ b/usr.bin/netstat/ipsec.c
@@ -154,12 +154,10 @@ static struct val2str ipsec_compnames[] = {
 	{ -1, NULL },
 };
 
-static void print_ipsecstats(const struct ipsecstat *ipsecstat);
-
 static void
-print_ipsecstats(const struct ipsecstat *ipsecstat)
+print_ipsecstats(const char *tag, const struct ipsecstat *ipsecstat)
 {
-	xo_open_container("ipsec-statistics");
+	xo_open_container(tag);
 
 #define	p(f, m) if (ipsecstat->f || sflag <= 1) \
 	xo_emit(m, (uintmax_t)ipsecstat->f, plural(ipsecstat->f))
@@ -194,27 +192,30 @@ print_ipsecstats(const struct ipsecstat *ipsecstat)
 	    "{N:/mbuf%s inserted during makespace}\n");
 #undef p2
 #undef p
-	xo_close_container("ipsec-statistics");
+	xo_close_container(tag);
 }
 
 void
 ipsec_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
 {
 	struct ipsecstat ipsecstat;
+	const char *tag;
 
 	if (strcmp(name, "ipsec6") == 0) {
 		if (fetch_stats("net.inet6.ipsec6.ipsecstats", off,&ipsecstat,
 				sizeof(ipsecstat), kread_counters) != 0)
 			return;
+		tag = "ipsec6-statistics";
 	} else {
 		if (fetch_stats("net.inet.ipsec.ipsecstats", off, &ipsecstat,
 				sizeof(ipsecstat), kread_counters) != 0)
 			return;
+		tag = "ipsec-statistics";
 	}
 
 	xo_emit("{T:/%s}:\n", name);
 
-	print_ipsecstats(&ipsecstat);
+	print_ipsecstats(tag, &ipsecstat);
 }