diff options
author | Stephen Hemminger <shemminger@osdl.org> | 2007-01-09 15:46:55 -0800 |
---|---|---|
committer | Stephen Hemminger <shemminger@osdl.org> | 2007-01-09 15:46:55 -0800 |
commit | 40076f622e0aacb2b792d3ac1b5d12aa97c4da9c (patch) | |
tree | 8e6389d4223774c01dcb8720f5c27616e47014e0 /tc | |
parent | 02e9f72fd980912c5572d0c529600001f354b5f4 (diff) |
netem parameters to change command
When using tc to change netem attributes, only those values
on the command line should be passed down, others should
remain unchanged.
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Diffstat (limited to 'tc')
-rw-r--r-- | tc/q_netem.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/tc/q_netem.c b/tc/q_netem.c index a3ae71c1..cfd17995 100644 --- a/tc/q_netem.c +++ b/tc/q_netem.c @@ -136,12 +136,14 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct tc_netem_reorder reorder; struct tc_netem_corrupt corrupt; __s16 *dist_data = NULL; + int present[__TCA_NETEM_MAX]; memset(&opt, 0, sizeof(opt)); opt.limit = 1000; memset(&cor, 0, sizeof(cor)); memset(&reorder, 0, sizeof(reorder)); memset(&corrupt, 0, sizeof(corrupt)); + memset(present, 0, sizeof(present)); while (argc > 0) { if (matches(*argv, "limit") == 0) { @@ -167,8 +169,8 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, if (NEXT_IS_NUMBER()) { NEXT_ARG(); - if (get_percent(&cor.delay_corr, - *argv)) { + ++present[TCA_NETEM_CORR]; + if (get_percent(&cor.delay_corr, *argv)) { explain1("latency"); return -1; } @@ -183,6 +185,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, } if (NEXT_IS_NUMBER()) { NEXT_ARG(); + ++present[TCA_NETEM_CORR]; if (get_percent(&cor.loss_corr, *argv)) { explain1("loss"); return -1; @@ -190,12 +193,14 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, } } else if (matches(*argv, "reorder") == 0) { NEXT_ARG(); + present[TCA_NETEM_REORDER] = 1; if (get_percent(&reorder.probability, *argv)) { explain1("reorder"); return -1; } if (NEXT_IS_NUMBER()) { NEXT_ARG(); + ++present[TCA_NETEM_CORR]; if (get_percent(&reorder.correlation, *argv)) { explain1("reorder"); return -1; @@ -203,12 +208,14 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, } } else if (matches(*argv, "corrupt") == 0) { NEXT_ARG(); + present[TCA_NETEM_CORRUPT] = 1; if (get_percent(&corrupt.probability, *argv)) { explain1("corrupt"); return -1; } if (NEXT_IS_NUMBER()) { NEXT_ARG(); + ++present[TCA_NETEM_CORR]; if (get_percent(&corrupt.correlation, *argv)) { explain1("corrupt"); return -1; @@ -273,18 +280,17 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, if (addattr_l(n, TCA_BUF_MAX, TCA_OPTIONS, &opt, sizeof(opt)) < 0) return -1; - if (cor.delay_corr || cor.loss_corr || cor.dup_corr) { - if (addattr_l(n, TCA_BUF_MAX, TCA_NETEM_CORR, &cor, sizeof(cor)) < 0) + if (present[TCA_NETEM_CORR] && + addattr_l(n, TCA_BUF_MAX, TCA_NETEM_CORR, &cor, sizeof(cor)) < 0) return -1; - } - if (addattr_l(n, TCA_BUF_MAX, TCA_NETEM_REORDER, &reorder, sizeof(reorder)) < 0) + if (present[TCA_NETEM_REORDER] && + addattr_l(n, TCA_BUF_MAX, TCA_NETEM_REORDER, &reorder, sizeof(reorder)) < 0) return -1; - if (corrupt.probability) { - if (addattr_l(n, TCA_BUF_MAX, TCA_NETEM_CORRUPT, &corrupt, sizeof(corrupt)) < 0) - return -1; - } + if (present[TCA_NETEM_CORRUPT] && + addattr_l(n, TCA_BUF_MAX, TCA_NETEM_CORRUPT, &corrupt, sizeof(corrupt)) < 0) + return -1; if (dist_data) { if (addattr_l(n, 32768, TCA_NETEM_DELAY_DIST, |