1 diff -urN linux.old/include/linux/netfilter_ipv4/ip_conntrack.h linux.dev/include/linux/netfilter_ipv4/ip_conntrack.h
2 --- linux.old/include/linux/netfilter_ipv4/ip_conntrack.h 2005-08-20 20:02:06.619827000 +0200
3 +++ linux.dev/include/linux/netfilter_ipv4/ip_conntrack.h 2005-08-20 20:19:23.302029232 +0200
5 unsigned int app_data_len;
8 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
13 /* get master conntrack via master expectation */
14 diff -urN linux.old/include/linux/netfilter_ipv4/ipt_CONNMARK.h linux.dev/include/linux/netfilter_ipv4/ipt_CONNMARK.h
15 --- linux.old/include/linux/netfilter_ipv4/ipt_CONNMARK.h 1970-01-01 01:00:00.000000000 +0100
16 +++ linux.dev/include/linux/netfilter_ipv4/ipt_CONNMARK.h 2005-08-20 20:19:41.058329864 +0200
18 +#ifndef _IPT_CONNMARK_H_target
19 +#define _IPT_CONNMARK_H_target
21 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
22 + * by Henrik Nordstrom <hno@marasystems.com>
24 + * This program is free software; you can redistribute it and/or modify
25 + * it under the terms of the GNU General Public License as published by
26 + * the Free Software Foundation; either version 2 of the License, or
27 + * (at your option) any later version.
31 + IPT_CONNMARK_SET = 0,
33 + IPT_CONNMARK_RESTORE
36 +struct ipt_connmark_target_info {
42 +#endif /*_IPT_CONNMARK_H_target*/
43 diff -urN linux.old/include/linux/netfilter_ipv4/ipt_connmark.h linux.dev/include/linux/netfilter_ipv4/ipt_connmark.h
44 --- linux.old/include/linux/netfilter_ipv4/ipt_connmark.h 1970-01-01 01:00:00.000000000 +0100
45 +++ linux.dev/include/linux/netfilter_ipv4/ipt_connmark.h 2005-08-20 20:19:41.058329864 +0200
47 +#ifndef _IPT_CONNMARK_H
48 +#define _IPT_CONNMARK_H
50 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
51 + * by Henrik Nordstrom <hno@marasystems.com>
53 + * This program is free software; you can redistribute it and/or modify
54 + * it under the terms of the GNU General Public License as published by
55 + * the Free Software Foundation; either version 2 of the License, or
56 + * (at your option) any later version.
59 +struct ipt_connmark_info {
60 + unsigned long mark, mask;
64 +#endif /*_IPT_CONNMARK_H*/
65 diff -urN linux.old/net/ipv4/netfilter/Config.in linux.dev/net/ipv4/netfilter/Config.in
66 --- linux.old/net/ipv4/netfilter/Config.in 2005-08-20 20:02:09.325416000 +0200
67 +++ linux.dev/net/ipv4/netfilter/Config.in 2005-08-20 20:29:11.546602464 +0200
70 tristate 'Connection tracking (required for masq/NAT)' CONFIG_IP_NF_CONNTRACK
71 if [ "$CONFIG_IP_NF_CONNTRACK" != "n" ]; then
72 - dep_tristate ' FTP protocol support' CONFIG_IP_NF_FTP $CONFIG_IP_NF_CONNTRACK
73 + bool ' Connection mark tracking support' CONFIG_IP_NF_CONNTRACK_MARK
74 + dep_tristate ' FTP protocol support' CONFIG_IP_NF_FTP $CONFIG_IP_NF_CONNTRACKa
75 dep_tristate ' Amanda protocol support' CONFIG_IP_NF_AMANDA $CONFIG_IP_NF_CONNTRACK
76 dep_tristate ' TFTP protocol support' CONFIG_IP_NF_TFTP $CONFIG_IP_NF_CONNTRACK
77 dep_tristate ' IRC protocol support' CONFIG_IP_NF_IRC $CONFIG_IP_NF_CONNTRACK
79 if [ "$CONFIG_IP_NF_CONNTRACK" != "n" ]; then
80 dep_tristate ' Connection state match support' CONFIG_IP_NF_MATCH_STATE $CONFIG_IP_NF_CONNTRACK $CONFIG_IP_NF_IPTABLES
81 dep_tristate ' Connection tracking match support' CONFIG_IP_NF_MATCH_CONNTRACK $CONFIG_IP_NF_CONNTRACK $CONFIG_IP_NF_IPTABLES
82 + if [ "$CONFIG_IP_NF_CONNTRACK_MARK" != "n" ]; then
83 + dep_tristate ' Connection mark match support' CONFIG_IP_NF_MATCH_CONNMARK $CONFIG_IP_NF_IPTABLES
86 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
87 dep_tristate ' Unclean match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_UNCLEAN $CONFIG_IP_NF_IPTABLES
90 dep_tristate ' MARK target support' CONFIG_IP_NF_TARGET_MARK $CONFIG_IP_NF_MANGLE
92 + if [ "$CONFIG_IP_NF_CONNTRACK_MARK" != "n" ]; then
93 + dep_tristate ' CONNMARK target support' CONFIG_IP_NF_TARGET_CONNMARK $CONFIG_IP_NF_IPTABLES
95 dep_tristate ' LOG target support' CONFIG_IP_NF_TARGET_LOG $CONFIG_IP_NF_IPTABLES
96 dep_tristate ' TTL target support' CONFIG_IP_NF_TARGET_TTL $CONFIG_IP_NF_IPTABLES
97 dep_tristate ' ULOG target support' CONFIG_IP_NF_TARGET_ULOG $CONFIG_IP_NF_IPTABLES
98 diff -urN linux.old/net/ipv4/netfilter/Makefile linux.dev/net/ipv4/netfilter/Makefile
99 --- linux.old/net/ipv4/netfilter/Makefile 2005-08-20 20:02:09.326416000 +0200
100 +++ linux.dev/net/ipv4/netfilter/Makefile 2005-08-20 20:29:54.081136232 +0200
103 obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
104 obj-$(CONFIG_IP_NF_MATCH_STATE) += ipt_state.o
105 +obj-$(CONFIG_IP_NF_MATCH_CONNMARK) += ipt_connmark.o
106 obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += ipt_conntrack.o
107 obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
108 obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
110 obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
111 obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
112 obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
113 +obj-$(CONFIG_IP_NF_TARGET_CONNMARK) += ipt_CONNMARK.o
114 obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
115 obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
116 obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o
117 diff -urN linux.old/net/ipv4/netfilter/ip_conntrack_core.c linux.dev/net/ipv4/netfilter/ip_conntrack_core.c
118 --- linux.old/net/ipv4/netfilter/ip_conntrack_core.c 2005-08-20 20:02:06.828795000 +0200
119 +++ linux.dev/net/ipv4/netfilter/ip_conntrack_core.c 2005-08-20 20:33:23.308328864 +0200
121 __set_bit(IPS_EXPECTED_BIT, &conntrack->status);
122 conntrack->master = expected;
123 expected->sibling = conntrack;
124 +#ifdef CONFIG_IP_NF_CONNTRACK_MARK
125 + conntrack->mark = expected->expectant->mark;
127 LIST_DELETE(&ip_conntrack_expect_list, expected);
128 expected->expectant->expecting--;
129 nf_conntrack_get(&master_ct(conntrack)->infos[0]);
130 diff -urN linux.old/net/ipv4/netfilter/ip_conntrack_standalone.c linux.dev/net/ipv4/netfilter/ip_conntrack_standalone.c
131 --- linux.old/net/ipv4/netfilter/ip_conntrack_standalone.c 2005-08-20 20:02:06.583833000 +0200
132 +++ linux.dev/net/ipv4/netfilter/ip_conntrack_standalone.c 2005-08-20 20:32:15.364657872 +0200
134 len += sprintf(buffer + len, "[ASSURED] ");
135 len += sprintf(buffer + len, "use=%u ",
136 atomic_read(&conntrack->ct_general.use));
137 + #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
138 + len += sprintf(buffer + len, "mark=%ld ", conntrack->mark);
141 #if defined(CONFIG_IP_NF_MATCH_LAYER7) || defined(CONFIG_IP_NF_MATCH_LAYER7_MODULE)
142 if(conntrack->layer7.app_proto)
143 diff -urN linux.old/net/ipv4/netfilter/ipt_CONNMARK.c linux.dev/net/ipv4/netfilter/ipt_CONNMARK.c
144 --- linux.old/net/ipv4/netfilter/ipt_CONNMARK.c 1970-01-01 01:00:00.000000000 +0100
145 +++ linux.dev/net/ipv4/netfilter/ipt_CONNMARK.c 2005-08-20 20:21:28.666970864 +0200
147 +/* This kernel module is used to modify the connection mark values, or
148 + * to optionally restore the skb nfmark from the connection mark
150 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
151 + * by Henrik Nordstrom <hno@marasystems.com>
153 + * This program is free software; you can redistribute it and/or modify
154 + * it under the terms of the GNU General Public License as published by
155 + * the Free Software Foundation; either version 2 of the License, or
156 + * (at your option) any later version.
158 + * This program is distributed in the hope that it will be useful,
159 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
160 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
161 + * GNU General Public License for more details.
163 + * You should have received a copy of the GNU General Public License
164 + * along with this program; if not, write to the Free Software
165 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
167 +#include <linux/module.h>
168 +#include <linux/skbuff.h>
169 +#include <linux/ip.h>
170 +#include <net/checksum.h>
172 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
173 +MODULE_DESCRIPTION("IP tables CONNMARK matching module");
174 +MODULE_LICENSE("GPL");
176 +#include <linux/netfilter_ipv4/ip_tables.h>
177 +#include <linux/netfilter_ipv4/ipt_CONNMARK.h>
178 +#include <linux/netfilter_ipv4/ip_conntrack.h>
181 +target(struct sk_buff **pskb,
182 + unsigned int hooknum,
183 + const struct net_device *in,
184 + const struct net_device *out,
185 + const void *targinfo,
188 + const struct ipt_connmark_target_info *markinfo = targinfo;
189 + unsigned long diff;
190 + unsigned long nfmark;
191 + unsigned long newmark;
193 + enum ip_conntrack_info ctinfo;
194 + struct ip_conntrack *ct = ip_conntrack_get((*pskb), &ctinfo);
196 + switch(markinfo->mode) {
197 + case IPT_CONNMARK_SET:
198 + newmark = (ct->mark & ~markinfo->mask) | markinfo->mark;
199 + if (newmark != ct->mark)
200 + ct->mark = newmark;
202 + case IPT_CONNMARK_SAVE:
203 + newmark = (ct->mark & ~markinfo->mask) | ((*pskb)->nfmark & markinfo->mask);
204 + if (ct->mark != newmark)
205 + ct->mark = newmark;
207 + case IPT_CONNMARK_RESTORE:
208 + nfmark = (*pskb)->nfmark;
209 + diff = (ct->mark ^ nfmark & markinfo->mask);
211 + (*pskb)->nfmark = nfmark ^ diff;
212 + (*pskb)->nfcache |= NFC_ALTERED;
218 + return IPT_CONTINUE;
222 +checkentry(const char *tablename,
223 + const struct ipt_entry *e,
225 + unsigned int targinfosize,
226 + unsigned int hook_mask)
228 + struct ipt_connmark_target_info *matchinfo = targinfo;
229 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_connmark_target_info))) {
230 + printk(KERN_WARNING "CONNMARK: targinfosize %u != %Zu\n",
232 + IPT_ALIGN(sizeof(struct ipt_connmark_target_info)));
236 + if (matchinfo->mode == IPT_CONNMARK_RESTORE) {
237 + if (strcmp(tablename, "mangle") != 0) {
238 + printk(KERN_WARNING "CONNMARK: restore can only be called from \"mangle\" table, not \"%s\"\n", tablename);
246 +static struct ipt_target ipt_connmark_reg = {
247 + .name = "CONNMARK",
249 + .checkentry = &checkentry,
253 +static int __init init(void)
255 + return ipt_register_target(&ipt_connmark_reg);
258 +static void __exit fini(void)
260 + ipt_unregister_target(&ipt_connmark_reg);
265 diff -urN linux.old/net/ipv4/netfilter/ipt_connmark.c linux.dev/net/ipv4/netfilter/ipt_connmark.c
266 --- linux.old/net/ipv4/netfilter/ipt_connmark.c 1970-01-01 01:00:00.000000000 +0100
267 +++ linux.dev/net/ipv4/netfilter/ipt_connmark.c 2005-08-20 20:21:28.666970864 +0200
269 +/* This kernel module matches connection mark values set by the
272 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
273 + * by Henrik Nordstrom <hno@marasystems.com>
275 + * This program is free software; you can redistribute it and/or modify
276 + * it under the terms of the GNU General Public License as published by
277 + * the Free Software Foundation; either version 2 of the License, or
278 + * (at your option) any later version.
280 + * This program is distributed in the hope that it will be useful,
281 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
282 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
283 + * GNU General Public License for more details.
285 + * You should have received a copy of the GNU General Public License
286 + * along with this program; if not, write to the Free Software
287 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
290 +#include <linux/module.h>
291 +#include <linux/skbuff.h>
293 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
294 +MODULE_DESCRIPTION("IP tables connmark match module");
295 +MODULE_LICENSE("GPL");
297 +#include <linux/netfilter_ipv4/ip_tables.h>
298 +#include <linux/netfilter_ipv4/ipt_connmark.h>
299 +#include <linux/netfilter_ipv4/ip_conntrack.h>
302 +match(const struct sk_buff *skb,
303 + const struct net_device *in,
304 + const struct net_device *out,
305 + const void *matchinfo,
311 + const struct ipt_connmark_info *info = matchinfo;
312 + enum ip_conntrack_info ctinfo;
313 + struct ip_conntrack *ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
317 + return ((ct->mark & info->mask) == info->mark) ^ info->invert;
321 +checkentry(const char *tablename,
322 + const struct ipt_ip *ip,
324 + unsigned int matchsize,
325 + unsigned int hook_mask)
327 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_connmark_info)))
333 +static struct ipt_match connmark_match = {
334 + .name = "connmark",
336 + .checkentry = &checkentry,
340 +static int __init init(void)
342 + return ipt_register_match(&connmark_match);
345 +static void __exit fini(void)
347 + ipt_unregister_match(&connmark_match);