]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tc: use bits not mbits/sec in rate percent
authorMarcos Antonio Moraes <marcos.antonio@digirati.com.br>
Thu, 7 Feb 2019 15:29:54 +0000 (13:29 -0200)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 8 Feb 2019 17:59:45 +0000 (09:59 -0800)
As /sys/class/net/<iface>/speed indicates a value in Mbits/sec, the
conversion is necessary to create the correct limits.

This guarantees the same result for the following commands in an
1000Mbit/sec device:

tc class add ... htb rate 500Mbit
tc class add ... htb rate 50%

Fixes: 927e3cfb52b5 ("tc: B.W limits can now be specified in %.")
Signed-off-by: Marcos Antonio Moraes <marcos.antonio@digirati.com.br>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
tc/tc_util.c

index 4e289ae9c2ade87f6b505f69cb0c9e27a4f7d0a1..07216fba38e755a5300186b767dd8db736edb5de 100644 (file)
@@ -195,7 +195,7 @@ static int parse_percent_rate(char *rate, size_t len,
 {
        long dev_mbit;
        int ret;
-       double perc, rate_mbit;
+       double perc, rate_bit;
        char *str_perc = NULL;
 
        if (!dev[0]) {
@@ -220,9 +220,9 @@ static int parse_percent_rate(char *rate, size_t len,
                return -1;
        }
 
-       rate_mbit = perc * dev_mbit;
+       rate_bit = perc * dev_mbit * 1000 * 1000;
 
-       ret = snprintf(rate, len, "%lf", rate_mbit);
+       ret = snprintf(rate, len, "%lf", rate_bit);
        if (ret <= 0 || ret >= len) {
                fprintf(stderr, "Unable to parse calculated rate\n");
                return -1;