ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / net / ipv4 / netfilter / ipt_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_ipv4/ip_tables.h>
16 #include <linux/netfilter_ipv4/ipt_MARK.h>
17
18 MODULE_LICENSE("GPL");
19 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
20 MODULE_DESCRIPTION("iptables MARK modification module");
21
22 static unsigned int
23 target(struct sk_buff **pskb,
24        const struct net_device *in,
25        const struct net_device *out,
26        unsigned int hooknum,
27        const void *targinfo,
28        void *userinfo)
29 {
30         const struct ipt_mark_target_info *markinfo = targinfo;
31
32         if((*pskb)->nfmark != markinfo->mark) {
33                 (*pskb)->nfmark = markinfo->mark;
34                 (*pskb)->nfcache |= NFC_ALTERED;
35         }
36         return IPT_CONTINUE;
37 }
38
39 static int
40 checkentry(const char *tablename,
41            const struct ipt_entry *e,
42            void *targinfo,
43            unsigned int targinfosize,
44            unsigned int hook_mask)
45 {
46         if (targinfosize != IPT_ALIGN(sizeof(struct ipt_mark_target_info))) {
47                 printk(KERN_WARNING "MARK: targinfosize %u != %Zu\n",
48                        targinfosize,
49                        IPT_ALIGN(sizeof(struct ipt_mark_target_info)));
50                 return 0;
51         }
52
53         if (strcmp(tablename, "mangle") != 0) {
54                 printk(KERN_WARNING "MARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
55                 return 0;
56         }
57
58         return 1;
59 }
60
61 static struct ipt_target ipt_mark_reg = {
62         .name           = "MARK",
63         .target         = target,
64         .checkentry     = checkentry,
65         .me             = THIS_MODULE,
66 };
67
68 static int __init init(void)
69 {
70         return ipt_register_target(&ipt_mark_reg);
71 }
72
73 static void __exit fini(void)
74 {
75         ipt_unregister_target(&ipt_mark_reg);
76 }
77
78 module_init(init);
79 module_exit(fini);