1 include/linux/netfilter_ipv4/ipt_quota.h | 12 +++
2 net/ipv4/netfilter/Kconfig | 10 +++
3 net/ipv4/netfilter/Makefile | 1
4 net/ipv4/netfilter/ipt_quota.c | 96 +++++++++++++++++++++++++++++++
5 4 files changed, 119 insertions(+)
7 diff -Nur --exclude '*.orig' linux.org/include/linux/netfilter_ipv4/ipt_quota.h linux/include/linux/netfilter_ipv4/ipt_quota.h
8 --- linux.org/include/linux/netfilter_ipv4/ipt_quota.h 1970-01-01 01:00:00.000000000 +0100
9 +++ linux/include/linux/netfilter_ipv4/ipt_quota.h 2006-05-04 10:23:57.000000000 +0200
14 +/* print debug info in both kernel/netfilter module & iptable library */
15 +//#define DEBUG_IPT_QUOTA
17 +struct ipt_quota_info {
19 + struct ipt_quota_info *master;
22 +#endif /*_IPT_QUOTA_H*/
23 diff -Nur --exclude '*.orig' linux.org/net/ipv4/netfilter/Kconfig linux/net/ipv4/netfilter/Kconfig
24 --- linux.org/net/ipv4/netfilter/Kconfig 2006-05-02 23:38:44.000000000 +0200
25 +++ linux/net/ipv4/netfilter/Kconfig 2006-05-04 10:23:57.000000000 +0200
27 Allows altering the ARP packet payload: source and destination
28 hardware and network addresses.
30 +config IP_NF_MATCH_QUOTA
31 + tristate 'quota match support'
32 + depends on IP_NF_IPTABLES
34 + This match implements network quotas.
36 + If you want to compile it as a module, say M here and read
37 + Documentation/modules.txt. If unsure, say `N'.
42 diff -Nur --exclude '*.orig' linux.org/net/ipv4/netfilter/Makefile linux/net/ipv4/netfilter/Makefile
43 --- linux.org/net/ipv4/netfilter/Makefile 2006-05-02 23:38:44.000000000 +0200
44 +++ linux/net/ipv4/netfilter/Makefile 2006-05-04 10:23:57.000000000 +0200
46 +obj-$(CONFIG_IP_NF_MATCH_QUOTA) += ipt_quota.o
47 diff -Nur --exclude '*.orig' linux.org/net/ipv4/netfilter/ipt_quota.c linux/net/ipv4/netfilter/ipt_quota.c
48 --- linux.org/net/ipv4/netfilter/ipt_quota.c 1970-01-01 01:00:00.000000000 +0100
49 +++ linux/net/ipv4/netfilter/ipt_quota.c 2006-05-04 10:23:57.000000000 +0200
52 + * netfilter module to enforce network quotas
54 + * Sam Johnston <samj@samj.net>
56 + * 30/01/05: Fixed on SMP --Pablo Neira <pablo@eurodev.net>
58 +#include <linux/module.h>
59 +#include <linux/skbuff.h>
60 +#include <linux/spinlock.h>
61 +#include <linux/interrupt.h>
63 +#include <linux/netfilter_ipv4/ip_tables.h>
64 +#include <linux/netfilter_ipv4/ipt_quota.h>
66 +MODULE_LICENSE("GPL");
67 +MODULE_AUTHOR("Sam Johnston <samj@samj.net>");
69 +static spinlock_t quota_lock = SPIN_LOCK_UNLOCKED;
72 +match(const struct sk_buff *skb,
73 + const struct net_device *in,
74 + const struct net_device *out,
75 + const void *matchinfo,
76 + int offset, unsigned int protoff, int *hotdrop)
78 + struct ipt_quota_info *q =
79 + ((struct ipt_quota_info *) matchinfo)->master;
81 + if (skb->len < sizeof(struct iphdr))
84 + spin_lock_bh("a_lock);
86 + if (q->quota >= skb->len) {
87 + /* we can afford this one */
88 + q->quota -= skb->len;
89 + spin_unlock_bh("a_lock);
91 +#ifdef DEBUG_IPT_QUOTA
92 + printk("IPT Quota OK: %llu datlen %d \n", q->quota, skb->len);
97 + /* so we do not allow even small packets from now on */
100 +#ifdef DEBUG_IPT_QUOTA
101 + printk("IPT Quota Failed: %llu datlen %d \n", q->quota, skb->len);
104 + spin_unlock_bh("a_lock);
109 +checkentry(const char *tablename,
110 + const struct ipt_ip *ip,
111 + void *matchinfo, unsigned int matchsize, unsigned int hook_mask)
113 + /* TODO: spinlocks? sanity checks? */
114 + struct ipt_quota_info *q = (struct ipt_quota_info *) matchinfo;
116 + if (matchsize != IPT_ALIGN(sizeof (struct ipt_quota_info)))
119 + /* For SMP, we only want to use one set of counters. */
125 +static struct ipt_match quota_match = {
128 + .checkentry = checkentry,
135 + return ipt_register_match("a_match);
141 + ipt_unregister_match("a_match);