Tomato 1.25
[tomato.git] / release / src / linux / linux / net / ipv4 / netfilter / ipt_bcount.c
blob63f93a14747c419d0e459abcb801496af413ff93
1 /*
3 bcount match (experimental)
4 Copyright (C) 2006 Jonathan Zarate
6 Licensed under GNU GPL v2 or later.
8 */
9 #include <linux/module.h>
10 #include <linux/skbuff.h>
11 #include <net/sock.h>
12 #include <linux/netfilter_ipv4/ip_tables.h>
13 #include <linux/netfilter_ipv4/ip_conntrack.h>
14 #include <linux/netfilter_ipv4/ipt_bcount.h>
16 // #define LOG printk
17 #define LOG(...) do { } while (0);
20 static int match(const struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
21 const void *matchinfo, int offset, const void *hdr, u_int16_t datalen, int *hotdrop)
23 const struct ipt_bcount_match *info = matchinfo;
24 struct ip_conntrack *ct;
25 enum ip_conntrack_info ctinfo;
27 ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
28 if (!ct) return !info->invert;
29 return ((ct->bcount >= info->min) && (ct->bcount <= info->max)) ^ info->invert;
32 static int checkentry(const char *tablename, const struct ipt_ip *ip, void *matchinfo,
33 unsigned int matchsize, unsigned int hook_mask)
35 return (matchsize == IPT_ALIGN(sizeof(struct ipt_bcount_match)));
39 static struct ipt_match bcount_match
40 = { { NULL, NULL }, "bcount", &match, &checkentry, NULL, THIS_MODULE };
42 static int __init init(void)
44 LOG(KERN_INFO "ipt_bcount <" __DATE__ " " __TIME__ "> loaded\n");
45 return ipt_register_match(&bcount_match);
48 static void __exit fini(void)
50 ipt_unregister_match(&bcount_match);
53 module_init(init);
54 module_exit(fini);
57 MODULE_AUTHOR("Jonathan Zarate");
58 MODULE_DESCRIPTION("bcount match");
59 MODULE_LICENSE("GPL");