]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: iplink_xdp.c: add json output support
authorJulien Fortin <julien@cumulusnetworks.com>
Thu, 17 Aug 2017 17:36:05 +0000 (10:36 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 18 Aug 2017 01:02:41 +0000 (18:02 -0700)
Schema
{
    "attached": {
        "type": "uint",
        "attr": "IFLA_XDP_ATTACHED"
    },
    "prog_id": {
        "type": "uint",
        "attr": "IFLA_XDP_PROG_ID"
    }
}

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
ip/iplink_xdp.c

index 9ae9ee5d06650cee5bb4f4ce607a7d3e0247eb06..3a61076e02117fc1e951552037ae7336d7a98172 100644 (file)
@@ -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", " ");
 }