1 --- a/Documentation/Configure.help
2 +++ b/Documentation/Configure.help
3 @@ -2888,6 +2888,13 @@ CONFIG_IP_NF_MATCH_LIMIT
4 If you want to compile it as a module, say M here and read
5 <file:Documentation/modules.txt>. If unsure, say `N'.
8 +CONFIG_IP_NF_MATCH_QUOTA
9 + This match implements network quotas.
11 + If you want to compile it as a module, say M here and read
12 + Documentation/modules.txt. If unsure, say `N'.
14 skb->pkt_type packet match support
15 CONFIG_IP_NF_MATCH_PKTTYPE
16 This patch allows you to match packet in accrodance
18 +++ b/include/linux/netfilter_ipv4/ipt_quota.h
23 +/* print debug info in both kernel/netfilter module & iptable library */
24 +//#define DEBUG_IPT_QUOTA
26 +struct ipt_quota_info {
28 + struct ipt_quota_info *master;
31 +#endif /*_IPT_QUOTA_H*/
32 --- a/net/ipv4/netfilter/Config.in
33 +++ b/net/ipv4/netfilter/Config.in
34 @@ -22,6 +22,7 @@ tristate 'IP tables support (required fo
35 if [ "$CONFIG_IP_NF_IPTABLES" != "n" ]; then
37 dep_tristate ' limit match support' CONFIG_IP_NF_MATCH_LIMIT $CONFIG_IP_NF_IPTABLES
38 + dep_tristate ' quota match support' CONFIG_IP_NF_MATCH_QUOTA $CONFIG_IP_NF_IPTABLES
39 dep_tristate ' MAC address match support' CONFIG_IP_NF_MATCH_MAC $CONFIG_IP_NF_IPTABLES
40 dep_tristate ' Packet type match support' CONFIG_IP_NF_MATCH_PKTTYPE $CONFIG_IP_NF_IPTABLES
41 dep_tristate ' netfilter MARK match support' CONFIG_IP_NF_MATCH_MARK $CONFIG_IP_NF_IPTABLES
42 --- a/net/ipv4/netfilter/Makefile
43 +++ b/net/ipv4/netfilter/Makefile
44 @@ -65,6 +65,7 @@ obj-$(CONFIG_IP_NF_NAT) += iptable_nat.o
46 obj-$(CONFIG_IP_NF_MATCH_HELPER) += ipt_helper.o
47 obj-$(CONFIG_IP_NF_MATCH_LIMIT) += ipt_limit.o
48 +obj-$(CONFIG_IP_NF_MATCH_QUOTA) += ipt_quota.o
49 obj-$(CONFIG_IP_NF_MATCH_MARK) += ipt_mark.o
50 obj-$(CONFIG_IP_NF_MATCH_MAC) += ipt_mac.o
51 obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_ipp2p.o
53 +++ b/net/ipv4/netfilter/ipt_quota.c
56 + * netfilter module to enforce network quotas
58 + * Sam Johnston <samj@samj.net>
60 + * 30/01/05: Fixed on SMP --Pablo Neira <pablo@eurodev.net>
62 +#include <linux/module.h>
63 +#include <linux/skbuff.h>
64 +#include <linux/spinlock.h>
65 +#include <linux/interrupt.h>
67 +#include <linux/netfilter_ipv4/ip_tables.h>
68 +#include <linux/netfilter_ipv4/ipt_quota.h>
70 +MODULE_LICENSE("GPL");
72 +static spinlock_t quota_lock = SPIN_LOCK_UNLOCKED;
75 +match(const struct sk_buff *skb,
76 + const struct net_device *in,
77 + const struct net_device *out,
78 + const void *matchinfo,
79 + int offset, const void *hdr, u_int16_t datalen, int *hotdrop)
81 + struct ipt_quota_info *q =
82 + ((struct ipt_quota_info *) matchinfo)->master;
84 + spin_lock_bh("a_lock);
86 + if (q->quota >= datalen) {
87 + /* we can afford this one */
88 + q->quota -= datalen;
89 + spin_unlock_bh("a_lock);
91 +#ifdef DEBUG_IPT_QUOTA
92 + printk("IPT Quota OK: %llu datlen %d \n", q->quota, datalen);
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, datalen);
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
126 + = { {NULL, NULL}, "quota", &match, &checkentry, NULL, THIS_MODULE };
131 + return ipt_register_match("a_match);
137 + ipt_unregister_match("a_match);