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/x_tables.h>
16 #include <linux/netfilter/xt_MARK.h>
18 MODULE_LICENSE("GPL");
19 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
20 MODULE_DESCRIPTION("ip[6]tables MARK modification module");
21 MODULE_ALIAS("ipt_MARK");
22 MODULE_ALIAS("ip6t_MARK");
25 target_v0(struct sk_buff **pskb,
26 const struct net_device *in,
27 const struct net_device *out,
29 const struct xt_target *target,
33 const struct xt_mark_target_info *markinfo = targinfo;
35 if((*pskb)->nfmark != markinfo->mark)
36 (*pskb)->nfmark = markinfo->mark;
42 target_v1(struct sk_buff **pskb,
43 const struct net_device *in,
44 const struct net_device *out,
46 const struct xt_target *target,
50 const struct xt_mark_target_info_v1 *markinfo = targinfo;
53 switch (markinfo->mode) {
55 mark = markinfo->mark;
59 mark = (*pskb)->nfmark & markinfo->mark;
63 mark = (*pskb)->nfmark | markinfo->mark;
67 if((*pskb)->nfmark != mark)
68 (*pskb)->nfmark = mark;
75 checkentry_v0(const char *tablename,
77 const struct xt_target *target,
79 unsigned int targinfosize,
80 unsigned int hook_mask)
82 struct xt_mark_target_info *markinfo = targinfo;
84 if (markinfo->mark > 0xffffffff) {
85 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
92 checkentry_v1(const char *tablename,
94 const struct xt_target *target,
96 unsigned int targinfosize,
97 unsigned int hook_mask)
99 struct xt_mark_target_info_v1 *markinfo = targinfo;
101 if (markinfo->mode != XT_MARK_SET
102 && markinfo->mode != XT_MARK_AND
103 && markinfo->mode != XT_MARK_OR) {
104 printk(KERN_WARNING "MARK: unknown mode %u\n",
108 if (markinfo->mark > 0xffffffff) {
109 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
115 static struct xt_target ipt_mark_reg_v0 = {
118 .targetsize = sizeof(struct xt_mark_target_info),
120 .checkentry = checkentry_v0,
125 static struct xt_target ipt_mark_reg_v1 = {
128 .targetsize = sizeof(struct xt_mark_target_info_v1),
130 .checkentry = checkentry_v1,
135 static struct xt_target ip6t_mark_reg_v0 = {
138 .targetsize = sizeof(struct xt_mark_target_info),
140 .checkentry = checkentry_v0,
145 static int __init init(void)
149 err = xt_register_target(AF_INET, &ipt_mark_reg_v0);
153 err = xt_register_target(AF_INET, &ipt_mark_reg_v1);
155 xt_unregister_target(AF_INET, &ipt_mark_reg_v0);
157 err = xt_register_target(AF_INET6, &ip6t_mark_reg_v0);
159 xt_unregister_target(AF_INET, &ipt_mark_reg_v0);
160 xt_unregister_target(AF_INET, &ipt_mark_reg_v1);
166 static void __exit fini(void)
168 xt_unregister_target(AF_INET, &ipt_mark_reg_v0);
169 xt_unregister_target(AF_INET, &ipt_mark_reg_v1);
170 xt_unregister_target(AF_INET6, &ip6t_mark_reg_v0);