]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tc: jsonify sample action
authorRoman Mashak <mrv@mojatatu.com>
Sat, 31 Mar 2018 04:20:45 +0000 (00:20 -0400)
committerDavid Ahern <dsahern@gmail.com>
Sun, 1 Apr 2018 15:44:31 +0000 (08:44 -0700)
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
tc/m_sample.c

index 1e18c5154fe688236199c61f78df94dfb68f5d4b..39a99246a8eaedac9a859f42e7795bdb0a0d4103 100644 (file)
@@ -149,23 +149,27 @@ static int print_sample(struct action_util *au, FILE *f, struct rtattr *arg)
 
        if (!tb[TCA_SAMPLE_PARMS] || !tb[TCA_SAMPLE_RATE] ||
            !tb[TCA_SAMPLE_PSAMPLE_GROUP]) {
-               fprintf(f, "[NULL sample parameters]");
+               print_string(PRINT_FP, NULL, "%s", "[NULL sample parameters]");
                return -1;
        }
        p = RTA_DATA(tb[TCA_SAMPLE_PARMS]);
 
-       fprintf(f, "sample rate 1/%d group %d",
-               rta_getattr_u32(tb[TCA_SAMPLE_RATE]),
-               rta_getattr_u32(tb[TCA_SAMPLE_PSAMPLE_GROUP]));
+       print_string(PRINT_ANY, "kind", "%s ", "sample");
+       print_uint(PRINT_ANY, "rate", "rate 1/%u ",
+                  rta_getattr_u32(tb[TCA_SAMPLE_RATE]));
+       print_uint(PRINT_ANY, "group", "group %u",
+                  rta_getattr_u32(tb[TCA_SAMPLE_PSAMPLE_GROUP]));
 
        if (tb[TCA_SAMPLE_TRUNC_SIZE])
-               fprintf(f, " trunc_size %d",
-                       rta_getattr_u32(tb[TCA_SAMPLE_TRUNC_SIZE]));
+               print_uint(PRINT_ANY, "trunc_size", " trunc_size %u",
+                          rta_getattr_u32(tb[TCA_SAMPLE_TRUNC_SIZE]));
 
        print_action_control(f, " ", p->action, "");
 
-       fprintf(f, "\n\tindex %d ref %d bind %d", p->index, p->refcnt,
-               p->bindcnt);
+       print_string(PRINT_FP, NULL, "%s", _SL_);
+       print_uint(PRINT_ANY, "index", "\t index %u", p->index);
+       print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
+       print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
 
        if (show_stats) {
                if (tb[TCA_SAMPLE_TM]) {
@@ -174,7 +178,7 @@ static int print_sample(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       fprintf(f, "\n");
+       print_string(PRINT_FP, NULL, "%s", _SL_);
        return 0;
 }