summaryrefslogtreecommitdiffstats
path: root/net/openvswitch/actions.c
diff options
context:
space:
mode:
authorWenyu Zhang <wenyuz@vmware.com>2015-08-05 09:30:47 +0200
committerDavid S. Miller <davem@davemloft.net>2015-08-07 21:00:38 +0200
commite05176a3283822bd32a1f3d929ce2050232299a8 (patch)
tree3a3ea7c2e7dcfc2b396128fd598d31c7a85dfa91 /net/openvswitch/actions.c
parentvxlan: combine VXLAN_FLOWBASED into VXLAN_COLLECT_METADATA (diff)
downloadlinux-e05176a3283822bd32a1f3d929ce2050232299a8.tar.xz
linux-e05176a3283822bd32a1f3d929ce2050232299a8.zip
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 <wenyuz@vmware.com> Acked-by: Pravin B Shelar <pshelar@nicira.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/openvswitch/actions.c')
-rw-r--r--net/openvswitch/actions.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index cf04c2f8b32a..a0ac410e9570 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -669,9 +669,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;