diff mbox series

[iproute2-next,1/9] tc: use JSON in error handling

Message ID 20180709194856.18922-2-stephen@networkplumber.org
State Superseded, archived
Delegated to: David Ahern
Headers show
Series TC more JSON support | expand

Commit Message

Stephen Hemminger July 9, 2018, 7:48 p.m. UTC
From: Stephen Hemminger <sthemmin@microsoft.com>

If option or qdisc is unknown, still output in JSON.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 tc/tc.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/tc/tc.c b/tc/tc.c
index 0d223281ba25..b6d2a6151793 100644
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -56,9 +56,11 @@  static struct filter_util *filter_list;
 static int print_noqopt(struct qdisc_util *qu, FILE *f,
 			struct rtattr *opt)
 {
-	if (opt && RTA_PAYLOAD(opt))
-		fprintf(f, "[Unknown qdisc, optlen=%u] ",
-			(unsigned int) RTA_PAYLOAD(opt));
+	if (opt && RTA_PAYLOAD(opt)) {
+		print_string(PRINT_JSON, "qdisc", NULL, "UNKNOWN");
+		print_uint(PRINT_ANY, "optlen", "[Unknown qdisc, optlen=%u] ",
+			   RTA_PAYLOAD(opt));
+	}
 	return 0;
 }
 
@@ -76,11 +78,12 @@  static int parse_noqopt(struct qdisc_util *qu, int argc, char **argv,
 
 static int print_nofopt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 fhandle)
 {
-	if (opt && RTA_PAYLOAD(opt))
-		fprintf(f, "fh %08x [Unknown filter, optlen=%u] ",
-			fhandle, (unsigned int) RTA_PAYLOAD(opt));
-	else if (fhandle)
-		fprintf(f, "fh %08x ", fhandle);
+	if (opt && RTA_PAYLOAD(opt)) {
+		print_0xhex(PRINT_ANY, "handle", "fh %08x ", fhandle);
+		print_uint(PRINT_ANY, "optlen", "[Unknown filter, optlen=%u] ",
+			RTA_PAYLOAD(opt));
+	} else if (fhandle)
+		print_0xhex(PRINT_ANY, "handle", "fh %08x ", fhandle);
 	return 0;
 }