]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
tc: add json support to size table
authorStephen Hemminger <stephen@networkplumber.org>
Wed, 23 Nov 2022 04:16:07 +0000 (20:16 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 23 Nov 2022 04:46:57 +0000 (20:46 -0800)
Fix the JSON output if size addaption table is used.

Example:
[ {
        "kind": "fq_codel",
        "handle": "1:",
        "dev": "enp2s0",
        "root": true,
        "refcnt": 2,
        "options": {
            "limit": 10240,
            "flows": 1024,
            "quantum": 1514,
            "target": 4999,
            "interval": 99999,
            "memory_limit": 33554432,
            "ecn": true,
            "drop_batch": 64
        },
        "stab": {
            "overhead": 30,
            "mpu": 68,
            "mtu": 2047,
            "tsize": 512
        }
    } ]

Remove fixed prefix arg and no longer needed fp arg.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
tc/tc_common.h
tc/tc_qdisc.c
tc/tc_stab.c

index 58dc9d6a6c4fb541971aab3141a98ad42dd26cfd..f1561d80a43bd065845911496775092d19aed81c 100644 (file)
@@ -16,7 +16,7 @@ int print_action(struct nlmsghdr *n, void *arg);
 int print_filter(struct nlmsghdr *n, void *arg);
 int print_qdisc(struct nlmsghdr *n, void *arg);
 int print_class(struct nlmsghdr *n, void *arg);
-void print_size_table(FILE *fp, const char *prefix, struct rtattr *rta);
+void print_size_table(struct rtattr *rta);
 
 struct tc_estimator;
 int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est);
index b79029d96202b2a4897ce4a11eae83ecdef516a2..33a6665eaac00775375e0592b9f24a30099a27be 100644 (file)
@@ -329,7 +329,7 @@ int print_qdisc(struct nlmsghdr *n, void *arg)
        print_nl();
 
        if (show_details && tb[TCA_STAB]) {
-               print_size_table(fp, " ", tb[TCA_STAB]);
+               print_size_table(tb[TCA_STAB]);
                print_nl();
        }
 
index c61ecfd200cad90553b99880b9d510338adbd6be..06dc1b134d850e54fae98f5d8c1584179ad6af4a 100644 (file)
@@ -103,7 +103,7 @@ int parse_size_table(int *argcp, char ***argvp, struct tc_sizespec *sp)
        return 0;
 }
 
-void print_size_table(FILE *fp, const char *prefix, struct rtattr *rta)
+void print_size_table(struct rtattr *rta)
 {
        struct rtattr *tb[TCA_STAB_MAX + 1];
 
@@ -117,17 +117,23 @@ void print_size_table(FILE *fp, const char *prefix, struct rtattr *rta)
                memcpy(&s, RTA_DATA(tb[TCA_STAB_BASE]),
                                MIN(RTA_PAYLOAD(tb[TCA_STAB_BASE]), sizeof(s)));
 
-               fprintf(fp, "%s", prefix);
+               print_string(PRINT_FP, NULL, " ", NULL);
+
                if (s.linklayer)
-                       fprintf(fp, "linklayer %s ",
-                                       sprint_linklayer(s.linklayer, b1));
+                       print_string(PRINT_ANY, "linklayer",
+                                    "linklayer %s ",
+                                    sprint_linklayer(s.linklayer, b1));
                if (s.overhead)
-                       fprintf(fp, "overhead %d ", s.overhead);
+                       print_int(PRINT_ANY, "overhead",
+                                 "overhead %d ", s.overhead);
                if (s.mpu)
-                       fprintf(fp, "mpu %u ", s.mpu);
+                       print_uint(PRINT_ANY, "mpu",
+                                  "mpu %u ", s.mpu);
                if (s.mtu)
-                       fprintf(fp, "mtu %u ", s.mtu);
+                       print_uint(PRINT_ANY, "mtu",
+                                  "mtu %u ", s.mtu);
                if (s.tsize)
-                       fprintf(fp, "tsize %u ", s.tsize);
+                       print_uint(PRINT_ANY, "tsize",
+                                  "tsize %u ", s.tsize);
        }
 }