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,
32 const struct xt_mark_target_info *markinfo = targinfo;
34 if((*pskb)->nfmark != markinfo->mark)
35 (*pskb)->nfmark = markinfo->mark;
41 target_v1(struct sk_buff **pskb,
42 const struct net_device *in,
43 const struct net_device *out,
48 const struct xt_mark_target_info_v1 *markinfo = targinfo;
51 switch (markinfo->mode) {
53 mark = markinfo->mark;
57 mark = (*pskb)->nfmark & markinfo->mark;
61 mark = (*pskb)->nfmark | markinfo->mark;
65 if((*pskb)->nfmark != mark)
66 (*pskb)->nfmark = mark;
73 checkentry_v0(const char *tablename,
76 unsigned int targinfosize,
77 unsigned int hook_mask)
79 struct xt_mark_target_info *markinfo = targinfo;
81 if (targinfosize != XT_ALIGN(sizeof(struct xt_mark_target_info))) {
82 printk(KERN_WARNING "MARK: targinfosize %u != %Zu\n",
84 XT_ALIGN(sizeof(struct xt_mark_target_info)));
88 if (strcmp(tablename, "mangle") != 0) {
89 printk(KERN_WARNING "MARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
93 if (markinfo->mark > 0xffffffff) {
94 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
102 checkentry_v1(const char *tablename,
105 unsigned int targinfosize,
106 unsigned int hook_mask)
108 struct xt_mark_target_info_v1 *markinfo = targinfo;
110 if (targinfosize != XT_ALIGN(sizeof(struct xt_mark_target_info_v1))){
111 printk(KERN_WARNING "MARK: targinfosize %u != %Zu\n",
113 XT_ALIGN(sizeof(struct xt_mark_target_info_v1)));
117 if (strcmp(tablename, "mangle") != 0) {
118 printk(KERN_WARNING "MARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
122 if (markinfo->mode != XT_MARK_SET
123 && markinfo->mode != XT_MARK_AND
124 && markinfo->mode != XT_MARK_OR) {
125 printk(KERN_WARNING "MARK: unknown mode %u\n",
130 if (markinfo->mark > 0xffffffff) {
131 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
138 static struct xt_target ipt_mark_reg_v0 = {
141 .checkentry = checkentry_v0,
146 static struct xt_target ipt_mark_reg_v1 = {
149 .checkentry = checkentry_v1,
154 static struct xt_target ip6t_mark_reg_v0 = {
157 .checkentry = checkentry_v0,
162 static int __init init(void)
166 err = xt_register_target(AF_INET, &ipt_mark_reg_v0);
170 err = xt_register_target(AF_INET, &ipt_mark_reg_v1);
172 xt_unregister_target(AF_INET, &ipt_mark_reg_v0);
174 err = xt_register_target(AF_INET6, &ip6t_mark_reg_v0);
176 xt_unregister_target(AF_INET, &ipt_mark_reg_v0);
177 xt_unregister_target(AF_INET, &ipt_mark_reg_v1);
183 static void __exit fini(void)
185 xt_unregister_target(AF_INET, &ipt_mark_reg_v0);
186 xt_unregister_target(AF_INET, &ipt_mark_reg_v1);
187 xt_unregister_target(AF_INET6, &ip6t_mark_reg_v0);