1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Kernel module to match EUI64 address parameters. */
4 /* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
7 #include <linux/module.h>
8 #include <linux/skbuff.h>
9 #include <linux/ipv6.h>
10 #include <linux/if_ether.h>
12 #include <linux/netfilter/x_tables.h>
13 #include <linux/netfilter_ipv6/ip6_tables.h>
15 MODULE_DESCRIPTION("Xtables: IPv6 EUI64 address match");
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
20 eui64_mt6(const struct sk_buff
*skb
, struct xt_action_param
*par
)
22 unsigned char eui64
[8];
24 if (!(skb_mac_header(skb
) >= skb
->head
&&
25 skb_mac_header(skb
) + ETH_HLEN
<= skb
->data
) &&
31 memset(eui64
, 0, sizeof(eui64
));
33 if (eth_hdr(skb
)->h_proto
== htons(ETH_P_IPV6
)) {
34 if (ipv6_hdr(skb
)->version
== 0x6) {
35 memcpy(eui64
, eth_hdr(skb
)->h_source
, 3);
36 memcpy(eui64
+ 5, eth_hdr(skb
)->h_source
+ 3, 3);
41 if (!memcmp(ipv6_hdr(skb
)->saddr
.s6_addr
+ 8, eui64
,
50 static struct xt_match eui64_mt6_reg __read_mostly
= {
52 .family
= NFPROTO_IPV6
,
54 .matchsize
= sizeof(int),
55 .hooks
= (1 << NF_INET_PRE_ROUTING
) | (1 << NF_INET_LOCAL_IN
) |
56 (1 << NF_INET_FORWARD
),
60 static int __init
eui64_mt6_init(void)
62 return xt_register_match(&eui64_mt6_reg
);
65 static void __exit
eui64_mt6_exit(void)
67 xt_unregister_match(&eui64_mt6_reg
);
70 module_init(eui64_mt6_init
);
71 module_exit(eui64_mt6_exit
);