Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 202934
b: refs/heads/master
c: fabf3a8
h: refs/heads/master
v: v3
  • Loading branch information
Eric Dumazet authored and Patrick McHardy committed Jun 1, 2010
1 parent baeca9e commit 8aea488
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a8b563894d6fee9b90b7d6ed76f8ec28ad45bcbe
refs/heads/master: fabf3a85ab88063c10f367cccba7b3a1e59df996
19 changes: 9 additions & 10 deletions trunk/net/netfilter/xt_statistic.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,34 @@
#include <linux/netfilter/x_tables.h>

struct xt_statistic_priv {
uint32_t count;
};
atomic_t count;
} ____cacheline_aligned_in_smp;

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
MODULE_DESCRIPTION("Xtables: statistics-based matching (\"Nth\", random)");
MODULE_ALIAS("ipt_statistic");
MODULE_ALIAS("ip6t_statistic");

static DEFINE_SPINLOCK(nth_lock);

static bool
statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
{
const struct xt_statistic_info *info = par->matchinfo;
bool ret = info->flags & XT_STATISTIC_INVERT;
int nval, oval;

switch (info->mode) {
case XT_STATISTIC_MODE_RANDOM:
if ((net_random() & 0x7FFFFFFF) < info->u.random.probability)
ret = !ret;
break;
case XT_STATISTIC_MODE_NTH:
spin_lock_bh(&nth_lock);
if (info->master->count++ == info->u.nth.every) {
info->master->count = 0;
do {
oval = atomic_read(&info->master->count);
nval = (oval == info->u.nth.every) ? 0 : oval + 1;
} while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
if (nval == 0)
ret = !ret;
}
spin_unlock_bh(&nth_lock);
break;
}

Expand All @@ -64,7 +63,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
if (info->master == NULL)
return -ENOMEM;
info->master->count = info->u.nth.count;
atomic_set(&info->master->count, info->u.nth.count);

return 0;
}
Expand Down

0 comments on commit 8aea488

Please sign in to comment.