Skip to content

Commit e05176a

Browse files
WenyuZhangdavem330
authored andcommitted
openvswitch: 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 <[email protected]> Acked-by: Pravin B Shelar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent da8b43c commit e05176a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/openvswitch/actions.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,12 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
669669

670670
for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
671671
a = nla_next(a, &rem)) {
672+
u32 probability;
673+
672674
switch (nla_type(a)) {
673675
case OVS_SAMPLE_ATTR_PROBABILITY:
674-
if (prandom_u32() >= nla_get_u32(a))
676+
probability = nla_get_u32(a);
677+
if (!probability || prandom_u32() > probability)
675678
return 0;
676679
break;
677680

0 commit comments

Comments
 (0)