summaryrefslogtreecommitdiff
path: root/release/src/linux/linux/net/ipv4/netfilter/ipt_bcount.c
blob: 63f93a14747c419d0e459abcb801496af413ff93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*

	bcount match (experimental)
	Copyright (C) 2006 Jonathan Zarate

	Licensed under GNU GPL v2 or later.

*/
#include <linux/module.h>
#include <linux/skbuff.h>
#include <net/sock.h>
#include <linux/netfilter_ipv4/ip_tables.h>
#include <linux/netfilter_ipv4/ip_conntrack.h>
#include <linux/netfilter_ipv4/ipt_bcount.h>

//	#define LOG			printk
#define LOG(...)	do { } while (0);


static int match(const struct sk_buff *skb,	const struct net_device *in, const struct net_device *out,
				 const void *matchinfo, int offset, const void *hdr, u_int16_t datalen, int *hotdrop)
{
	const struct ipt_bcount_match *info = matchinfo;
	struct ip_conntrack *ct;
	enum ip_conntrack_info ctinfo;

	ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
	if (!ct) return !info->invert;
	return ((ct->bcount >= info->min) && (ct->bcount <= info->max)) ^ info->invert;
}

static int checkentry(const char *tablename, const struct ipt_ip *ip, void *matchinfo,
					  unsigned int matchsize, unsigned int hook_mask)
{
	return (matchsize == IPT_ALIGN(sizeof(struct ipt_bcount_match)));
}


static struct ipt_match bcount_match
= { { NULL, NULL }, "bcount", &match, &checkentry, NULL, THIS_MODULE };

static int __init init(void)
{
	LOG(KERN_INFO "ipt_bcount <" __DATE__ " " __TIME__ "> loaded\n");
	return ipt_register_match(&bcount_match);
}

static void __exit fini(void)
{
	ipt_unregister_match(&bcount_match);
}

module_init(init);
module_exit(fini);


MODULE_AUTHOR("Jonathan Zarate");
MODULE_DESCRIPTION("bcount match");
MODULE_LICENSE("GPL");