]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - net/netfilter/xt_quota.c
[NETFILTER]: x_tables: consistent and unique symbol names
[linux-2.6-omap-h63xx.git] / net / netfilter / xt_quota.c
1 /*
2  * netfilter module to enforce network quotas
3  *
4  * Sam Johnston <samj@samj.net>
5  */
6 #include <linux/skbuff.h>
7 #include <linux/spinlock.h>
8
9 #include <linux/netfilter/x_tables.h>
10 #include <linux/netfilter/xt_quota.h>
11
12 MODULE_LICENSE("GPL");
13 MODULE_AUTHOR("Sam Johnston <samj@samj.net>");
14 MODULE_ALIAS("ipt_quota");
15 MODULE_ALIAS("ip6t_quota");
16
17 static DEFINE_SPINLOCK(quota_lock);
18
19 static bool
20 quota_mt(const struct sk_buff *skb, const struct net_device *in,
21          const struct net_device *out, const struct xt_match *match,
22          const void *matchinfo, int offset, unsigned int protoff,
23          bool *hotdrop)
24 {
25         struct xt_quota_info *q =
26                 ((const struct xt_quota_info *)matchinfo)->master;
27         bool ret = q->flags & XT_QUOTA_INVERT;
28
29         spin_lock_bh(&quota_lock);
30         if (q->quota >= skb->len) {
31                 q->quota -= skb->len;
32                 ret = !ret;
33         } else {
34                 /* we do not allow even small packets from now on */
35                 q->quota = 0;
36         }
37         spin_unlock_bh(&quota_lock);
38
39         return ret;
40 }
41
42 static bool
43 quota_mt_check(const char *tablename, const void *entry,
44                const struct xt_match *match, void *matchinfo,
45                unsigned int hook_mask)
46 {
47         struct xt_quota_info *q = matchinfo;
48
49         if (q->flags & ~XT_QUOTA_MASK)
50                 return false;
51         /* For SMP, we only want to use one set of counters. */
52         q->master = q;
53         return true;
54 }
55
56 static struct xt_match quota_mt_reg[] __read_mostly = {
57         {
58                 .name           = "quota",
59                 .family         = AF_INET,
60                 .checkentry     = quota_mt_check,
61                 .match          = quota_mt,
62                 .matchsize      = sizeof(struct xt_quota_info),
63                 .me             = THIS_MODULE
64         },
65         {
66                 .name           = "quota",
67                 .family         = AF_INET6,
68                 .checkentry     = quota_mt_check,
69                 .match          = quota_mt,
70                 .matchsize      = sizeof(struct xt_quota_info),
71                 .me             = THIS_MODULE
72         },
73 };
74
75 static int __init quota_mt_init(void)
76 {
77         return xt_register_matches(quota_mt_reg, ARRAY_SIZE(quota_mt_reg));
78 }
79
80 static void __exit quota_mt_exit(void)
81 {
82         xt_unregister_matches(quota_mt_reg, ARRAY_SIZE(quota_mt_reg));
83 }
84
85 module_init(quota_mt_init);
86 module_exit(quota_mt_exit);