]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
openvswitch: meter: fix the incorrect calculation of max delta_t
authorzhangliping <zhangliping02@baidu.com>
Fri, 9 Mar 2018 02:08:50 +0000 (10:08 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Mar 2018 16:05:41 +0000 (18:05 +0200)
[ Usptream commit ddc502dfed600bff0b61d899f70d95b76223fdfc ]

Max delat_t should be the full_bucket/rate instead of the full_bucket.
Also report EINVAL if the rate is zero.

Fixes: 96fbc13d7e77 ("openvswitch: Add meter infrastructure")
Cc: Andy Zhou <azhou@ovn.org>
Signed-off-by: zhangliping <zhangliping02@baidu.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/openvswitch/meter.c

index 3fbfc78991ac5748e098dc372727600d0af21ba6..0d961f09d0c7258f0b8057a72704295e3b470bd9 100644 (file)
@@ -242,14 +242,20 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
 
                band->type = nla_get_u32(attr[OVS_BAND_ATTR_TYPE]);
                band->rate = nla_get_u32(attr[OVS_BAND_ATTR_RATE]);
+               if (band->rate == 0) {
+                       err = -EINVAL;
+                       goto exit_free_meter;
+               }
+
                band->burst_size = nla_get_u32(attr[OVS_BAND_ATTR_BURST]);
                /* Figure out max delta_t that is enough to fill any bucket.
                 * Keep max_delta_t size to the bucket units:
                 * pkts => 1/1000 packets, kilobits => bits.
+                *
+                * Start with a full bucket.
                 */
-               band_max_delta_t = (band->burst_size + band->rate) * 1000;
-               /* Start with a full bucket. */
-               band->bucket = band_max_delta_t;
+               band->bucket = (band->burst_size + band->rate) * 1000;
+               band_max_delta_t = band->bucket / band->rate;
                if (band_max_delta_t > meter->max_delta_t)
                        meter->max_delta_t = band_max_delta_t;
                band++;