[PATCH] fix build on x86_64 with !CONFIG_HOTPLUG_CPU
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / netfilter / xt_CONNMARK.c
blob22506e376be5b1a17a904720c391805eba6d6163
1 /* This kernel module is used to modify the connection mark values, or
2 * to optionally restore the skb nfmark from the connection mark
4 * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
5 * by Henrik Nordstrom <hno@marasystems.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/module.h>
22 #include <linux/skbuff.h>
23 #include <linux/ip.h>
24 #include <net/checksum.h>
26 MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
27 MODULE_DESCRIPTION("IP tables CONNMARK matching module");
28 MODULE_LICENSE("GPL");
29 MODULE_ALIAS("ipt_CONNMARK");
31 #include <linux/netfilter/x_tables.h>
32 #include <linux/netfilter/xt_CONNMARK.h>
33 #include <net/netfilter/nf_conntrack_compat.h>
35 static unsigned int
36 target(struct sk_buff **pskb,
37 const struct net_device *in,
38 const struct net_device *out,
39 unsigned int hooknum,
40 const void *targinfo,
41 void *userinfo)
43 const struct xt_connmark_target_info *markinfo = targinfo;
44 u_int32_t diff;
45 u_int32_t nfmark;
46 u_int32_t newmark;
47 u_int32_t ctinfo;
48 u_int32_t *ctmark = nf_ct_get_mark(*pskb, &ctinfo);
50 if (ctmark) {
51 switch(markinfo->mode) {
52 case XT_CONNMARK_SET:
53 newmark = (*ctmark & ~markinfo->mask) | markinfo->mark;
54 if (newmark != *ctmark)
55 *ctmark = newmark;
56 break;
57 case XT_CONNMARK_SAVE:
58 newmark = (*ctmark & ~markinfo->mask) | ((*pskb)->nfmark & markinfo->mask);
59 if (*ctmark != newmark)
60 *ctmark = newmark;
61 break;
62 case XT_CONNMARK_RESTORE:
63 nfmark = (*pskb)->nfmark;
64 diff = (*ctmark ^ nfmark) & markinfo->mask;
65 if (diff != 0)
66 (*pskb)->nfmark = nfmark ^ diff;
67 break;
71 return XT_CONTINUE;
74 static int
75 checkentry(const char *tablename,
76 const void *entry,
77 void *targinfo,
78 unsigned int targinfosize,
79 unsigned int hook_mask)
81 struct xt_connmark_target_info *matchinfo = targinfo;
82 if (targinfosize != XT_ALIGN(sizeof(struct xt_connmark_target_info))) {
83 printk(KERN_WARNING "CONNMARK: targinfosize %u != %Zu\n",
84 targinfosize,
85 XT_ALIGN(sizeof(struct xt_connmark_target_info)));
86 return 0;
89 if (matchinfo->mode == XT_CONNMARK_RESTORE) {
90 if (strcmp(tablename, "mangle") != 0) {
91 printk(KERN_WARNING "CONNMARK: restore can only be called from \"mangle\" table, not \"%s\"\n", tablename);
92 return 0;
96 if (matchinfo->mark > 0xffffffff || matchinfo->mask > 0xffffffff) {
97 printk(KERN_WARNING "CONNMARK: Only supports 32bit mark\n");
98 return 0;
101 return 1;
104 static struct xt_target connmark_reg = {
105 .name = "CONNMARK",
106 .target = &target,
107 .checkentry = &checkentry,
108 .me = THIS_MODULE
110 static struct xt_target connmark6_reg = {
111 .name = "CONNMARK",
112 .target = &target,
113 .checkentry = &checkentry,
114 .me = THIS_MODULE
117 static int __init init(void)
119 int ret;
121 need_conntrack();
123 ret = xt_register_target(AF_INET, &connmark_reg);
124 if (ret)
125 return ret;
127 ret = xt_register_target(AF_INET6, &connmark6_reg);
128 if (ret)
129 xt_unregister_target(AF_INET, &connmark_reg);
131 return ret;
134 static void __exit fini(void)
136 xt_unregister_target(AF_INET, &connmark_reg);
137 xt_unregister_target(AF_INET6, &connmark6_reg);
140 module_init(init);
141 module_exit(fini);