Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Jan Engelhardt | 6709dbb | 2007-02-07 15:11:19 -0800 | [diff] [blame] | 15 | #include <linux/netfilter/x_tables.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/netfilter_ipv6/ip6_tables.h> |
| 17 | |
| 18 | MODULE_DESCRIPTION("IPv6 EUI64 address checking match"); |
| 19 | MODULE_LICENSE("GPL"); |
| 20 | MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>"); |
| 21 | |
Jan Engelhardt | 1d93a9c | 2007-07-07 22:15:35 -0700 | [diff] [blame] | 22 | static bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | match(const struct sk_buff *skb, |
| 24 | const struct net_device *in, |
| 25 | const struct net_device *out, |
Patrick McHardy | c498673 | 2006-03-20 18:02:56 -0800 | [diff] [blame] | 26 | const struct xt_match *match, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | const void *matchinfo, |
| 28 | int offset, |
| 29 | unsigned int protoff, |
Jan Engelhardt | cff533a | 2007-07-07 22:15:12 -0700 | [diff] [blame] | 30 | bool *hotdrop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 32 | unsigned char eui64[8]; |
| 33 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 35 | if (!(skb_mac_header(skb) >= skb->head && |
Jan Engelhardt | 7c4e36b | 2007-07-07 22:19:08 -0700 | [diff] [blame] | 36 | skb_mac_header(skb) + ETH_HLEN <= skb->data) && |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 37 | offset != 0) { |
Jan Engelhardt | cff533a | 2007-07-07 22:15:12 -0700 | [diff] [blame] | 38 | *hotdrop = true; |
Jan Engelhardt | 1d93a9c | 2007-07-07 22:15:35 -0700 | [diff] [blame] | 39 | return false; |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 40 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 42 | memset(eui64, 0, sizeof(eui64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Alexey Dobriyan | d8fd0a7 | 2006-05-16 15:24:41 -0700 | [diff] [blame] | 44 | if (eth_hdr(skb)->h_proto == htons(ETH_P_IPV6)) { |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 45 | if (ipv6_hdr(skb)->version == 0x6) { |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 52 | i = 0; |
Jan Engelhardt | 7c4e36b | 2007-07-07 22:19:08 -0700 | [diff] [blame] | 53 | while (ipv6_hdr(skb)->saddr.s6_addr[8 + i] == eui64[i] |
| 54 | && i < 8) |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 55 | i++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 57 | if (i == 8) |
Jan Engelhardt | 1d93a9c | 2007-07-07 22:15:35 -0700 | [diff] [blame] | 58 | return true; |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 59 | } |
| 60 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Jan Engelhardt | 1d93a9c | 2007-07-07 22:15:35 -0700 | [diff] [blame] | 62 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Patrick McHardy | 9f15c53 | 2007-07-07 22:22:02 -0700 | [diff] [blame^] | 65 | static struct xt_match eui64_match __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | .name = "eui64", |
Jan Engelhardt | 6709dbb | 2007-02-07 15:11:19 -0800 | [diff] [blame] | 67 | .family = AF_INET6, |
Patrick McHardy | 7f93971 | 2006-03-20 18:01:43 -0800 | [diff] [blame] | 68 | .match = match, |
| 69 | .matchsize = sizeof(int), |
| 70 | .hooks = (1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_IN) | |
| 71 | (1 << NF_IP6_FORWARD), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | .me = THIS_MODULE, |
| 73 | }; |
| 74 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 75 | static int __init ip6t_eui64_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Jan Engelhardt | 6709dbb | 2007-02-07 15:11:19 -0800 | [diff] [blame] | 77 | return xt_register_match(&eui64_match); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 80 | static void __exit ip6t_eui64_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Jan Engelhardt | 6709dbb | 2007-02-07 15:11:19 -0800 | [diff] [blame] | 82 | xt_unregister_match(&eui64_match); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 85 | module_init(ip6t_eui64_init); |
| 86 | module_exit(ip6t_eui64_fini); |