]> git.proxmox.com Git - mirror_iproute2.git/commit - tc/tc_util.c
tc: util: constrain percentage in 0-100 interval
authorAndrea Claudi <aclaudi@redhat.com>
Sat, 13 Jul 2019 09:44:07 +0000 (11:44 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 15 Jul 2019 20:45:59 +0000 (13:45 -0700)
commit6bc13e4a20f50e9c37d5a504c78222913c433fd3
treea9b0d11421c0964f0185b13da84005822a90758d
parentfda6f26e9b364ffff567a3ae10535c538f7db7a0
tc: util: constrain percentage in 0-100 interval

parse_percent() currently allows to specify negative percentages
or value above 100%. However this does not seems to make sense,
as the function is used for probabilities or bandiwidth rates.

Moreover, using negative values leads to erroneous results
(using Bernoulli loss model as example):

$ ip link add test type dummy
$ ip link set test up
$ tc qdisc add dev test root netem loss gemodel -10% limit 10
$ tc qdisc show dev test
qdisc netem 800c: root refcnt 2 limit 10 loss gemodel p 90% r 10% 1-h 100% 1-k 0%

Using values above 100% we have instead:

$ ip link add test type dummy
$ ip link set test up
$ tc qdisc add dev test root netem loss gemodel 140% limit 10
$ tc qdisc show dev test
qdisc netem 800f: root refcnt 2 limit 10 loss gemodel p 40% r 60% 1-h 100% 1-k 0%

This commit changes parse_percent() with a check to ensure
percentage values stay between 1.0 and 0.0.
parse_percent_rate() function, which already employs a similar
check, is adjusted accordingly.

With this check in place, we have:

$ ip link add test type dummy
$ ip link set test up
$ tc qdisc add dev test root netem loss gemodel -10% limit 10
Illegal "loss gemodel p"

Fixes: 927e3cfb52b58 ("tc: B.W limits can now be specified in %.")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
tc/tc_util.c