Thread (33 messages) 33 messages, 4 authors, 2017-09-20

[PATCH iproute2 json v2 18/27] ip: iplink_xdp.c: add json output support

flat view
STALE3320d

From: Julien Fortin <hidden>
Date: 2017-08-17 17:41:39
Subsystem: the rest · Maintainer: Linus Torvalds

Revision v2 of 2 in this series.

Revisions (2)
  1. v1 [diff vs current]
  2. v2 current
From: Julien Fortin <redacted>

Schema
{
    "attached": {
        "type": "uint",
        "attr": "IFLA_XDP_ATTACHED"
    },
    "prog_id": {
        "type": "uint",
        "attr": "IFLA_XDP_PROG_ID"
    }
}

Signed-off-by: Julien Fortin <redacted>
---
 ip/iplink_xdp.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c
index 9ae9ee5d..3a61076e 100644
--- a/ip/iplink_xdp.c
+++ b/ip/iplink_xdp.c
@@ -16,6 +16,7 @@
 
 #include "xdp.h"
 #include "bpf_util.h"
+#include "ip_common.h"
 
 extern int force;
 
@@ -92,20 +93,24 @@ void xdp_dump(FILE *fp, struct rtattr *xdp)
 		return;
 
 	mode = rta_getattr_u8(tb[IFLA_XDP_ATTACHED]);
-	if (mode == XDP_ATTACHED_NONE)
-		return;
-	else if (mode == XDP_ATTACHED_DRV)
-		fprintf(fp, "xdp");
-	else if (mode == XDP_ATTACHED_SKB)
-		fprintf(fp, "xdpgeneric");
-	else if (mode == XDP_ATTACHED_HW)
-		fprintf(fp, "xdpoffload");
-	else
-		fprintf(fp, "xdp[%u]", mode);
+	if (is_json_context()) {
+		print_uint(PRINT_JSON, "attached", NULL, mode);
+	} else {
+		if (mode == XDP_ATTACHED_NONE)
+			return;
+		else if (mode == XDP_ATTACHED_DRV)
+			fprintf(fp, "xdp");
+		else if (mode == XDP_ATTACHED_SKB)
+			fprintf(fp, "xdpgeneric");
+		else if (mode == XDP_ATTACHED_HW)
+			fprintf(fp, "xdpoffload");
+		else
+			fprintf(fp, "xdp[%u]", mode);
+	}
 
 	if (tb[IFLA_XDP_PROG_ID])
-		fprintf(fp, "/id:%u",
-			rta_getattr_u32(tb[IFLA_XDP_PROG_ID]));
+		print_uint(PRINT_ANY, "prog_id", "/id:%u",
+				   rta_getattr_u32(tb[IFLA_XDP_PROG_ID]));
 
-	fprintf(fp, " ");
+	print_string(PRINT_FP, NULL, "%c", " ");
 }
-- 
2.14.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help