more debug output
[linux-2.4.git] / net / ipv6 / netfilter / ip6t_eui64.c
1 /* Kernel module to match EUI64 address parameters. */
2 #include <linux/module.h>
3 #include <linux/skbuff.h>
4 #include <linux/ipv6.h>
5 #include <linux/if_ether.h>
6
7 #include <linux/netfilter_ipv6/ip6_tables.h>
8
9 static int
10 match(const struct sk_buff *skb,
11       const struct net_device *in,
12       const struct net_device *out,
13       const void *matchinfo,
14       int offset,
15       const void *hdr,
16       u_int16_t datalen,
17       int *hotdrop)
18 {
19
20     unsigned char eui64[8];
21     int i=0;
22
23      if ( !(skb->mac.raw >= skb->head
24                 && (skb->mac.raw + ETH_HLEN) <= skb->data)
25                 && offset != 0) {
26                         *hotdrop = 1;
27                         return 0;
28                 }
29     
30     memset(eui64, 0, sizeof(eui64));
31
32     if (skb->mac.ethernet->h_proto == ntohs(ETH_P_IPV6)) {
33       if (skb->nh.ipv6h->version == 0x6) { 
34          memcpy(eui64, skb->mac.ethernet->h_source, 3);
35          memcpy(eui64 + 5, skb->mac.ethernet->h_source + 3, 3);
36          eui64[3]=0xff;
37          eui64[4]=0xfe;
38          eui64[0] |= 0x02;
39
40          i=0;
41          while ((skb->nh.ipv6h->saddr.in6_u.u6_addr8[8+i] ==
42                          eui64[i]) && (i<8)) i++;
43
44          if ( i == 8 )
45                 return 1;
46       }
47     }
48
49     return 0;
50 }
51
52 static int
53 ip6t_eui64_checkentry(const char *tablename,
54                    const struct ip6t_ip6 *ip,
55                    void *matchinfo,
56                    unsigned int matchsize,
57                    unsigned int hook_mask)
58 {
59         if (hook_mask
60             & ~((1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_IN) |
61                 (1 << NF_IP6_FORWARD))) {
62                 printk("ip6t_eui64: only valid for PRE_ROUTING, LOCAL_IN or FORWARD.\n");
63                 return 0;
64         }
65
66         if (matchsize != IP6T_ALIGN(sizeof(int)))
67                 return 0;
68
69         return 1;
70 }
71
72 static struct ip6t_match eui64_match
73 = { { NULL, NULL }, "eui64", &match, &ip6t_eui64_checkentry, NULL, THIS_MODULE };
74
75 static int __init init(void)
76 {
77         return ip6t_register_match(&eui64_match);
78 }
79
80 static void __exit fini(void)
81 {
82         ip6t_unregister_match(&eui64_match);
83 }
84
85 module_init(init);
86 module_exit(fini);
87 MODULE_DESCRIPTION("IPv6 EUI64 address checking match");
88 MODULE_LICENSE("GPL");
89 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");