2 * netfilter module to enforce network quotas
4 * Sam Johnston <samj@samj.net>
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_ALIAS("ipt_quota");
15 MODULE_ALIAS("ip6t_quota");
17 static DEFINE_SPINLOCK(quota_lock);
20 match(const struct sk_buff *skb,
21 const struct net_device *in, const struct net_device *out,
22 const struct xt_match *match, const void *matchinfo,
23 int offset, unsigned int protoff, bool *hotdrop)
25 struct xt_quota_info *q =
26 ((const struct xt_quota_info *)matchinfo)->master;
27 bool ret = q->flags & XT_QUOTA_INVERT;
29 spin_lock_bh("a_lock);
30 if (q->quota >= skb->len) {
34 /* we do not allow even small packets from now on */
37 spin_unlock_bh("a_lock);
43 checkentry(const char *tablename, const void *entry,
44 const struct xt_match *match, void *matchinfo,
45 unsigned int hook_mask)
47 struct xt_quota_info *q = matchinfo;
49 if (q->flags & ~XT_QUOTA_MASK)
51 /* For SMP, we only want to use one set of counters. */
56 static struct xt_match xt_quota_match[] __read_mostly = {
60 .checkentry = checkentry,
62 .matchsize = sizeof(struct xt_quota_info),
68 .checkentry = checkentry,
70 .matchsize = sizeof(struct xt_quota_info),
75 static int __init xt_quota_init(void)
77 return xt_register_matches(xt_quota_match, ARRAY_SIZE(xt_quota_match));
80 static void __exit xt_quota_fini(void)
82 xt_unregister_matches(xt_quota_match, ARRAY_SIZE(xt_quota_match));
85 module_init(xt_quota_init);
86 module_exit(xt_quota_fini);