]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/q_choke.c
bridge: fdb: add support for src_vni option
[mirror_iproute2.git] / tc / q_choke.c
index 6fbcadf308b3afe3228c651bf8802fb91163ccea..1353c80c806ba1bea44ce3c066c51166cca480ec 100644 (file)
@@ -12,7 +12,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -32,21 +31,19 @@ static void explain(void)
 }
 
 static int choke_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-                          struct nlmsghdr *n)
+                          struct nlmsghdr *n, const char *dev)
 {
-       struct tc_red_qopt opt;
-       unsigned burst = 0;
-       unsigned avpkt = 1000;
+       struct tc_red_qopt opt = {};
+       unsigned int burst = 0;
+       unsigned int avpkt = 1000;
        double probability = 0.02;
-       unsigned rate = 0;
+       unsigned int rate = 0;
        int ecn_ok = 0;
        int wlog;
        __u8 sbuf[256];
        __u32 max_P;
        struct rtattr *tail;
 
-       memset(&opt, 0, sizeof(opt));
-
        while (argc > 0) {
                if (strcmp(*argv, "limit") == 0) {
                        NEXT_ARG();
@@ -56,7 +53,12 @@ static int choke_parse_opt(struct qdisc_util *qu, int argc, char **argv,
                        }
                } else if (strcmp(*argv, "bandwidth") == 0) {
                        NEXT_ARG();
-                       if (get_rate(&rate, *argv)) {
+                       if (strchr(*argv, '%')) {
+                               if (get_percent_rate(&rate, *argv, dev)) {
+                                       fprintf(stderr, "Illegal \"bandwidth\"\n");
+                                       return -1;
+                               }
+                       } else if (get_rate(&rate, *argv)) {
                                fprintf(stderr, "Illegal \"bandwidth\"\n");
                                return -1;
                        }
@@ -108,11 +110,11 @@ static int choke_parse_opt(struct qdisc_util *qu, int argc, char **argv,
                return -1;
        }
 
-       /* Compute default min/max thresholds based on 
+       /* Compute default min/max thresholds based on
           Sally Floyd's recommendations:
           http://www.icir.org/floyd/REDparameters.txt
        */
-       if (!opt.qth_max) 
+       if (!opt.qth_max)
                opt.qth_max = opt.limit / 4;
        if (!opt.qth_min)
                opt.qth_min = opt.qth_max / 3;
@@ -154,13 +156,12 @@ static int choke_parse_opt(struct qdisc_util *qu, int argc, char **argv,
        if (ecn_ok)
                opt.flags |= TC_RED_ECN;
 
-       tail = NLMSG_TAIL(n);
-       addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
+       tail = addattr_nest(n, 1024, TCA_OPTIONS);
        addattr_l(n, 1024, TCA_CHOKE_PARMS, &opt, sizeof(opt));
        addattr_l(n, 1024, TCA_CHOKE_STAB, sbuf, 256);
        max_P = probability * pow(2, 32);
        addattr_l(n, 1024, TCA_CHOKE_MAX_P, &max_P, sizeof(max_P));
-       tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
+       addattr_nest_end(n, tail);
        return 0;
 }
 
@@ -187,8 +188,7 @@ static int choke_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
        fprintf(f, "limit %up min %up max %up ",
                qopt->limit, qopt->qth_min, qopt->qth_max);
 
-       if (qopt->flags & TC_RED_ECN)
-               fprintf(f, "ecn ");
+       tc_red_print_flags(qopt->flags);
 
        if (show_details) {
                fprintf(f, "ewma %u ", qopt->Wlog);