2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-27 15:18:06 +00:00

datapath: Make 100 percents packets sampled when sampling rate is 1.

When sampling rate is 1, the sampling probability is UINT32_MAX. The packet
should be sampled even the prandom32() generate the number of UINT32_MAX.
And none packet need be sampled when the probability is 0.

Signed-off-by: Wenyu Zhang <wenyuz@vmware.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Upstream: e05176a3283 ("openvswitch: Make 100 percents packets
sampled when sampling rate is 1.")

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
This commit is contained in:
Wenyu Zhang
2015-08-24 20:56:44 -07:00
committed by Pravin B Shelar
parent 6c52e6d8c0
commit c02c4967b9

View File

@@ -681,9 +681,12 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
a = nla_next(a, &rem)) {
u32 probability;
switch (nla_type(a)) {
case OVS_SAMPLE_ATTR_PROBABILITY:
if (prandom_u32() >= nla_get_u32(a))
probability = nla_get_u32(a);
if (!probability || prandom_u32() > probability)
return 0;
break;