summaryrefslogtreecommitdiff
path: root/release/src/linux/linux/net/ipv4/netfilter/ipt_macsave.c
blob: 25fa26a4c314dba0b19ca46cfb6fe1a0f9234f43 (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
60
61
62
/*

	macsave match
	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_macsave.h>

#define DEBUG	1

#ifdef DEBUG
#define DLOG			printk
#else
#define DLOG(...)	do { } while (0);
#endif


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_macsave_match_info *info = matchinfo;
	struct ip_conntrack *ct;
	enum ip_conntrack_info ctinfo;

	ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);	// note about cast: ip_conntrack_get() will not modify skb
	if (ct) return (memcmp(ct->macsave, info->mac, sizeof(ct->macsave)) == 0) ^ info->invert;
	return 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_macsave_match_info)));
}


static struct ipt_match macsave_match
= { { NULL, NULL }, "macsave", &match, &checkentry, NULL, THIS_MODULE };

static int __init init(void)
{
	DLOG(KERN_INFO "macsave match init " __DATE__ " " __TIME__ "\n");
	return ipt_register_match(&macsave_match);
}

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

module_init(init);
module_exit(fini);
MODULE_LICENSE("GPL");