Skip to content

Commit

Permalink
netfilter: xt_quota: use per-rule spin lock
Browse files Browse the repository at this point in the history
Use per-rule spin lock to improve the scalability.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
  • Loading branch information
Changli Gao authored and Patrick McHardy committed Jul 23, 2010
1 parent f667009 commit b0c81aa
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions net/netfilter/xt_quota.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#include <linux/netfilter/xt_quota.h>

struct xt_quota_priv {
uint64_t quota;
spinlock_t lock;
uint64_t quota;
};

MODULE_LICENSE("GPL");
Expand All @@ -20,16 +21,14 @@ MODULE_DESCRIPTION("Xtables: countdown quota match");
MODULE_ALIAS("ipt_quota");
MODULE_ALIAS("ip6t_quota");

static DEFINE_SPINLOCK(quota_lock);

static bool
quota_mt(const struct sk_buff *skb, struct xt_action_param *par)
{
struct xt_quota_info *q = (void *)par->matchinfo;
struct xt_quota_priv *priv = q->master;
bool ret = q->flags & XT_QUOTA_INVERT;

spin_lock_bh(&quota_lock);
spin_lock_bh(&priv->lock);
if (priv->quota >= skb->len) {
priv->quota -= skb->len;
ret = !ret;
Expand All @@ -39,7 +38,7 @@ quota_mt(const struct sk_buff *skb, struct xt_action_param *par)
}
/* Copy quota back to matchinfo so that iptables can display it */
q->quota = priv->quota;
spin_unlock_bh(&quota_lock);
spin_unlock_bh(&priv->lock);

return ret;
}
Expand All @@ -55,6 +54,7 @@ static int quota_mt_check(const struct xt_mtchk_param *par)
if (q->master == NULL)
return -ENOMEM;

spin_lock_init(&q->master->lock);
q->master->quota = q->quota;
return 0;
}
Expand Down

0 comments on commit b0c81aa

Please sign in to comment.