[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170817173614.54987-19-julien@cumulusnetworks.com>
Date: Thu, 17 Aug 2017 10:36:05 -0700
From: Julien Fortin <julien@...ulusnetworks.com>
To: netdev@...r.kernel.org
Cc: roopa@...ulusnetworks.com, nikolay@...ulusnetworks.com,
dsa@...ulusnetworks.com, Julien Fortin <julien@...ulusnetworks.com>
Subject: [PATCH iproute2 json v2 18/27] ip: iplink_xdp.c: add json output support
From: Julien Fortin <julien@...ulusnetworks.com>
Schema
{
"attached": {
"type": "uint",
"attr": "IFLA_XDP_ATTACHED"
},
"prog_id": {
"type": "uint",
"attr": "IFLA_XDP_PROG_ID"
}
}
Signed-off-by: Julien Fortin <julien@...ulusnetworks.com>
---
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
Powered by blists - more mailing lists