ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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_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       const void *hdr,
28       u_int16_t datalen,
29       int *hotdrop)
30 {
31
32     unsigned char eui64[8];
33     int i=0;
34
35      if ( !(skb->mac.raw >= skb->head
36                 && (skb->mac.raw + ETH_HLEN) <= skb->data)
37                 && offset != 0) {
38                         *hotdrop = 1;
39                         return 0;
40                 }
41     
42     memset(eui64, 0, sizeof(eui64));
43
44     if (skb->mac.ethernet->h_proto == ntohs(ETH_P_IPV6)) {
45       if (skb->nh.ipv6h->version == 0x6) { 
46          memcpy(eui64, skb->mac.ethernet->h_source, 3);
47          memcpy(eui64 + 5, skb->mac.ethernet->h_source + 3, 3);
48          eui64[3]=0xff;
49          eui64[4]=0xfe;
50          eui64[0] |= 0x02;
51
52          i=0;
53          while ((skb->nh.ipv6h->saddr.s6_addr[8+i] ==
54                          eui64[i]) && (i<8)) i++;
55
56          if ( i == 8 )
57                 return 1;
58       }
59     }
60
61     return 0;
62 }
63
64 static int
65 ip6t_eui64_checkentry(const char *tablename,
66                    const struct ip6t_ip6 *ip,
67                    void *matchinfo,
68                    unsigned int matchsize,
69                    unsigned int hook_mask)
70 {
71         if (hook_mask
72             & ~((1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_IN) |
73                 (1 << NF_IP6_PRE_ROUTING) )) {
74                 printk("ip6t_eui64: only valid for PRE_ROUTING, LOCAL_IN or FORWARD.\n");
75                 return 0;
76         }
77
78         if (matchsize != IP6T_ALIGN(sizeof(int)))
79                 return 0;
80
81         return 1;
82 }
83
84 static struct ip6t_match eui64_match = {
85         .name           = "eui64",
86         .match          = &match,
87         .checkentry     = &ip6t_eui64_checkentry,
88         .me             = THIS_MODULE,
89 };
90
91 static int __init init(void)
92 {
93         return ip6t_register_match(&eui64_match);
94 }
95
96 static void __exit fini(void)
97 {
98         ip6t_unregister_match(&eui64_match);
99 }
100
101 module_init(init);
102 module_exit(fini);