]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - net/ipv6/netfilter/ip6t_eui64.c
[NETFILTER]: Update modules' descriptions
[linux-2.6.git] / net / ipv6 / netfilter / ip6t_eui64.c
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/x_tables.h>
16 #include <linux/netfilter_ipv6/ip6_tables.h>
17
18 MODULE_DESCRIPTION("Xtables: IPv6 EUI64 address match");
19 MODULE_LICENSE("GPL");
20 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
21
22 static bool
23 eui64_mt6(const struct sk_buff *skb, const struct net_device *in,
24           const struct net_device *out, const struct xt_match *match,
25           const void *matchinfo, int offset, unsigned int protoff,
26           bool *hotdrop)
27 {
28         unsigned char eui64[8];
29         int i = 0;
30
31         if (!(skb_mac_header(skb) >= skb->head &&
32               skb_mac_header(skb) + ETH_HLEN <= skb->data) &&
33             offset != 0) {
34                 *hotdrop = true;
35                 return false;
36         }
37
38         memset(eui64, 0, sizeof(eui64));
39
40         if (eth_hdr(skb)->h_proto == htons(ETH_P_IPV6)) {
41                 if (ipv6_hdr(skb)->version == 0x6) {
42                         memcpy(eui64, eth_hdr(skb)->h_source, 3);
43                         memcpy(eui64 + 5, eth_hdr(skb)->h_source + 3, 3);
44                         eui64[3] = 0xff;
45                         eui64[4] = 0xfe;
46                         eui64[0] ^= 0x02;
47
48                         i = 0;
49                         while (ipv6_hdr(skb)->saddr.s6_addr[8 + i] == eui64[i]
50                                && i < 8)
51                                 i++;
52
53                         if (i == 8)
54                                 return true;
55                 }
56         }
57
58         return false;
59 }
60
61 static struct xt_match eui64_mt6_reg __read_mostly = {
62         .name           = "eui64",
63         .family         = AF_INET6,
64         .match          = eui64_mt6,
65         .matchsize      = sizeof(int),
66         .hooks          = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_IN) |
67                           (1 << NF_INET_FORWARD),
68         .me             = THIS_MODULE,
69 };
70
71 static int __init eui64_mt6_init(void)
72 {
73         return xt_register_match(&eui64_mt6_reg);
74 }
75
76 static void __exit eui64_mt6_exit(void)
77 {
78         xt_unregister_match(&eui64_mt6_reg);
79 }
80
81 module_init(eui64_mt6_init);
82 module_exit(eui64_mt6_exit);