]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/q_gred.c
tc: code cleanup
[mirror_iproute2.git] / tc / q_gred.c
index f31daa37ddc975d93c7d945f6914fb33e073f308..0a9894966c82d529ea14a45a10d1cc35e2f39ca0 100644 (file)
@@ -30,9 +30,9 @@
 
 
 #if 0
-#define DPRINTF(format,args...) fprintf(stderr,format,##args)
+#define DPRINTF(format, args...) fprintf(stderr, format, ##args)
 #else
-#define DPRINTF(format,args...)
+#define DPRINTF(format, args...)
 #endif
 
 static void explain(void)
@@ -55,7 +55,7 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
        opt.def_DP = MAX_DPs;
 
        while (argc > 0) {
-               DPRINTF(stderr,"init_gred: invoked with %s\n",*argv);
+               DPRINTF(stderr, "init_gred: invoked with %s\n", *argv);
                if (strcmp(*argv, "vqs") == 0 ||
                    strcmp(*argv, "DPs") == 0) {
                        NEXT_ARG();
@@ -63,14 +63,13 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
                                fprintf(stderr, "Illegal \"vqs\"\n");
                                return -1;
                        } else if (opt.DPs > MAX_DPs) {
-                               fprintf(stderr, "GRED: only %u VQs are "
-                                       "currently supported\n", MAX_DPs);
+                               fprintf(stderr, "GRED: only %u VQs are currently supported\n",
+                                       MAX_DPs);
                                return -1;
                        }
                } else if (strcmp(*argv, "default") == 0) {
                        if (opt.DPs == 0) {
-                               fprintf(stderr, "\"default\" must be defined "
-                                       "after \"vqs\"\n");
+                               fprintf(stderr, "\"default\" must be defined after \"vqs\"\n");
                                return -1;
                        }
                        NEXT_ARG();
@@ -78,8 +77,7 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
                                fprintf(stderr, "Illegal \"default\"\n");
                                return -1;
                        } else if (opt.def_DP >= opt.DPs) {
-                               fprintf(stderr, "\"default\" must be less than "
-                                       "\"vqs\"\n");
+                               fprintf(stderr, "\"default\" must be less than \"vqs\"\n");
                                return -1;
                        }
                } else if (strcmp(*argv, "grio") == 0) {
@@ -102,12 +100,12 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
        }
 
        if (!opt.DPs || opt.def_DP == MAX_DPs) {
-               fprintf(stderr, "Illegal gred setup parameters \n");
+               fprintf(stderr, "Illegal gred setup parameters\n");
                return -1;
        }
 
-       DPRINTF("TC_GRED: sending DPs=%u def_DP=%u\n",opt.DPs,opt.def_DP);
-       n->nlmsg_flags|=NLM_F_CREATE;
+       DPRINTF("TC_GRED: sending DPs=%u def_DP=%u\n", opt.DPs, opt.def_DP);
+       n->nlmsg_flags |= NLM_F_CREATE;
        tail = NLMSG_TAIL(n);
        addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
        addattr_l(n, 1024, TCA_GRED_DPS, &opt, sizeof(struct tc_gred_sopt));
@@ -121,12 +119,12 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
 */
 static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
-       int ok=0;
+       int ok = 0;
        struct tc_gred_qopt opt = { 0 };
-       unsigned burst = 0;
-       unsigned avpkt = 0;
+       unsigned int burst = 0;
+       unsigned int avpkt = 0;
        double probability = 0.02;
-       unsigned rate = 0;
+       unsigned int rate = 0;
        int parm;
        __u8 sbuf[256];
        struct rtattr *tail;
@@ -169,8 +167,8 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
                                fprintf(stderr, "Illegal \"vq\"\n");
                                return -1;
                        } else if (opt.DP >= MAX_DPs) {
-                               fprintf(stderr, "GRED: only %u VQs are "
-                                       "currently supported\n", MAX_DPs);
+                               fprintf(stderr, "GRED: only %u VQs are currently supported\n",
+                                       MAX_DPs);
                                return -1;
                        } /* need a better error check */
                        ok++;
@@ -197,7 +195,7 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
                        ok++;
                } else if (strcmp(*argv, "prio") == 0) {
                        NEXT_ARG();
-                       opt.prio=strtol(*argv, (char **)NULL, 10);
+                       opt.prio = strtol(*argv, (char **)NULL, 10);
                        /* some error check here */
                        ok++;
                } else if (strcmp(*argv, "bandwidth") == 0) {
@@ -224,8 +222,7 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
        }
        if (opt.DP == MAX_DPs || !opt.limit || !opt.qth_min || !opt.qth_max ||
            !avpkt) {
-               fprintf(stderr, "Required parameter (vq, limit, min, max, "
-                       "avpkt) is missing\n");
+               fprintf(stderr, "Required parameter (vq, limit, min, max, avpkt) is missing\n");
                return -1;
        }
        if (!burst) {
@@ -241,8 +238,8 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
                return -1;
        }
        if (parm >= 10)
-               fprintf(stderr, "GRED: WARNING. Burst %u seems to be too "
-                   "large.\n", burst);
+               fprintf(stderr, "GRED: WARNING. Burst %u seems to be too large.\n",
+                   burst);
        opt.Wlog = parm;
        if ((parm = tc_red_eval_P(opt.qth_min, opt.qth_max, probability)) < 0) {
                fprintf(stderr, "GRED: failed to calculate probability.\n");
@@ -251,8 +248,7 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
        opt.Plog = parm;
        if ((parm = tc_red_eval_idle_damping(opt.Wlog, avpkt, rate, sbuf)) < 0)
            {
-               fprintf(stderr, "GRED: failed to calculate idle damping "
-                   "table.\n");
+               fprintf(stderr, "GRED: failed to calculate idle damping table.\n");
                return -1;
        }
        opt.Scell_log = parm;
@@ -274,7 +270,8 @@ static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
        struct tc_gred_qopt *qopt;
        __u32 *max_p = NULL;
        __u32 *limit = NULL;
-       unsigned i;
+       unsigned int i;
+
        SPRINT_BUF(b1);
        SPRINT_BUF(b2);
        SPRINT_BUF(b3);
@@ -299,7 +296,7 @@ static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
        qopt = RTA_DATA(tb[TCA_GRED_PARMS]);
        if (RTA_PAYLOAD(tb[TCA_GRED_DPS]) < sizeof(*sopt) ||
            RTA_PAYLOAD(tb[TCA_GRED_PARMS]) < sizeof(*qopt)*MAX_DPs) {
-               fprintf(f,"\n GRED received message smaller than expected\n");
+               fprintf(f, "\n GRED received message smaller than expected\n");
                return -1;
        }
 
@@ -314,7 +311,7 @@ static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
                fprintf(f, "limit %s ",
                        sprint_size(*limit, b1));
 
-       for (i=0;i<MAX_DPs;i++, qopt++) {
+       for (i = 0; i < MAX_DPs; i++, qopt++) {
                if (qopt->DP >= MAX_DPs) continue;
                fprintf(f, "\n vq %u prio %hhu limit %s min %s max %s ",
                        qopt->DP,