lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180710210558.20278-29-stephen@networkplumber.org>
Date:   Tue, 10 Jul 2018 14:05:55 -0700
From:   Stephen Hemminger <stephen@...workplumber.org>
To:     netdev@...r.kernel.org
Cc:     Stephen Hemminger <sthemmin@...rosoft.com>,
        Stephen Hemminger <stephen@...workplumber.org>
Subject: [PATCH v2 iproute2-next 28/31] tc/atm: convert to JSON output

From: Stephen Hemminger <sthemmin@...rosoft.com>

Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
---
 tc/q_atm.c | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/tc/q_atm.c b/tc/q_atm.c
index f8215f06507a..d5ab7a06b28f 100644
--- a/tc/q_atm.c
+++ b/tc/q_atm.c
@@ -194,37 +194,45 @@ static int atm_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 			fprintf(stderr, "ATM: address too short\n");
 		else {
 			if (atm2text(buffer, MAX_ATM_ADDR_LEN,
-			    RTA_DATA(tb[TCA_ATM_ADDR]), A2T_PRETTY | A2T_NAME) <
-			    0) fprintf(stderr, "atm2text error\n");
-			fprintf(f, "pvc %s ", buffer);
+				     RTA_DATA(tb[TCA_ATM_ADDR]), A2T_PRETTY | A2T_NAME) < 0)
+				fprintf(stderr, "atm2text error\n");
+			else
+				print_string(PRINT_ANY, "pvc",
+					     "pvc %s ", buffer);
 		}
 	}
+
 	if (tb[TCA_ATM_HDR]) {
 		int i;
 		const __u8 *hdr = RTA_DATA(tb[TCA_ATM_HDR]);
 
-		fprintf(f, "hdr");
-		for (i = 0; i < RTA_PAYLOAD(tb[TCA_ATM_HDR]); i++)
-			fprintf(f, "%c%02x", i ? '.' : ' ', hdr[i]);
-		if (!i) fprintf(f, " .");
-		fprintf(f, " ");
+		open_json_array(PRINT_ANY, "hdr");
+		for (i = 0; i < RTA_PAYLOAD(tb[TCA_ATM_HDR]); i++) {
+			print_string(PRINT_FP, NULL, "%s",
+				     i ? "." : " ");
+			print_0xhex(PRINT_ANY, NULL, "%02x", hdr[i]);
+		}
+
+		print_string(PRINT_FP, NULL, "%s ", i ? "" : " .");
 	}
+
 	if (tb[TCA_ATM_EXCESS]) {
 		__u32 excess;
 
 		if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS]) < sizeof(excess))
 			fprintf(stderr, "ATM: excess class ID too short\n");
 		else {
-			excess = rta_getattr_u32(tb[TCA_ATM_EXCESS]);
-			if (!excess) fprintf(f, "excess clp ");
-			else {
-				char buf[64];
+			char buf[64];
 
+			excess = rta_getattr_u32(tb[TCA_ATM_EXCESS]);
+			if (!excess)
+				strcpy(buf, "clp");
+			else
 				print_tc_classid(buf, sizeof(buf), excess);
-				fprintf(f, "excess %s ", buf);
-			}
+			print_string(PRINT_ANY, "excess", "excess %s ", buf);
 		}
 	}
+
 	if (tb[TCA_ATM_STATE]) {
 		static const char *map[] = { ATM_VS2TXT_MAP };
 		int state;
@@ -233,7 +241,7 @@ static int atm_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 			fprintf(stderr, "ATM: state field too short\n");
 		else {
 			state = rta_getattr_u32(tb[TCA_ATM_STATE]);
-			fprintf(f, "%s ", map[state]);
+			print_string(PRINT_ANY, "state", "%s ", map[state]);
 		}
 	}
 	return 0;
-- 
2.18.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ