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_DESCRIPTION("Xtables: countdown quota match");
15 MODULE_ALIAS("ipt_quota");
16 MODULE_ALIAS("ip6t_quota");
18 static DEFINE_SPINLOCK(quota_lock);
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,
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("a_lock);
31 if (q->quota >= skb->len) {
35 /* we do not allow even small packets from now on */
38 spin_unlock_bh("a_lock);
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)
52 /* For SMP, we only want to use one set of counters. */
57 static struct xt_match quota_mt_reg[] __read_mostly = {
61 .checkentry = quota_mt_check,
63 .matchsize = sizeof(struct xt_quota_info),
69 .checkentry = quota_mt_check,
71 .matchsize = sizeof(struct xt_quota_info),
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);