USB: cyberjack: remove a unnecessary variable.
[linux-2.6/mini2440.git] / net / netfilter / xt_quota.c
blob3b021d0c522ab938c6b28c1b8052fddd4e2de49f
1 /*
2 * netfilter module to enforce network quotas
4 * Sam Johnston <samj@samj.net>
5 */
6 #include <linux/skbuff.h>
7 #include <linux/spinlock.h>
9 #include <linux/netfilter/x_tables.h>
10 #include <linux/netfilter/xt_quota.h>
12 MODULE_LICENSE("GPL");
13 MODULE_AUTHOR("Sam Johnston <samj@samj.net>");
14 MODULE_DESCRIPTION("Xtables: countdown quota match");
15 MODULE_ALIAS("ipt_quota");
16 MODULE_ALIAS("ip6t_quota");
18 static DEFINE_SPINLOCK(quota_lock);
20 static bool
21 quota_mt(const struct sk_buff *skb, const struct net_device *in,
22 const struct net_device *out, const struct xt_match *match,
23 const void *matchinfo, int offset, unsigned int protoff,
24 bool *hotdrop)
26 struct xt_quota_info *q =
27 ((const struct xt_quota_info *)matchinfo)->master;
28 bool ret = q->flags & XT_QUOTA_INVERT;
30 spin_lock_bh(&quota_lock);
31 if (q->quota >= skb->len) {
32 q->quota -= skb->len;
33 ret = !ret;
34 } else {
35 /* we do not allow even small packets from now on */
36 q->quota = 0;
38 spin_unlock_bh(&quota_lock);
40 return ret;
43 static bool
44 quota_mt_check(const char *tablename, const void *entry,
45 const struct xt_match *match, void *matchinfo,
46 unsigned int hook_mask)
48 struct xt_quota_info *q = matchinfo;
50 if (q->flags & ~XT_QUOTA_MASK)
51 return false;
52 /* For SMP, we only want to use one set of counters. */
53 q->master = q;
54 return true;
57 static struct xt_match quota_mt_reg[] __read_mostly = {
59 .name = "quota",
60 .family = AF_INET,
61 .checkentry = quota_mt_check,
62 .match = quota_mt,
63 .matchsize = sizeof(struct xt_quota_info),
64 .me = THIS_MODULE
67 .name = "quota",
68 .family = AF_INET6,
69 .checkentry = quota_mt_check,
70 .match = quota_mt,
71 .matchsize = sizeof(struct xt_quota_info),
72 .me = THIS_MODULE
76 static int __init quota_mt_init(void)
78 return xt_register_matches(quota_mt_reg, ARRAY_SIZE(quota_mt_reg));
81 static void __exit quota_mt_exit(void)
83 xt_unregister_matches(quota_mt_reg, ARRAY_SIZE(quota_mt_reg));
86 module_init(quota_mt_init);
87 module_exit(quota_mt_exit);