aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWenyu Zhang <wenyuz@vmware.com>2015-08-05 03:30:47 -0400
committerDavid S. Miller <davem@davemloft.net>2015-08-07 15:00:38 -0400
commite05176a3283822bd32a1f3d929ce2050232299a8 (patch)
tree3a3ea7c2e7dcfc2b396128fd598d31c7a85dfa91
parentda8b43c0e1dcea3bcac5f37ea59934ddaa137aed (diff)
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>
-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,
669 669
670 for (a = nla_data(attr), rem = nla_len(attr); rem > 0; 670 for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
671 a = nla_next(a, &rem)) { 671 a = nla_next(a, &rem)) {
672 u32 probability;
673
672 switch (nla_type(a)) { 674 switch (nla_type(a)) {
673 case OVS_SAMPLE_ATTR_PROBABILITY: 675 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)
675 return 0; 678 return 0;
676 break; 679 break;
677 680