]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tc: add json support in csum action
authorKeara Leibovitz <kleib@mojatatu.com>
Tue, 5 Jun 2018 20:44:19 +0000 (16:44 -0400)
committerDavid Ahern <dsahern@gmail.com>
Tue, 5 Jun 2018 22:30:30 +0000 (15:30 -0700)
Add json output support for checksum action.

Example output:

~$ $TC actions add action csum udp continue index 7
~$ $TC actions add action csum icmp iph igmp pipe index 200 cookie 112233
~$ $TC -j actions ls action csum

[{
    "total acts":2
}, {
    "actions": [{
        "order":0,
        "csum":"udp",
        "control_action": {
            "type":"continue"
        },
        "index":7,
        "ref":1,
        "bind":0
    }, {
        "order":1,
        "csum":"iph, icmp, igmp",
        "control_action": {
            "type":"pipe"
        },
        "index":200,
        "ref":1,
        "bind":0,
        "cookie":"112233"
    }]
}]

v2:
    Don't initialized char buf[64];
    Add output example

Signed-off-by: Keara Leibovitz <kleib@mojatatu.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
tc/m_csum.c

index 8391071d73f2396ed30c426790cac82e4dfbd4fb..752269d1d02049dea645b2ed196421080b67e259 100644 (file)
@@ -162,6 +162,7 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
        char *uflag_5 = "";
        char *uflag_6 = "";
        char *uflag_7 = "";
+       SPRINT_BUF(buf);
 
        int uflag_count = 0;
 
@@ -198,12 +199,15 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
                uflag_1 = "?empty";
        }
 
-       fprintf(f, "csum (%s%s%s%s%s%s%s) ",
-               uflag_1, uflag_2, uflag_3,
-               uflag_4, uflag_5, uflag_6, uflag_7);
+       snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s",
+                uflag_1, uflag_2, uflag_3,
+                uflag_4, uflag_5, uflag_6, uflag_7);
+       print_string(PRINT_ANY, "csum", "csum (%s) ", buf);
+
        print_action_control(f, "action ", sel->action, "\n");
-       fprintf(f, "\tindex %u ref %d bind %d", sel->index, sel->refcnt,
-               sel->bindcnt);
+       print_uint(PRINT_ANY, "index", "\tindex %u", sel->index);
+       print_int(PRINT_ANY, "ref", " ref %d", sel->refcnt);
+       print_int(PRINT_ANY, "bind", " bind %d", sel->bindcnt);
 
        if (show_stats) {
                if (tb[TCA_CSUM_TM]) {
@@ -212,7 +216,7 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       fprintf(f, "\n");
+       print_string(PRINT_FP, NULL, "%s", "\n");
 
        return 0;
 }