diff options
Diffstat (limited to 'tc/q_netem.c')
-rw-r--r-- | tc/q_netem.c | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/tc/q_netem.c b/tc/q_netem.c index 7bc8c6a5..cdaddce9 100644 --- a/tc/q_netem.c +++ b/tc/q_netem.c @@ -30,10 +30,10 @@ static void explain(void) { fprintf(stderr, -"Usage: ... netem [ limit PACKETS ] \n" \ +"Usage: ... netem [ limit PACKETS ]\n" \ " [ delay TIME [ JITTER [CORRELATION]]]\n" \ " [ distribution {uniform|normal|pareto|paretonormal} ]\n" \ -" [ corrupt PERCENT [CORRELATION]] \n" \ +" [ corrupt PERCENT [CORRELATION]]\n" \ " [ duplicate PERCENT [CORRELATION]]\n" \ " [ loss random PERCENT [CORRELATION]]\n" \ " [ loss state P13 [P31 [P32 [P23 P14]]]\n" \ @@ -58,7 +58,7 @@ static const double max_percent_value = 0xffffffff; /* scaled value used to percent of maximum. */ static void set_percent(__u32 *percent, double per) { - *percent = (unsigned) rint(per * max_percent_value); + *percent = (unsigned int) rint(per * max_percent_value); } @@ -70,7 +70,7 @@ static int parse_percent(double *val, const char *str) char *p; *val = strtod(str, &p) / 100.; - if (*p && strcmp(p, "%") ) + if (*p && strcmp(p, "%")) return -1; return 0; @@ -92,7 +92,7 @@ static void print_percent(char *buf, int len, __u32 per) snprintf(buf, len, "%g%%", 100. * (double) per / max_percent_value); } -static char * sprint_percent(__u32 per, char *buf) +static char *sprint_percent(__u32 per, char *buf) { print_percent(buf, SPRINT_BSIZE-1, per); return buf; @@ -123,6 +123,7 @@ static int get_distribution(const char *type, __s16 *data, int maxdata) n = 0; while (getline(&line, &len, f) != -1) { char *p, *endp; + if (*line == '\n' || *line == '#') continue; @@ -154,9 +155,9 @@ static int get_distribution(const char *type, __s16 *data, int maxdata) (based on kernel PSCHED_CLOCK configuration */ static int get_ticks(__u32 *ticks, const char *str) { - unsigned t; + unsigned int t; - if(get_time(&t, str)) + if (get_time(&t, str)) return -1; if (tc_core_time2big(t)) { @@ -174,24 +175,18 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, int dist_size = 0; struct rtattr *tail; struct tc_netem_qopt opt = { .limit = 1000 }; - struct tc_netem_corr cor; - struct tc_netem_reorder reorder; - struct tc_netem_corrupt corrupt; + struct tc_netem_corr cor = {}; + struct tc_netem_reorder reorder = {}; + struct tc_netem_corrupt corrupt = {}; struct tc_netem_gimodel gimodel; struct tc_netem_gemodel gemodel; - struct tc_netem_rate rate; + struct tc_netem_rate rate = {}; __s16 *dist_data = NULL; __u16 loss_type = NETEM_LOSS_UNSPEC; - int present[__TCA_NETEM_MAX]; + int present[__TCA_NETEM_MAX] = {}; __u64 rate64 = 0; - memset(&cor, 0, sizeof(cor)); - memset(&reorder, 0, sizeof(reorder)); - memset(&corrupt, 0, sizeof(corrupt)); - memset(&rate, 0, sizeof(rate)); - memset(present, 0, sizeof(present)); - - for( ; argc > 0; --argc, ++argv) { + for ( ; argc > 0; --argc, ++argv) { if (matches(*argv, "limit") == 0) { NEXT_ARG(); if (get_size(&opt.limit, *argv)) { @@ -236,7 +231,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, if (!strcmp(*argv, "random")) { NEXT_ARG(); - random_loss_model: + random_loss_model: if (get_percent(&opt.loss, *argv)) { explain1("loss percent"); return -1; @@ -343,7 +338,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, return -1; } } else if (matches(*argv, "ecn") == 0) { - present[TCA_NETEM_ECN] = 1; + present[TCA_NETEM_ECN] = 1; } else if (matches(*argv, "reorder") == 0) { NEXT_ARG(); present[TCA_NETEM_REORDER] = 1; @@ -474,7 +469,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, if (present[TCA_NETEM_CORR] && addattr_l(n, 1024, TCA_NETEM_CORR, &cor, sizeof(cor)) < 0) - return -1; + return -1; if (present[TCA_NETEM_REORDER] && addattr_l(n, 1024, TCA_NETEM_REORDER, &reorder, sizeof(reorder)) < 0) @@ -483,7 +478,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, if (present[TCA_NETEM_ECN] && addattr_l(n, 1024, TCA_NETEM_ECN, &present[TCA_NETEM_ECN], sizeof(present[TCA_NETEM_ECN])) < 0) - return -1; + return -1; if (present[TCA_NETEM_CORRUPT] && addattr_l(n, 1024, TCA_NETEM_CORRUPT, &corrupt, sizeof(corrupt)) < 0) @@ -496,11 +491,11 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, if (loss_type == NETEM_LOSS_GI) { if (addattr_l(n, 1024, NETEM_LOSS_GI, &gimodel, sizeof(gimodel)) < 0) - return -1; + return -1; } else if (loss_type == NETEM_LOSS_GE) { if (addattr_l(n, 1024, NETEM_LOSS_GE, &gemodel, sizeof(gemodel)) < 0) - return -1; + return -1; } else { fprintf(stderr, "loss in the weeds!\n"); return -1; @@ -543,13 +538,15 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) int *ecn = NULL; struct tc_netem_qopt qopt; const struct tc_netem_rate *rate = NULL; - int len = RTA_PAYLOAD(opt) - sizeof(qopt); + int len; __u64 rate64 = 0; + SPRINT_BUF(b1); if (opt == NULL) return 0; + len = RTA_PAYLOAD(opt) - sizeof(qopt); if (len < 0) { fprintf(stderr, "options size error\n"); return -1; @@ -558,6 +555,7 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) if (len > 0) { struct rtattr *tb[TCA_NETEM_MAX+1]; + parse_rtattr(tb, TCA_NETEM_MAX, RTA_DATA(opt) + sizeof(qopt), len); @@ -684,7 +682,7 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) } struct qdisc_util netem_qdisc_util = { - .id = "netem", + .id = "netem", .parse_qopt = netem_parse_opt, .print_qopt = netem_print_opt, }; |