blob: 4f6b84c8f4ab6567cc70301d7bdcc2460eabb38a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
15#include <linux/netfilter_ipv6/ip6_tables.h>
16
17MODULE_DESCRIPTION("IPv6 EUI64 address checking match");
18MODULE_LICENSE("GPL");
19MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
20
21static int
22match(const struct sk_buff *skb,
23 const struct net_device *in,
24 const struct net_device *out,
Patrick McHardyc4986732006-03-20 18:02:56 -080025 const struct xt_match *match,
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 const void *matchinfo,
27 int offset,
28 unsigned int protoff,
29 int *hotdrop)
30{
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080031 unsigned char eui64[8];
32 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080034 if (!(skb->mac.raw >= skb->head &&
35 (skb->mac.raw + ETH_HLEN) <= skb->data) &&
36 offset != 0) {
37 *hotdrop = 1;
38 return 0;
39 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080041 memset(eui64, 0, sizeof(eui64));
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Alexey Dobriyand8fd0a72006-05-16 15:24:41 -070043 if (eth_hdr(skb)->h_proto == htons(ETH_P_IPV6)) {
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080044 if (skb->nh.ipv6h->version == 0x6) {
45 memcpy(eui64, eth_hdr(skb)->h_source, 3);
46 memcpy(eui64 + 5, eth_hdr(skb)->h_source + 3, 3);
47 eui64[3] = 0xff;
48 eui64[4] = 0xfe;
49 eui64[0] |= 0x02;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080051 i = 0;
52 while ((skb->nh.ipv6h->saddr.s6_addr[8+i] == eui64[i])
53 && (i < 8))
54 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080056 if (i == 8)
57 return 1;
58 }
59 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080061 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static struct ip6t_match eui64_match = {
65 .name = "eui64",
Patrick McHardy7f939712006-03-20 18:01:43 -080066 .match = match,
67 .matchsize = sizeof(int),
68 .hooks = (1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_IN) |
69 (1 << NF_IP6_FORWARD),
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 .me = THIS_MODULE,
71};
72
Andrew Morton65b4b4e2006-03-28 16:37:06 -080073static int __init ip6t_eui64_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 return ip6t_register_match(&eui64_match);
76}
77
Andrew Morton65b4b4e2006-03-28 16:37:06 -080078static void __exit ip6t_eui64_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 ip6t_unregister_match(&eui64_match);
81}
82
Andrew Morton65b4b4e2006-03-28 16:37:06 -080083module_init(ip6t_eui64_init);
84module_exit(ip6t_eui64_fini);