]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/q_fq_codel.c
tc: Remove pointless assignments in batch()
[mirror_iproute2.git] / tc / q_fq_codel.c
index 4f747ebdff177482e3d389c73ae2051191d74164..02ad2214110b460d5e3c6233525cf1de13f1a667 100644 (file)
@@ -38,7 +38,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 static void explain(void)
 {
        fprintf(stderr, "Usage: ... fq_codel [ limit PACKETS ] [ flows NUMBER ]\n");
-       fprintf(stderr, "                    [ target TIME] [ interval TIME ]\n");
+       fprintf(stderr, "                    [ memory_limit BYTES ]\n");
+       fprintf(stderr, "                    [ target TIME ] [ interval TIME ]\n");
        fprintf(stderr, "                    [ quantum BYTES ] [ [no]ecn ]\n");
        fprintf(stderr, "                    [ ce_threshold TIME ]\n");
 }
 
 static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-                             struct nlmsghdr *n)
+                             struct nlmsghdr *n, const char *dev)
 {
-       unsigned limit = 0;
-       unsigned flows = 0;
-       unsigned target = 0;
-       unsigned interval = 0;
-       unsigned quantum = 0;
-       unsigned ce_threshold = ~0U;
+       unsigned int limit = 0;
+       unsigned int flows = 0;
+       unsigned int target = 0;
+       unsigned int interval = 0;
+       unsigned int quantum = 0;
+       unsigned int ce_threshold = ~0U;
+       unsigned int memory = ~0U;
        int ecn = -1;
        struct rtattr *tail;
 
@@ -99,6 +100,12 @@ static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
                                fprintf(stderr, "Illegal \"ce_threshold\"\n");
                                return -1;
                        }
+               } else if (strcmp(*argv, "memory_limit") == 0) {
+                       NEXT_ARG();
+                       if (get_size(&memory, *argv)) {
+                               fprintf(stderr, "Illegal \"memory_limit\"\n");
+                               return -1;
+                       }
                } else if (strcmp(*argv, "interval") == 0) {
                        NEXT_ARG();
                        if (get_time(&interval, *argv)) {
@@ -120,8 +127,7 @@ static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
                argc--; argv++;
        }
 
-       tail = NLMSG_TAIL(n);
-       addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
+       tail = addattr_nest(n, 1024, TCA_OPTIONS);
        if (limit)
                addattr_l(n, 1024, TCA_FQ_CODEL_LIMIT, &limit, sizeof(limit));
        if (flows)
@@ -137,20 +143,26 @@ static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
        if (ce_threshold != ~0U)
                addattr_l(n, 1024, TCA_FQ_CODEL_CE_THRESHOLD,
                          &ce_threshold, sizeof(ce_threshold));
-       tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
+       if (memory != ~0U)
+               addattr_l(n, 1024, TCA_FQ_CODEL_MEMORY_LIMIT,
+                         &memory, sizeof(memory));
+
+       addattr_nest_end(n, tail);
        return 0;
 }
 
 static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 {
        struct rtattr *tb[TCA_FQ_CODEL_MAX + 1];
-       unsigned limit;
-       unsigned flows;
-       unsigned interval;
-       unsigned target;
-       unsigned ecn;
-       unsigned quantum;
-       unsigned ce_threshold;
+       unsigned int limit;
+       unsigned int flows;
+       unsigned int interval;
+       unsigned int target;
+       unsigned int ecn;
+       unsigned int quantum;
+       unsigned int ce_threshold;
+       unsigned int memory_limit;
+
        SPRINT_BUF(b1);
 
        if (opt == NULL)
@@ -161,38 +173,51 @@ static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt
        if (tb[TCA_FQ_CODEL_LIMIT] &&
            RTA_PAYLOAD(tb[TCA_FQ_CODEL_LIMIT]) >= sizeof(__u32)) {
                limit = rta_getattr_u32(tb[TCA_FQ_CODEL_LIMIT]);
-               fprintf(f, "limit %up ", limit);
+               print_uint(PRINT_ANY, "limit", "limit %up ", limit);
        }
        if (tb[TCA_FQ_CODEL_FLOWS] &&
            RTA_PAYLOAD(tb[TCA_FQ_CODEL_FLOWS]) >= sizeof(__u32)) {
                flows = rta_getattr_u32(tb[TCA_FQ_CODEL_FLOWS]);
-               fprintf(f, "flows %u ", flows);
+               print_uint(PRINT_ANY, "flows", "flows %u ", flows);
        }
        if (tb[TCA_FQ_CODEL_QUANTUM] &&
            RTA_PAYLOAD(tb[TCA_FQ_CODEL_QUANTUM]) >= sizeof(__u32)) {
                quantum = rta_getattr_u32(tb[TCA_FQ_CODEL_QUANTUM]);
-               fprintf(f, "quantum %u ", quantum);
+               print_uint(PRINT_ANY, "quantum", "quantum %u ", quantum);
        }
        if (tb[TCA_FQ_CODEL_TARGET] &&
            RTA_PAYLOAD(tb[TCA_FQ_CODEL_TARGET]) >= sizeof(__u32)) {
                target = rta_getattr_u32(tb[TCA_FQ_CODEL_TARGET]);
-               fprintf(f, "target %s ", sprint_time(target, b1));
+               print_uint(PRINT_JSON, "target", NULL, target);
+               print_string(PRINT_FP, NULL, "target %s ",
+                            sprint_time(target, b1));
        }
        if (tb[TCA_FQ_CODEL_CE_THRESHOLD] &&
            RTA_PAYLOAD(tb[TCA_FQ_CODEL_CE_THRESHOLD]) >= sizeof(__u32)) {
                ce_threshold = rta_getattr_u32(tb[TCA_FQ_CODEL_CE_THRESHOLD]);
-               fprintf(f, "ce_threshold %s ", sprint_time(ce_threshold, b1));
+               print_uint(PRINT_JSON, "ce_threshold", NULL, ce_threshold);
+               print_string(PRINT_FP, NULL, "ce_threshold %s ",
+                            sprint_time(ce_threshold, b1));
        }
        if (tb[TCA_FQ_CODEL_INTERVAL] &&
            RTA_PAYLOAD(tb[TCA_FQ_CODEL_INTERVAL]) >= sizeof(__u32)) {
                interval = rta_getattr_u32(tb[TCA_FQ_CODEL_INTERVAL]);
-               fprintf(f, "interval %s ", sprint_time(interval, b1));
+               print_uint(PRINT_JSON, "interval", NULL, interval);
+               print_string(PRINT_FP, NULL, "interval %s ",
+                            sprint_time(interval, b1));
+       }
+       if (tb[TCA_FQ_CODEL_MEMORY_LIMIT] &&
+           RTA_PAYLOAD(tb[TCA_FQ_CODEL_MEMORY_LIMIT]) >= sizeof(__u32)) {
+               memory_limit = rta_getattr_u32(tb[TCA_FQ_CODEL_MEMORY_LIMIT]);
+               print_uint(PRINT_JSON, "memory_limit", NULL, memory_limit);
+               print_string(PRINT_FP, NULL, "memory_limit %s ",
+                            sprint_size(memory_limit, b1));
        }
        if (tb[TCA_FQ_CODEL_ECN] &&
            RTA_PAYLOAD(tb[TCA_FQ_CODEL_ECN]) >= sizeof(__u32)) {
                ecn = rta_getattr_u32(tb[TCA_FQ_CODEL_ECN]);
                if (ecn)
-                       fprintf(f, "ecn ");
+                       print_bool(PRINT_ANY, "ecn", "ecn ", true);
        }
 
        return 0;
@@ -201,7 +226,8 @@ static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt
 static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f,
                                 struct rtattr *xstats)
 {
-       struct tc_fq_codel_xstats _st, *st;
+       struct tc_fq_codel_xstats _st = {}, *st;
+
        SPRINT_BUF(b1);
 
        if (xstats == NULL)
@@ -209,36 +235,54 @@ static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f,
 
        st = RTA_DATA(xstats);
        if (RTA_PAYLOAD(xstats) < sizeof(*st)) {
-               memset(&_st, 0, sizeof(_st));
                memcpy(&_st, st, RTA_PAYLOAD(xstats));
                st = &_st;
        }
        if (st->type == TCA_FQ_CODEL_XSTATS_QDISC) {
-               fprintf(f, "  maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u",
-                       st->qdisc_stats.maxpacket,
-                       st->qdisc_stats.drop_overlimit,
-                       st->qdisc_stats.new_flow_count,
+               print_uint(PRINT_ANY, "maxpacket", "  maxpacket %u",
+                       st->qdisc_stats.maxpacket);
+               print_uint(PRINT_ANY, "drop_overlimit", " drop_overlimit %u",
+                       st->qdisc_stats.drop_overlimit);
+               print_uint(PRINT_ANY, "new_flow_count", " new_flow_count %u",
+                       st->qdisc_stats.new_flow_count);
+               print_uint(PRINT_ANY, "ecn_mark", " ecn_mark %u",
                        st->qdisc_stats.ecn_mark);
                if (st->qdisc_stats.ce_mark)
-                       fprintf(f, " ce_mark %u", st->qdisc_stats.ce_mark);
-               fprintf(f, "\n  new_flows_len %u old_flows_len %u",
-                       st->qdisc_stats.new_flows_len,
+                       print_uint(PRINT_ANY, "ce_mark", " ce_mark %u",
+                               st->qdisc_stats.ce_mark);
+               if (st->qdisc_stats.memory_usage)
+                       print_uint(PRINT_ANY, "memory_used", " memory_used %u",
+                               st->qdisc_stats.memory_usage);
+               if (st->qdisc_stats.drop_overmemory)
+                       print_uint(PRINT_ANY, "drop_overmemory", " drop_overmemory %u",
+                               st->qdisc_stats.drop_overmemory);
+               print_uint(PRINT_ANY, "new_flows_len", "\n  new_flows_len %u",
+                       st->qdisc_stats.new_flows_len);
+               print_uint(PRINT_ANY, "old_flows_len", " old_flows_len %u",
                        st->qdisc_stats.old_flows_len);
        }
        if (st->type == TCA_FQ_CODEL_XSTATS_CLASS) {
-               fprintf(f, "  deficit %d count %u lastcount %u ldelay %s",
-                       st->class_stats.deficit,
-                       st->class_stats.count,
-                       st->class_stats.lastcount,
+               print_uint(PRINT_ANY, "deficit", "  deficit %u",
+                       st->class_stats.deficit);
+               print_uint(PRINT_ANY, "count", " count %u",
+                       st->class_stats.count);
+               print_uint(PRINT_ANY, "lastcount", " lastcount %u",
+                       st->class_stats.lastcount);
+               print_uint(PRINT_JSON, "ldelay", NULL,
+                       st->class_stats.ldelay);
+               print_string(PRINT_FP, NULL, " ldelay %s",
                        sprint_time(st->class_stats.ldelay, b1));
                if (st->class_stats.dropping) {
-                       fprintf(f, " dropping");
+                       print_bool(PRINT_ANY, "dropping", " dropping", true);
                        if (st->class_stats.drop_next < 0)
-                               fprintf(f, " drop_next -%s",
+                               print_string(PRINT_FP, NULL, " drop_next -%s",
                                        sprint_time(-st->class_stats.drop_next, b1));
-                       else
-                               fprintf(f, " drop_next %s",
+                       else {
+                               print_uint(PRINT_JSON, "drop_next", NULL,
+                                       st->class_stats.drop_next);
+                               print_string(PRINT_FP, NULL, " drop_next %s",
                                        sprint_time(st->class_stats.drop_next, b1));
+                       }
                }
        }
        return 0;