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 mark_tg_v0(struct sk_buff *skb, const struct net_device *in,
26 const struct net_device *out, unsigned int hooknum,
27 const struct xt_target *target, const void *targinfo)
29 const struct xt_mark_target_info *markinfo = targinfo;
31 skb->mark = markinfo->mark;
36 mark_tg(struct sk_buff *skb, const struct net_device *in,
37 const struct net_device *out, unsigned int hooknum,
38 const struct xt_target *target, const void *targinfo)
40 const struct xt_mark_target_info_v1 *markinfo = targinfo;
43 switch (markinfo->mode) {
45 mark = markinfo->mark;
49 mark = skb->mark & markinfo->mark;
53 mark = skb->mark | markinfo->mark;
62 mark_tg_check_v0(const char *tablename, const void *entry,
63 const struct xt_target *target, void *targinfo,
64 unsigned int hook_mask)
66 const struct xt_mark_target_info *markinfo = targinfo;
68 if (markinfo->mark > 0xffffffff) {
69 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
76 mark_tg_check(const char *tablename, const void *entry,
77 const struct xt_target *target, void *targinfo,
78 unsigned int hook_mask)
80 const struct xt_mark_target_info_v1 *markinfo = targinfo;
82 if (markinfo->mode != XT_MARK_SET
83 && markinfo->mode != XT_MARK_AND
84 && markinfo->mode != XT_MARK_OR) {
85 printk(KERN_WARNING "MARK: unknown mode %u\n",
89 if (markinfo->mark > 0xffffffff) {
90 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
97 struct compat_xt_mark_target_info_v1 {
104 static void mark_tg_compat_from_user(void *dst, void *src)
106 const struct compat_xt_mark_target_info_v1 *cm = src;
107 struct xt_mark_target_info_v1 m = {
111 memcpy(dst, &m, sizeof(m));
114 static int mark_tg_compat_to_user(void __user *dst, void *src)
116 const struct xt_mark_target_info_v1 *m = src;
117 struct compat_xt_mark_target_info_v1 cm = {
121 return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
123 #endif /* CONFIG_COMPAT */
125 static struct xt_target mark_tg_reg[] __read_mostly = {
130 .checkentry = mark_tg_check_v0,
131 .target = mark_tg_v0,
132 .targetsize = sizeof(struct xt_mark_target_info),
140 .checkentry = mark_tg_check,
142 .targetsize = sizeof(struct xt_mark_target_info_v1),
144 .compatsize = sizeof(struct compat_xt_mark_target_info_v1),
145 .compat_from_user = mark_tg_compat_from_user,
146 .compat_to_user = mark_tg_compat_to_user,
155 .checkentry = mark_tg_check_v0,
156 .target = mark_tg_v0,
157 .targetsize = sizeof(struct xt_mark_target_info),
165 .checkentry = mark_tg_check,
167 .targetsize = sizeof(struct xt_mark_target_info_v1),
169 .compatsize = sizeof(struct compat_xt_mark_target_info_v1),
170 .compat_from_user = mark_tg_compat_from_user,
171 .compat_to_user = mark_tg_compat_to_user,
178 static int __init mark_tg_init(void)
180 return xt_register_targets(mark_tg_reg, ARRAY_SIZE(mark_tg_reg));
183 static void __exit mark_tg_exit(void)
185 xt_unregister_targets(mark_tg_reg, ARRAY_SIZE(mark_tg_reg));
188 module_init(mark_tg_init);
189 module_exit(mark_tg_exit);