]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/q_cbq.c
tc: Remove pointless assignments in batch()
[mirror_iproute2.git] / tc / q_cbq.c
index faad735045aa8d0f7bd62e7daf4379443e2bdfc1..e7f1a3bfaf5dbb2565d4f1bafdab9639d8a2ec06 100644 (file)
@@ -13,7 +13,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -47,10 +46,10 @@ static void explain1(char *arg)
 }
 
 
-static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
+static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
 {
-       struct tc_ratespec r;
-       struct tc_cbq_lssopt lss;
+       struct tc_ratespec r = {};
+       struct tc_cbq_lssopt lss = {};
        __u32 rtab[256];
        unsigned mpu = 0, avpkt = 0, allot = 0;
        unsigned short overhead = 0;
@@ -59,14 +58,16 @@ static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
        int ewma_log =  -1;
        struct rtattr *tail;
 
-       memset(&lss, 0, sizeof(lss));
-       memset(&r, 0, sizeof(r));
-
        while (argc > 0) {
                if (matches(*argv, "bandwidth") == 0 ||
                    matches(*argv, "rate") == 0) {
                        NEXT_ARG();
-                       if (get_rate(&r.rate, *argv)) {
+                       if (strchr(*argv, '%')) {
+                               if (get_percent_rate(&r.rate, *argv, dev)) {
+                                       explain1("bandwidth");
+                                       return -1;
+                               }
+                       } else if (get_rate(&r.rate, *argv)) {
                                explain1("bandwidth");
                                return -1;
                        }
@@ -164,8 +165,7 @@ static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
        lss.change = TCF_CBQ_LSS_MAXIDLE|TCF_CBQ_LSS_EWMA|TCF_CBQ_LSS_AVPKT;
        lss.avpkt = avpkt;
 
-       tail = NLMSG_TAIL(n);
-       addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
+       tail = addattr_nest(n, 1024, TCA_OPTIONS);
        addattr_l(n, 1024, TCA_CBQ_RATE, &r, sizeof(r));
        addattr_l(n, 1024, TCA_CBQ_LSSOPT, &lss, sizeof(lss));
        addattr_l(n, 3024, TCA_CBQ_RTAB, rtab, 1024);
@@ -176,18 +176,17 @@ static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
                        printf("%u ", rtab[i]);
                printf("\n");
        }
-       tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
+       addattr_nest_end(n, tail);
        return 0;
 }
 
-static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
+static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
 {
        int wrr_ok = 0, fopt_ok = 0;
-       struct tc_ratespec r;
-       struct tc_cbq_lssopt lss;
-       struct tc_cbq_wrropt wrr;
-       struct tc_cbq_fopt fopt;
-       struct tc_cbq_ovl ovl;
+       struct tc_ratespec r = {};
+       struct tc_cbq_lssopt lss = {};
+       struct tc_cbq_wrropt wrr = {};
+       struct tc_cbq_fopt fopt = {};
        __u32 rtab[256];
        unsigned mpu = 0;
        int cell_log =  -1;
@@ -198,22 +197,26 @@ static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
        unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
        struct rtattr *tail;
 
-       memset(&r, 0, sizeof(r));
-       memset(&lss, 0, sizeof(lss));
-       memset(&wrr, 0, sizeof(wrr));
-       memset(&fopt, 0, sizeof(fopt));
-       memset(&ovl, 0, sizeof(ovl));
-
        while (argc > 0) {
                if (matches(*argv, "rate") == 0) {
                        NEXT_ARG();
-                       if (get_rate(&r.rate, *argv)) {
+                       if (strchr(*argv, '%')) {
+                               if (get_percent_rate(&r.rate, *argv, dev)) {
+                                       explain1("rate");
+                                       return -1;
+                               }
+                       } else if (get_rate(&r.rate, *argv)) {
                                explain1("rate");
                                return -1;
                        }
                } else if (matches(*argv, "bandwidth") == 0) {
                        NEXT_ARG();
-                       if (get_rate(&bndw, *argv)) {
+                       if (strchr(*argv, '%')) {
+                               if (get_percent_rate(&bndw, *argv, dev)) {
+                                       explain1("bandwidth");
+                                       return -1;
+                               }
+                       } else if (get_rate(&bndw, *argv)) {
                                explain1("bandwidth");
                                return -1;
                        }
@@ -415,8 +418,7 @@ static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
                lss.change |= TCF_CBQ_LSS_EWMA;
        }
 
-       tail = NLMSG_TAIL(n);
-       addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
+       tail = addattr_nest(n, 1024, TCA_OPTIONS);
        if (lss.change) {
                lss.change |= TCF_CBQ_LSS_FLAGS;
                addattr_l(n, 1024, TCA_CBQ_LSSOPT, &lss, sizeof(lss));
@@ -436,7 +438,7 @@ static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
                        printf("\n");
                }
        }
-       tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
+       addattr_nest_end(n, tail);
        return 0;
 }