Merge branch 'for-linus' of master.kernel.org:/home/rmk/linux-2.6-arm
[linux-2.6-block.git] / net / ipv6 / netfilter / ip6t_eui64.c
CommitLineData
1da177e4
LT
1/* Kernel module to match EUI64 address parameters. */
2
3/* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/module.h>
11#include <linux/skbuff.h>
12#include <linux/ipv6.h>
13#include <linux/if_ether.h>
14
6709dbbb 15#include <linux/netfilter/x_tables.h>
1da177e4
LT
16#include <linux/netfilter_ipv6/ip6_tables.h>
17
2ae15b64 18MODULE_DESCRIPTION("Xtables: IPv6 EUI64 address match");
1da177e4
LT
19MODULE_LICENSE("GPL");
20MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
21
1d93a9cb 22static bool
f7108a20 23eui64_mt6(const struct sk_buff *skb, const struct xt_match_param *par)
1da177e4 24{
f0daaa65
YK
25 unsigned char eui64[8];
26 int i = 0;
1da177e4 27
98e399f8 28 if (!(skb_mac_header(skb) >= skb->head &&
7c4e36bc 29 skb_mac_header(skb) + ETH_HLEN <= skb->data) &&
f7108a20
JE
30 par->fragoff != 0) {
31 *par->hotdrop = true;
1d93a9cb 32 return false;
f0daaa65
YK
33 }
34
35 memset(eui64, 0, sizeof(eui64));
36
d8fd0a73 37 if (eth_hdr(skb)->h_proto == htons(ETH_P_IPV6)) {
0660e03f 38 if (ipv6_hdr(skb)->version == 0x6) {
f0daaa65
YK
39 memcpy(eui64, eth_hdr(skb)->h_source, 3);
40 memcpy(eui64 + 5, eth_hdr(skb)->h_source + 3, 3);
41 eui64[3] = 0xff;
42 eui64[4] = 0xfe;
8f41f017 43 eui64[0] ^= 0x02;
f0daaa65
YK
44
45 i = 0;
7c4e36bc
JE
46 while (ipv6_hdr(skb)->saddr.s6_addr[8 + i] == eui64[i]
47 && i < 8)
f0daaa65
YK
48 i++;
49
50 if (i == 8)
1d93a9cb 51 return true;
f0daaa65
YK
52 }
53 }
54
1d93a9cb 55 return false;
1da177e4
LT
56}
57
d3c5ee6d 58static struct xt_match eui64_mt6_reg __read_mostly = {
1da177e4 59 .name = "eui64",
ee999d8b 60 .family = NFPROTO_IPV6,
d3c5ee6d 61 .match = eui64_mt6,
7f939713 62 .matchsize = sizeof(int),
6e23ae2a
PM
63 .hooks = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_IN) |
64 (1 << NF_INET_FORWARD),
1da177e4
LT
65 .me = THIS_MODULE,
66};
67
d3c5ee6d 68static int __init eui64_mt6_init(void)
1da177e4 69{
d3c5ee6d 70 return xt_register_match(&eui64_mt6_reg);
1da177e4
LT
71}
72
d3c5ee6d 73static void __exit eui64_mt6_exit(void)
1da177e4 74{
d3c5ee6d 75 xt_unregister_match(&eui64_mt6_reg);
1da177e4
LT
76}
77
d3c5ee6d
JE
78module_init(eui64_mt6_init);
79module_exit(eui64_mt6_exit);