Skip to content

Commit ddc502d

Browse files
zhanglipingdavem330
authored andcommitted
openvswitch: meter: fix the incorrect calculation of max delta_t
Max delat_t should be the full_bucket/rate instead of the full_bucket. Also report EINVAL if the rate is zero. Fixes: 96fbc13 ("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>
1 parent 13fbcc8 commit ddc502d

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎net/openvswitch/meter.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,20 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
242242

243243
band->type = nla_get_u32(attr[OVS_BAND_ATTR_TYPE]);
244244
band->rate = nla_get_u32(attr[OVS_BAND_ATTR_RATE]);
245+
if (band->rate == 0) {
246+
err = -EINVAL;
247+
goto exit_free_meter;
248+
}
249+
245250
band->burst_size = nla_get_u32(attr[OVS_BAND_ATTR_BURST]);
246251
/* Figure out max delta_t that is enough to fill any bucket.
247252
* Keep max_delta_t size to the bucket units:
248253
* pkts => 1/1000 packets, kilobits => bits.
254+
*
255+
* Start with a full bucket.
249256
*/
250-
band_max_delta_t = (band->burst_size + band->rate) * 1000;
251-
/* Start with a full bucket. */
252-
band->bucket = band_max_delta_t;
257+
band->bucket = (band->burst_size + band->rate) * 1000;
258+
band_max_delta_t = band->bucket / band->rate;
253259
if (band_max_delta_t > meter->max_delta_t)
254260
meter->max_delta_t = band_max_delta_t;
255261
band++;

0 commit comments

Comments
 (0)