Debian Codegraph @

net/ipv6/netfilter/ip6t_eui64.c

raw
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Kernel module to match EUI64 address parameters. */
3
4 /* (C) 2001-2002 Andras Kis-Szabo <[email protected]>
5 */
6
7 #include <linux/module.h>
8 #include <linux/skbuff.h>
9 #include <linux/ipv6.h>
10 #include <linux/if_ether.h>
11
12 #include <linux/netfilter/x_tables.h>
13 #include <linux/netfilter_ipv6/ip6_tables.h>
14
15 MODULE_DESCRIPTION("Xtables: IPv6 EUI64 address match");
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("Andras Kis-Szabo <[email protected]>");
18
19 static bool
20 eui64_mt6(const struct sk_buff *skb, struct xt_action_param *par)
21 {
22 unsigned char eui64[8];
23
24 if (!(skb_mac_header(skb) >= skb->head &&
25 skb_mac_header(skb) + ETH_HLEN <= skb->data)) {
26 par->hotdrop = true;
27 return false;
28 }
29
30 memset(eui64, 0, sizeof(eui64));
31
32 if (eth_hdr(skb)->h_proto == htons(ETH_P_IPV6)) {
33 if (ipv6_hdr(skb)->version == 0x6) {
34 memcpy(eui64, eth_hdr(skb)->h_source, 3);
35 memcpy(eui64 + 5, eth_hdr(skb)->h_source + 3, 3);
36 eui64[3] = 0xff;
37 eui64[4] = 0xfe;
38 eui64[0] ^= 0x02;
39
40 if (!memcmp(ipv6_hdr(skb)->saddr.s6_addr + 8, eui64,
41 sizeof(eui64)))
42 return true;
43 }
44 }
45
46 return false;
47 }
48
49 static struct xt_match eui64_mt6_reg __read_mostly = {
50 .name = "eui64",
51 .family = NFPROTO_IPV6,
52 .match = eui64_mt6,
53 .matchsize = sizeof(int),
54 .hooks = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_IN) |
55 (1 << NF_INET_FORWARD),
56 .me = THIS_MODULE,
57 };
58
59 static int __init eui64_mt6_init(void)
60 {
61 return xt_register_match(&eui64_mt6_reg);
62 }
63
64 static void __exit eui64_mt6_exit(void)
65 {
66 xt_unregister_match(&eui64_mt6_reg);
67 }
68
69 module_init(eui64_mt6_init);
70 module_exit(eui64_mt6_exit);