[NETFILTER]: Add "revision" support to arp_tables and ip6_tables
[safe/jmp/linux-2.6] / net / ipv6 / netfilter / ip6t_MARK.c
1 /* This is a module which is used for setting the NFMARK field of an skb. */
2
3 /* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
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/ip.h>
13 #include <net/checksum.h>
14
15 #include <linux/netfilter_ipv6/ip6_tables.h>
16 #include <linux/netfilter_ipv6/ip6t_MARK.h>
17
18 MODULE_LICENSE("GPL");
19 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
20
21 static unsigned int
22 target(struct sk_buff **pskb,
23        const struct net_device *in,
24        const struct net_device *out,
25        unsigned int hooknum,
26        const void *targinfo,
27        void *userinfo)
28 {
29         const struct ip6t_mark_target_info *markinfo = targinfo;
30
31         if((*pskb)->nfmark != markinfo->mark)
32                 (*pskb)->nfmark = markinfo->mark;
33
34         return IP6T_CONTINUE;
35 }
36
37 static int
38 checkentry(const char *tablename,
39            const struct ip6t_entry *e,
40            void *targinfo,
41            unsigned int targinfosize,
42            unsigned int hook_mask)
43 {
44         if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_mark_target_info))) {
45                 printk(KERN_WARNING "MARK: targinfosize %u != %Zu\n",
46                        targinfosize,
47                        IP6T_ALIGN(sizeof(struct ip6t_mark_target_info)));
48                 return 0;
49         }
50
51         if (strcmp(tablename, "mangle") != 0) {
52                 printk(KERN_WARNING "MARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
53                 return 0;
54         }
55
56         return 1;
57 }
58
59 static struct ip6t_target ip6t_mark_reg = {
60         .name           = "MARK",
61         .target         = target,
62         .checkentry     = checkentry,
63         .me             = THIS_MODULE
64 };
65
66 static int __init init(void)
67 {
68         printk(KERN_DEBUG "registering ipv6 mark target\n");
69         if (ip6t_register_target(&ip6t_mark_reg))
70                 return -EINVAL;
71
72         return 0;
73 }
74
75 static void __exit fini(void)
76 {
77         ip6t_unregister_target(&ip6t_mark_reg);
78 }
79
80 module_init(init);
81 module_exit(fini);