Commit eb6d7d6a authored by David Ward's avatar David Ward Committed by Stephen Hemminger

tc: gred: Handle unsigned values properly in option parsing/printing

DPs, def_DP, and DP are unsigned values that are sent and received
in TCA_GRED_* netlink attributes; handle them properly when they
are parsed or printed. Use MAX_DPs as the initial value for def_DP
and DP, and fix the operator used for bounds checking them.
Signed-off-by: default avatarDavid Ward <david.ward@ll.mit.edu>
parent 1693a4d3
...@@ -53,34 +53,34 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv, ...@@ -53,34 +53,34 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
struct rtattr *tail; struct rtattr *tail;
struct tc_gred_sopt opt = { 0 }; struct tc_gred_sopt opt = { 0 };
int dps = 0;
int def_dp = -1; opt.def_DP = MAX_DPs;
while (argc > 0) { while (argc > 0) {
DPRINTF(stderr,"init_gred: invoked with %s\n",*argv); DPRINTF(stderr,"init_gred: invoked with %s\n",*argv);
if (strcmp(*argv, "DPs") == 0) { if (strcmp(*argv, "DPs") == 0) {
NEXT_ARG(); NEXT_ARG();
DPRINTF(stderr,"init_gred: next_arg with %s\n",*argv); if (get_unsigned(&opt.DPs, *argv, 10)) {
dps = strtol(*argv, (char **)NULL, 10);
if (dps < 0 || dps >MAX_DPs) {
fprintf(stderr, "DPs =%d\n", dps);
fprintf(stderr, "Illegal \"DPs\"\n"); fprintf(stderr, "Illegal \"DPs\"\n");
fprintf(stderr, "GRED: only %d DPs are " return -1;
"currently supported\n",MAX_DPs); } else if (opt.DPs > MAX_DPs) {
fprintf(stderr, "GRED: only %u DPs are "
"currently supported\n", MAX_DPs);
return -1; return -1;
} }
} else if (strcmp(*argv, "default") == 0) { } else if (strcmp(*argv, "default") == 0) {
NEXT_ARG(); if (opt.DPs == 0) {
def_dp = strtol(*argv, (char **)NULL, 10); fprintf(stderr, "\"default\" must be defined "
if (dps == 0) { "after \"DPs\"\n");
fprintf(stderr, "\"default DP\" must be "
"defined after DPs\n");
return -1; return -1;
} }
if (def_dp < 0 || def_dp > dps) { NEXT_ARG();
fprintf(stderr, if (get_unsigned(&opt.def_DP, *argv, 10)) {
"\"default DP\" must be less than %d\n", fprintf(stderr, "Illegal \"default\"\n");
opt.DPs); return -1;
} else if (opt.def_DP >= opt.DPs) {
fprintf(stderr, "\"default\" must be less than "
"\"DPs\"\n");
return -1; return -1;
} }
} else if (strcmp(*argv, "grio") == 0) { } else if (strcmp(*argv, "grio") == 0) {
...@@ -96,15 +96,12 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv, ...@@ -96,15 +96,12 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
argc--; argv++; argc--; argv++;
} }
if (!dps || def_dp == -1) { if (!opt.DPs || opt.def_DP == MAX_DPs) {
fprintf(stderr, "Illegal gred setup parameters \n"); fprintf(stderr, "Illegal gred setup parameters \n");
return -1; return -1;
} }
opt.DPs = dps; DPRINTF("TC_GRED: sending DPs=%u def_DP=%u\n",opt.DPs,opt.def_DP);
opt.def_DP = def_dp;
DPRINTF("TC_GRED: sending DPs=%d default=%d\n",opt.DPs,opt.def_DP);
n->nlmsg_flags|=NLM_F_CREATE; n->nlmsg_flags|=NLM_F_CREATE;
tail = NLMSG_TAIL(n); tail = NLMSG_TAIL(n);
addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
...@@ -118,7 +115,7 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv, ...@@ -118,7 +115,7 @@ 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) 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; struct tc_gred_qopt opt = { 0 };
unsigned burst = 0; unsigned burst = 0;
unsigned avpkt = 0; unsigned avpkt = 0;
double probability = 0.02; double probability = 0.02;
...@@ -128,7 +125,7 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n ...@@ -128,7 +125,7 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
struct rtattr *tail; struct rtattr *tail;
__u32 max_P; __u32 max_P;
memset(&opt, 0, sizeof(opt)); opt.DP = MAX_DPs;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "limit") == 0) { if (strcmp(*argv, "limit") == 0) {
...@@ -160,14 +157,14 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n ...@@ -160,14 +157,14 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
ok++; ok++;
} else if (strcmp(*argv, "DP") == 0) { } else if (strcmp(*argv, "DP") == 0) {
NEXT_ARG(); NEXT_ARG();
opt.DP=strtol(*argv, (char **)NULL, 10); if (get_unsigned(&opt.DP, *argv, 10)) {
DPRINTF ("\n ******* DP =%u\n",opt.DP);
if (opt.DP >MAX_DPs) { /* need a better error check */
fprintf(stderr, "DP =%u \n",opt.DP);
fprintf(stderr, "Illegal \"DP\"\n"); fprintf(stderr, "Illegal \"DP\"\n");
fprintf(stderr, "GRED: only %d DPs are currently supported\n",MAX_DPs);
return -1; return -1;
} } else if (opt.DP >= MAX_DPs) {
fprintf(stderr, "GRED: only %u DPs are "
"currently supported\n", MAX_DPs);
return -1;
} /* need a better error check */
ok++; ok++;
} else if (strcmp(*argv, "burst") == 0) { } else if (strcmp(*argv, "burst") == 0) {
NEXT_ARG(); NEXT_ARG();
...@@ -217,10 +214,10 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n ...@@ -217,10 +214,10 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
explain(); explain();
return -1; return -1;
} }
if (!opt.qth_min || !opt.qth_max || !opt.limit || !avpkt || if (opt.DP == MAX_DPs || !opt.limit || !opt.qth_min || !opt.qth_max ||
(opt.DP<0)) { !avpkt) {
fprintf(stderr, "Required parameter (min, max, limit, " fprintf(stderr, "Required parameter (DP, limit, min, max, "
"avpkt, DP) is missing\n"); "avpkt) is missing\n");
return -1; return -1;
} }
if (!burst) { if (!burst) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment