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 *skb,
26 const struct net_device *in,
27 const struct net_device *out,
29 const struct xt_target *target,
32 const struct xt_mark_target_info *markinfo = targinfo;
34 skb->mark = markinfo->mark;
39 target_v1(struct sk_buff *skb,
40 const struct net_device *in,
41 const struct net_device *out,
43 const struct xt_target *target,
46 const struct xt_mark_target_info_v1 *markinfo = targinfo;
49 switch (markinfo->mode) {
51 mark = markinfo->mark;
55 mark = skb->mark & markinfo->mark;
59 mark = skb->mark | markinfo->mark;
69 checkentry_v0(const char *tablename,
71 const struct xt_target *target,
73 unsigned int hook_mask)
75 const struct xt_mark_target_info *markinfo = targinfo;
77 if (markinfo->mark > 0xffffffff) {
78 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
85 checkentry_v1(const char *tablename,
87 const struct xt_target *target,
89 unsigned int hook_mask)
91 const struct xt_mark_target_info_v1 *markinfo = targinfo;
93 if (markinfo->mode != XT_MARK_SET
94 && markinfo->mode != XT_MARK_AND
95 && markinfo->mode != XT_MARK_OR) {
96 printk(KERN_WARNING "MARK: unknown mode %u\n",
100 if (markinfo->mark > 0xffffffff) {
101 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
108 struct compat_xt_mark_target_info_v1 {
115 static void compat_from_user_v1(void *dst, void *src)
117 const struct compat_xt_mark_target_info_v1 *cm = src;
118 struct xt_mark_target_info_v1 m = {
122 memcpy(dst, &m, sizeof(m));
125 static int compat_to_user_v1(void __user *dst, void *src)
127 const struct xt_mark_target_info_v1 *m = src;
128 struct compat_xt_mark_target_info_v1 cm = {
132 return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
134 #endif /* CONFIG_COMPAT */
136 static struct xt_target xt_mark_target[] __read_mostly = {
141 .checkentry = checkentry_v0,
143 .targetsize = sizeof(struct xt_mark_target_info),
151 .checkentry = checkentry_v1,
153 .targetsize = sizeof(struct xt_mark_target_info_v1),
155 .compatsize = sizeof(struct compat_xt_mark_target_info_v1),
156 .compat_from_user = compat_from_user_v1,
157 .compat_to_user = compat_to_user_v1,
166 .checkentry = checkentry_v0,
168 .targetsize = sizeof(struct xt_mark_target_info),
174 static int __init xt_mark_init(void)
176 return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
179 static void __exit xt_mark_fini(void)
181 xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
184 module_init(xt_mark_init);
185 module_exit(xt_mark_fini);