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 | |
| 15 | #include <linux/netfilter_ipv6/ip6_tables.h> |
| 16 | |
| 17 | MODULE_DESCRIPTION("IPv6 EUI64 address checking match"); |
| 18 | MODULE_LICENSE("GPL"); |
| 19 | MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>"); |
| 20 | |
| 21 | static int |
| 22 | match(const struct sk_buff *skb, |
| 23 | const struct net_device *in, |
| 24 | const struct net_device *out, |
| 25 | const void *matchinfo, |
| 26 | int offset, |
| 27 | unsigned int protoff, |
| 28 | int *hotdrop) |
| 29 | { |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 30 | unsigned char eui64[8]; |
| 31 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 33 | if (!(skb->mac.raw >= skb->head && |
| 34 | (skb->mac.raw + ETH_HLEN) <= skb->data) && |
| 35 | offset != 0) { |
| 36 | *hotdrop = 1; |
| 37 | return 0; |
| 38 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 40 | memset(eui64, 0, sizeof(eui64)); |
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 | if (eth_hdr(skb)->h_proto == ntohs(ETH_P_IPV6)) { |
| 43 | if (skb->nh.ipv6h->version == 0x6) { |
| 44 | memcpy(eui64, eth_hdr(skb)->h_source, 3); |
| 45 | memcpy(eui64 + 5, eth_hdr(skb)->h_source + 3, 3); |
| 46 | eui64[3] = 0xff; |
| 47 | eui64[4] = 0xfe; |
| 48 | eui64[0] |= 0x02; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 50 | i = 0; |
| 51 | while ((skb->nh.ipv6h->saddr.s6_addr[8+i] == eui64[i]) |
| 52 | && (i < 8)) |
| 53 | i++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 55 | if (i == 8) |
| 56 | return 1; |
| 57 | } |
| 58 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 60 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static int |
| 64 | ip6t_eui64_checkentry(const char *tablename, |
Yasuyuki Kozakai | f0daaa6 | 2006-01-17 02:39:39 -0800 | [diff] [blame] | 65 | const void *ip, |
| 66 | void *matchinfo, |
| 67 | unsigned int matchsize, |
| 68 | unsigned int hook_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
| 70 | if (hook_mask |
| 71 | & ~((1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_IN) | |
| 72 | (1 << NF_IP6_FORWARD))) { |
| 73 | printk("ip6t_eui64: only valid for PRE_ROUTING, LOCAL_IN or FORWARD.\n"); |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | if (matchsize != IP6T_ALIGN(sizeof(int))) |
| 78 | return 0; |
| 79 | |
| 80 | return 1; |
| 81 | } |
| 82 | |
| 83 | static struct ip6t_match eui64_match = { |
| 84 | .name = "eui64", |
| 85 | .match = &match, |
| 86 | .checkentry = &ip6t_eui64_checkentry, |
| 87 | .me = THIS_MODULE, |
| 88 | }; |
| 89 | |
| 90 | static int __init init(void) |
| 91 | { |
| 92 | return ip6t_register_match(&eui64_match); |
| 93 | } |
| 94 | |
| 95 | static void __exit fini(void) |
| 96 | { |
| 97 | ip6t_unregister_match(&eui64_match); |
| 98 | } |
| 99 | |
| 100 | module_init(init); |
| 101 | module_exit(fini); |