blob: aab0706908c5491fc4405468232dfdd440f23c4d [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
Jan Engelhardt6709dbb2007-02-07 15:11:19 -080015#include <linux/netfilter/x_tables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/netfilter_ipv6/ip6_tables.h>
17
Jan Engelhardt2ae15b62008-01-14 23:42:28 -080018MODULE_DESCRIPTION("Xtables: IPv6 EUI64 address match");
Linus Torvalds1da177e2005-04-16 15:20:36 -070019MODULE_LICENSE("GPL");
20MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
21
Jan Engelhardt1d93a9c2007-07-07 22:15:35 -070022static bool
Jan Engelhardt62fc8052009-07-07 20:42:08 +020023eui64_mt6(const struct sk_buff *skb, struct xt_action_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080025 unsigned char eui64[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -070027 if (!(skb_mac_header(skb) >= skb->head &&
Jan Engelhardt7c4e36b2007-07-07 22:19:08 -070028 skb_mac_header(skb) + ETH_HLEN <= skb->data) &&
Jan Engelhardtf7108a22008-10-08 11:35:18 +020029 par->fragoff != 0) {
Jan Engelhardtb4ba2612009-07-07 20:54:30 +020030 par->hotdrop = true;
Jan Engelhardt1d93a9c2007-07-07 22:15:35 -070031 return false;
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080032 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080034 memset(eui64, 0, sizeof(eui64));
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Alexey Dobriyand8fd0a72006-05-16 15:24:41 -070036 if (eth_hdr(skb)->h_proto == htons(ETH_P_IPV6)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -070037 if (ipv6_hdr(skb)->version == 0x6) {
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080038 memcpy(eui64, eth_hdr(skb)->h_source, 3);
39 memcpy(eui64 + 5, eth_hdr(skb)->h_source + 3, 3);
40 eui64[3] = 0xff;
41 eui64[4] = 0xfe;
Yasuyuki Kozakai8f41f012008-01-10 22:40:39 -080042 eui64[0] ^= 0x02;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Patrick McHardy48890862009-08-31 15:30:31 +020044 if (!memcmp(ipv6_hdr(skb)->saddr.s6_addr + 8, eui64,
45 sizeof(eui64)))
Jan Engelhardt1d93a9c2007-07-07 22:15:35 -070046 return true;
Yasuyuki Kozakaif0daaa62006-01-17 02:39:39 -080047 }
48 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Jan Engelhardt1d93a9c2007-07-07 22:15:35 -070050 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080053static struct xt_match eui64_mt6_reg __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .name = "eui64",
Jan Engelhardtee999d82008-10-08 11:35:01 +020055 .family = NFPROTO_IPV6,
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080056 .match = eui64_mt6,
Patrick McHardy7f939712006-03-20 18:01:43 -080057 .matchsize = sizeof(int),
Patrick McHardy6e23ae22007-11-19 18:53:30 -080058 .hooks = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_IN) |
59 (1 << NF_INET_FORWARD),
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 .me = THIS_MODULE,
61};
62
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080063static int __init eui64_mt6_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080065 return xt_register_match(&eui64_mt6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080068static void __exit eui64_mt6_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080070 xt_unregister_match(&eui64_mt6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080073module_init(eui64_mt6_init);
74module_exit(eui64_mt6_exit);