1 /* This is a module which is used for setting the NFMARK field of an skb. */
3 /* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
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.
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
13 #include <net/checksum.h>
15 #include <linux/netfilter_ipv4/ip_tables.h>
16 #include <linux/netfilter_ipv4/ipt_MARK.h>
18 MODULE_LICENSE("GPL");
19 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
20 MODULE_DESCRIPTION("iptables MARK modification module");
23 target_v0(struct sk_buff **pskb,
24 const struct net_device *in,
25 const struct net_device *out,
30 const struct ipt_mark_target_info *markinfo = targinfo;
32 if((*pskb)->nfmark != markinfo->mark)
33 (*pskb)->nfmark = markinfo->mark;
39 target_v1(struct sk_buff **pskb,
40 const struct net_device *in,
41 const struct net_device *out,
46 const struct ipt_mark_target_info_v1 *markinfo = targinfo;
49 switch (markinfo->mode) {
51 mark = markinfo->mark;
55 mark = (*pskb)->nfmark & markinfo->mark;
59 mark = (*pskb)->nfmark | markinfo->mark;
63 if((*pskb)->nfmark != mark)
64 (*pskb)->nfmark = mark;
71 checkentry_v0(const char *tablename,
72 const struct ipt_entry *e,
74 unsigned int targinfosize,
75 unsigned int hook_mask)
77 struct ipt_mark_target_info *markinfo = targinfo;
79 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_mark_target_info))) {
80 printk(KERN_WARNING "MARK: targinfosize %u != %Zu\n",
82 IPT_ALIGN(sizeof(struct ipt_mark_target_info)));
86 if (strcmp(tablename, "mangle") != 0) {
87 printk(KERN_WARNING "MARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
91 if (markinfo->mark > 0xffffffff) {
92 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
100 checkentry_v1(const char *tablename,
101 const struct ipt_entry *e,
103 unsigned int targinfosize,
104 unsigned int hook_mask)
106 struct ipt_mark_target_info_v1 *markinfo = targinfo;
108 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_mark_target_info_v1))){
109 printk(KERN_WARNING "MARK: targinfosize %u != %Zu\n",
111 IPT_ALIGN(sizeof(struct ipt_mark_target_info_v1)));
115 if (strcmp(tablename, "mangle") != 0) {
116 printk(KERN_WARNING "MARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
120 if (markinfo->mode != IPT_MARK_SET
121 && markinfo->mode != IPT_MARK_AND
122 && markinfo->mode != IPT_MARK_OR) {
123 printk(KERN_WARNING "MARK: unknown mode %u\n",
128 if (markinfo->mark > 0xffffffff) {
129 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
136 static struct ipt_target ipt_mark_reg_v0 = {
139 .checkentry = checkentry_v0,
144 static struct ipt_target ipt_mark_reg_v1 = {
147 .checkentry = checkentry_v1,
152 static int __init init(void)
156 err = ipt_register_target(&ipt_mark_reg_v0);
158 err = ipt_register_target(&ipt_mark_reg_v1);
160 ipt_unregister_target(&ipt_mark_reg_v0);
165 static void __exit fini(void)
167 ipt_unregister_target(&ipt_mark_reg_v0);
168 ipt_unregister_target(&ipt_mark_reg_v1);