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>");
15 static DEFINE_SPINLOCK(quota_lock);
18 match(const struct sk_buff *skb,
19 const struct net_device *in, const struct net_device *out,
20 const struct xt_match *match, const void *matchinfo,
21 int offset, unsigned int protoff, int *hotdrop)
23 struct xt_quota_info *q = ((struct xt_quota_info *)matchinfo)->master;
24 int ret = q->flags & XT_QUOTA_INVERT ? 1 : 0;
26 spin_lock_bh("a_lock);
27 if (q->quota >= skb->len) {
31 /* we do not allow even small packets from now on */
34 spin_unlock_bh("a_lock);
40 checkentry(const char *tablename, const void *entry,
41 const struct xt_match *match, void *matchinfo,
42 unsigned int matchsize, unsigned int hook_mask)
44 struct xt_quota_info *q = (struct xt_quota_info *)matchinfo;
46 if (q->flags & ~XT_QUOTA_MASK)
48 /* For SMP, we only want to use one set of counters. */
53 static struct xt_match quota_match = {
57 .matchsize = sizeof(struct xt_quota_info),
58 .checkentry = checkentry,
62 static struct xt_match quota_match6 = {
66 .matchsize = sizeof(struct xt_quota_info),
67 .checkentry = checkentry,
71 static int __init xt_quota_init(void)
75 ret = xt_register_match("a_match);
78 ret = xt_register_match("a_match6);
84 xt_unregister_match("a_match);
89 static void __exit xt_quota_fini(void)
91 xt_unregister_match("a_match6);
92 xt_unregister_match("a_match);
95 module_init(xt_quota_init);
96 module_exit(xt_quota_fini);