vserver 1.9.5.x5
[linux-2.6.git] / net / ipv6 / netfilter / ip6t_mac.c
1 /* Kernel module to match MAC address parameters. */
2
3 /* (C) 1999-2001 Paul `Rusty' Russell
4  * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13 #include <linux/if_ether.h>
14
15 #include <linux/netfilter_ipv6/ip6t_mac.h>
16 #include <linux/netfilter_ipv6/ip6_tables.h>
17
18 MODULE_LICENSE("GPL");
19 MODULE_DESCRIPTION("MAC address matching module for IPv6");
20 MODULE_AUTHOR("Netfilter Core Teaam <coreteam@netfilter.org>");
21
22 static int
23 match(const struct sk_buff *skb,
24       const struct net_device *in,
25       const struct net_device *out,
26       const void *matchinfo,
27       int offset,
28       unsigned int protoff,
29       int *hotdrop)
30 {
31     const struct ip6t_mac_info *info = matchinfo;
32
33     /* Is mac pointer valid? */
34     return (skb->mac.raw >= skb->head
35             && (skb->mac.raw + ETH_HLEN) <= skb->data
36             /* If so, compare... */
37             && ((memcmp(eth_hdr(skb)->h_source, info->srcaddr, ETH_ALEN)
38                 == 0) ^ info->invert));
39 }
40
41 static int
42 ip6t_mac_checkentry(const char *tablename,
43                    const struct ip6t_ip6 *ip,
44                    void *matchinfo,
45                    unsigned int matchsize,
46                    unsigned int hook_mask)
47 {
48         if (hook_mask
49             & ~((1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_IN)
50                 | (1 << NF_IP6_FORWARD))) {
51                 printk("ip6t_mac: only valid for PRE_ROUTING, LOCAL_IN or"
52                        " FORWARD\n");
53                 return 0;
54         }
55
56         if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_mac_info)))
57                 return 0;
58
59         return 1;
60 }
61
62 static struct ip6t_match mac_match = {
63         .name           = "mac",
64         .match          = &match,
65         .checkentry     = &ip6t_mac_checkentry,
66         .me             = THIS_MODULE,
67 };
68
69 static int __init init(void)
70 {
71         return ip6t_register_match(&mac_match);
72 }
73
74 static void __exit fini(void)
75 {
76         ip6t_unregister_match(&mac_match);
77 }
78
79 module_init(init);
80 module_exit(fini);