From ffcf81c99d1cf9a6f7c93b24d0cde044e7ff9231 Mon Sep 17 00:00:00 2001 From: Navdeep Parhar Date: Wed, 25 Jul 2018 17:20:54 +0000 Subject: [PATCH] cxgbetool(8): Require and validate only those inputs that are applicable to the type of rate limiter being configured. For example, the class WRR scheduler doesn't need any kbps limits (it just needs the weights for each class), the channel scheduler doesn't need anything except the aggregate kbps to limit the channel to, and so on. MFC after: 3 days Sponsored by: Chelsio Communications --- usr.sbin/cxgbetool/cxgbetool.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/usr.sbin/cxgbetool/cxgbetool.c b/usr.sbin/cxgbetool/cxgbetool.c index 117f88866a05..6cf9fefd46cc 100644 --- a/usr.sbin/cxgbetool/cxgbetool.c +++ b/usr.sbin/cxgbetool/cxgbetool.c @@ -2862,15 +2862,20 @@ sched_class(int argc, const char *argv[]) warnx("sched params \"level\" parameter missing"); errs++; } - if (op.u.params.mode < 0) { + if (op.u.params.mode < 0 && + op.u.params.level == SCHED_CLASS_LEVEL_CL_RL) { warnx("sched params \"mode\" parameter missing"); errs++; } - if (op.u.params.rateunit < 0) { + if (op.u.params.rateunit < 0 && + (op.u.params.level == SCHED_CLASS_LEVEL_CL_RL || + op.u.params.level == SCHED_CLASS_LEVEL_CH_RL)) { warnx("sched params \"rate-unit\" parameter missing"); errs++; } - if (op.u.params.ratemode < 0) { + if (op.u.params.ratemode < 0 && + (op.u.params.level == SCHED_CLASS_LEVEL_CL_RL || + op.u.params.level == SCHED_CLASS_LEVEL_CH_RL)) { warnx("sched params \"rate-mode\" parameter missing"); errs++; } @@ -2878,7 +2883,9 @@ sched_class(int argc, const char *argv[]) warnx("sched params \"channel\" missing"); errs++; } - if (op.u.params.cl < 0) { + if (op.u.params.cl < 0 && + (op.u.params.level == SCHED_CLASS_LEVEL_CL_RL || + op.u.params.level == SCHED_CLASS_LEVEL_CL_WRR)) { warnx("sched params \"class\" missing"); errs++; } @@ -2889,15 +2896,14 @@ sched_class(int argc, const char *argv[]) "rate-limit level"); errs++; } - if (op.u.params.weight < 0 && - op.u.params.level == SCHED_CLASS_LEVEL_CL_WRR) { - warnx("sched params \"weight\" missing for " - "weighted-round-robin level"); + if (op.u.params.level == SCHED_CLASS_LEVEL_CL_WRR && + (op.u.params.weight < 1 || op.u.params.weight > 99)) { + warnx("sched params \"weight\" missing or invalid " + "(not 1-99) for weighted-round-robin level"); errs++; } if (op.u.params.pktsize < 0 && - (op.u.params.level == SCHED_CLASS_LEVEL_CL_RL || - op.u.params.level == SCHED_CLASS_LEVEL_CH_RL)) { + op.u.params.level == SCHED_CLASS_LEVEL_CL_RL) { warnx("sched params \"pkt-size\" missing for " "rate-limit level"); errs++;