Merge git://git.infradead.org/mtd-2.6
[deliverable/linux.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
18MODULE_DESCRIPTION("IPv6 EUI64 address checking match");
19MODULE_LICENSE("GPL");
20MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
21
22static int
23match(const struct sk_buff *skb,
24 const struct net_device *in,
25 const struct net_device *out,
c4986734 26 const struct xt_match *match,
1da177e4
LT
27 const void *matchinfo,
28 int offset,
29 unsigned int protoff,
30 int *hotdrop)
31{
f0daaa65
YK
32 unsigned char eui64[8];
33 int i = 0;
1da177e4 34
f0daaa65
YK
35 if (!(skb->mac.raw >= skb->head &&
36 (skb->mac.raw + ETH_HLEN) <= skb->data) &&
37 offset != 0) {
38 *hotdrop = 1;
39 return 0;
40 }
41
42 memset(eui64, 0, sizeof(eui64));
43
d8fd0a73 44 if (eth_hdr(skb)->h_proto == htons(ETH_P_IPV6)) {
f0daaa65
YK
45 if (skb->nh.ipv6h->version == 0x6) {
46 memcpy(eui64, eth_hdr(skb)->h_source, 3);
47 memcpy(eui64 + 5, eth_hdr(skb)->h_source + 3, 3);
48 eui64[3] = 0xff;
49 eui64[4] = 0xfe;
50 eui64[0] |= 0x02;
51
52 i = 0;
53 while ((skb->nh.ipv6h->saddr.s6_addr[8+i] == eui64[i])
54 && (i < 8))
55 i++;
56
57 if (i == 8)
58 return 1;
59 }
60 }
61
62 return 0;
1da177e4
LT
63}
64
6709dbbb 65static struct xt_match eui64_match = {
1da177e4 66 .name = "eui64",
6709dbbb 67 .family = AF_INET6,
7f939713
PM
68 .match = match,
69 .matchsize = sizeof(int),
70 .hooks = (1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_IN) |
71 (1 << NF_IP6_FORWARD),
1da177e4
LT
72 .me = THIS_MODULE,
73};
74
65b4b4e8 75static int __init ip6t_eui64_init(void)
1da177e4 76{
6709dbbb 77 return xt_register_match(&eui64_match);
1da177e4
LT
78}
79
65b4b4e8 80static void __exit ip6t_eui64_fini(void)
1da177e4 81{
6709dbbb 82 xt_unregister_match(&eui64_match);
1da177e4
LT
83}
84
65b4b4e8
AM
85module_init(ip6t_eui64_init);
86module_exit(ip6t_eui64_fini);
This page took 0.196749 seconds and 5 git commands to generate.