1 diff -Nurb linux-2.6.22-510/include/linux/netfilter/xt_MARK.h linux-2.6.22-520/include/linux/netfilter/xt_MARK.h
2 --- linux-2.6.22-510/include/linux/netfilter/xt_MARK.h 2007-07-08 19:32:17.000000000 -0400
3 +++ linux-2.6.22-520/include/linux/netfilter/xt_MARK.h 2008-06-06 17:07:56.000000000 -0400
11 struct xt_mark_target_info_v1 {
12 diff -Nurb linux-2.6.22-510/include/linux/netfilter/xt_SETXID.h linux-2.6.22-520/include/linux/netfilter/xt_SETXID.h
13 --- linux-2.6.22-510/include/linux/netfilter/xt_SETXID.h 1969-12-31 19:00:00.000000000 -0500
14 +++ linux-2.6.22-520/include/linux/netfilter/xt_SETXID.h 2008-06-06 17:07:56.000000000 -0400
16 +#ifndef _XT_SETXID_H_target
17 +#define _XT_SETXID_H_target
24 +struct xt_setxid_target_info_v1 {
29 +#endif /*_XT_SETXID_H_target*/
30 diff -Nurb linux-2.6.22-510/include/linux/netfilter_ipv4/ipt_MARK.h linux-2.6.22-520/include/linux/netfilter_ipv4/ipt_MARK.h
31 --- linux-2.6.22-510/include/linux/netfilter_ipv4/ipt_MARK.h 2007-07-08 19:32:17.000000000 -0400
32 +++ linux-2.6.22-520/include/linux/netfilter_ipv4/ipt_MARK.h 2008-06-06 17:07:56.000000000 -0400
34 #define IPT_MARK_SET XT_MARK_SET
35 #define IPT_MARK_AND XT_MARK_AND
36 #define IPT_MARK_OR XT_MARK_OR
37 +#define IPT_MARK_COPYXID XT_MARK_COPYXID
39 #define ipt_mark_target_info_v1 xt_mark_target_info_v1
41 diff -Nurb linux-2.6.22-510/include/linux/netfilter_ipv4/ipt_SETXID.h linux-2.6.22-520/include/linux/netfilter_ipv4/ipt_SETXID.h
42 --- linux-2.6.22-510/include/linux/netfilter_ipv4/ipt_SETXID.h 1969-12-31 19:00:00.000000000 -0500
43 +++ linux-2.6.22-520/include/linux/netfilter_ipv4/ipt_SETXID.h 2008-06-06 17:07:56.000000000 -0400
45 +#ifndef _IPT_SETXID_H_target
46 +#define _IPT_SETXID_H_target
48 +/* Backwards compatibility for old userspace */
50 +#include <linux/netfilter/xt_SETXID.h>
53 +#define IPT_SET_PACKET_XID XT_SET_PACKET_XID
55 +#define ipt_setxid_target_info_v1 xt_setxid_target_info_v1
57 +#endif /*_IPT_SETXID_H_target*/
58 diff -Nurb linux-2.6.22-510/include/net/netfilter/nf_conntrack.h linux-2.6.22-520/include/net/netfilter/nf_conntrack.h
59 --- linux-2.6.22-510/include/net/netfilter/nf_conntrack.h 2007-07-08 19:32:17.000000000 -0400
60 +++ linux-2.6.22-520/include/net/netfilter/nf_conntrack.h 2008-06-06 17:07:56.000000000 -0400
62 /* Storage reserved for other modules: */
63 union nf_conntrack_proto proto;
65 + /* PLANETLAB. VNET-specific */
66 + int xid[IP_CT_DIR_MAX];
68 /* features dynamically at the end: helper, nat (both optional) */
71 diff -Nurb linux-2.6.22-510/net/netfilter/Kconfig linux-2.6.22-520/net/netfilter/Kconfig
72 --- linux-2.6.22-510/net/netfilter/Kconfig 2007-07-08 19:32:17.000000000 -0400
73 +++ linux-2.6.22-520/net/netfilter/Kconfig 2008-06-06 17:07:56.000000000 -0400
76 To compile it as a module, choose M here. If unsure, say N.
78 +config NETFILTER_XT_TARGET_SETXID
79 + tristate '"SETXID" target support'
80 + depends on NETFILTER_XTABLES
82 + This option adds a `SETXID' target, which allows you to alter the
85 config NETFILTER_XT_MATCH_COMMENT
86 tristate '"comment" match support'
87 depends on NETFILTER_XTABLES
88 diff -Nurb linux-2.6.22-510/net/netfilter/Makefile linux-2.6.22-520/net/netfilter/Makefile
89 --- linux-2.6.22-510/net/netfilter/Makefile 2007-07-08 19:32:17.000000000 -0400
90 +++ linux-2.6.22-520/net/netfilter/Makefile 2008-06-06 17:07:56.000000000 -0400
92 obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
95 +obj-$(CONFIG_NETFILTER_XT_TARGET_SETXID) += xt_SETXID.o
96 obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o
97 obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
98 obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
99 diff -Nurb linux-2.6.22-510/net/netfilter/nf_conntrack_core.c linux-2.6.22-520/net/netfilter/nf_conntrack_core.c
100 --- linux-2.6.22-510/net/netfilter/nf_conntrack_core.c 2007-07-08 19:32:17.000000000 -0400
101 +++ linux-2.6.22-520/net/netfilter/nf_conntrack_core.c 2008-06-06 17:07:56.000000000 -0400
104 /* Overload tuple linked list to put us in unconfirmed list. */
105 list_add(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list, &unconfirmed);
106 + conntrack->xid[IP_CT_DIR_ORIGINAL] = -1;
107 + conntrack->xid[IP_CT_DIR_REPLY] = -1;
109 write_unlock_bh(&nf_conntrack_lock);
111 diff -Nurb linux-2.6.22-510/net/netfilter/xt_MARK.c linux-2.6.22-520/net/netfilter/xt_MARK.c
112 --- linux-2.6.22-510/net/netfilter/xt_MARK.c 2007-07-08 19:32:17.000000000 -0400
113 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c 2008-06-07 17:55:26.000000000 -0400
115 * This program is free software; you can redistribute it and/or modify
116 * it under the terms of the GNU General Public License version 2 as
117 * published by the Free Software Foundation.
121 #include <linux/module.h>
122 +#include <linux/version.h>
123 #include <linux/skbuff.h>
124 #include <linux/ip.h>
125 #include <net/checksum.h>
126 +#include <net/route.h>
127 +#include <net/inet_hashtables.h>
129 +#include <net/netfilter/nf_conntrack.h>
130 #include <linux/netfilter/x_tables.h>
131 #include <linux/netfilter/xt_MARK.h>
134 MODULE_ALIAS("ipt_MARK");
135 MODULE_ALIAS("ip6t_MARK");
137 +static inline u_int16_t
138 +get_dst_port(struct nf_conntrack_tuple *tuple)
140 + switch (tuple->dst.protonum) {
142 + /* XXX Truncate 32-bit GRE key to 16 bits */
143 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
144 + return tuple->dst.u.gre.key;
146 + return htons(ntohl(tuple->dst.u.gre.key));
149 + /* Bind on ICMP echo ID */
150 + return tuple->src.u.icmp.id;
152 + return tuple->dst.u.tcp.port;
154 + return tuple->dst.u.udp.port;
156 + return tuple->dst.u.all;
160 +static inline u_int16_t
161 +get_src_port(struct nf_conntrack_tuple *tuple)
163 + switch (tuple->dst.protonum) {
165 + /* XXX Truncate 32-bit GRE key to 16 bits */
166 + return htons(ntohl(tuple->src.u.gre.key));
168 + /* Bind on ICMP echo ID */
169 + return tuple->src.u.icmp.id;
171 + return tuple->src.u.tcp.port;
173 + return tuple->src.u.udp.port;
175 + return tuple->src.u.all;
180 target_v0(struct sk_buff **pskb,
181 const struct net_device *in,
186 +extern DEFINE_PER_CPU(int, sknid_elevator);
189 target_v1(struct sk_buff **pskb,
190 const struct net_device *in,
192 const void *targinfo)
194 const struct xt_mark_target_info_v1 *markinfo = targinfo;
196 + enum ip_conntrack_info ctinfo;
197 + struct sock *connection_sk;
199 + struct nf_conn *ct;
200 + extern struct inet_hashinfo tcp_hashinfo;
201 + enum ip_conntrack_dir dir;
205 + u_int16_t proto, src_port;
211 switch (markinfo->mode) {
215 mark = (*pskb)->mark | markinfo->mark;
218 + case XT_MARK_COPYXID:
220 + ct = nf_ct_get((*pskb), &ctinfo);
224 + dir = CTINFO2DIR(ctinfo);
225 + src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
226 + dst_ip = ct->tuplehash[dir].tuple.dst.u3.ip;
227 + src_port = get_src_port(&ct->tuplehash[dir].tuple);
228 + proto = ct->tuplehash[dir].tuple.dst.protonum;
230 + dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
231 + ip = ct->tuplehash[dir].tuple.dst.u3.ip;
232 + port = get_dst_port(&ct->tuplehash[dir].tuple);
234 + if (proto == 1 || proto == 17) {
235 + if ((*pskb)->mark>0) /* The packet is marked, it's going out */
237 + //if (ct->xid[0]>0 && ct->xid[0]!=(*pskb)->mark)
238 + /*printk(KERN_CRIT "xt_MARK log: %d/%d/%d/%d\n",ct->xid[0],(*pskb)->mark,hooknum==NF_IP_LOCAL_IN,proto);*/
240 + ct->xid[0]=(*pskb)->mark;
243 + if (ct->xid[0] > 0) {
248 + else if (proto == 6) {
250 + connection_sk = (*pskb)->sk;
251 + sock_hold(connection_sk);
254 + connection_sk = inet_lookup_established(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
257 + if (connection_sk) {
258 + if (connection_sk->sk_state == TCP_TIME_WAIT) {
259 + inet_twsk_put(inet_twsk(connection_sk));
262 + connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
263 + ct->xid[!dir]=connection_sk->sk_nid;
264 + if (connection_sk->sk_nid != 0)
265 + mark = connection_sk->sk_nid;
266 + sock_put(connection_sk);
274 (*pskb)->mark = mark;
277 + curtag=&__get_cpu_var(sknid_elevator);
278 + if (mark > 0 && *curtag==-2)
287 checkentry_v0(const char *tablename,
291 if (markinfo->mode != XT_MARK_SET
292 && markinfo->mode != XT_MARK_AND
293 - && markinfo->mode != XT_MARK_OR) {
294 + && markinfo->mode != XT_MARK_OR
295 + && markinfo->mode != XT_MARK_COPYXID) {
296 printk(KERN_WARNING "MARK: unknown mode %u\n",
299 diff -Nurb linux-2.6.22-510/net/netfilter/xt_SETXID.c linux-2.6.22-520/net/netfilter/xt_SETXID.c
300 --- linux-2.6.22-510/net/netfilter/xt_SETXID.c 1969-12-31 19:00:00.000000000 -0500
301 +++ linux-2.6.22-520/net/netfilter/xt_SETXID.c 2008-06-06 17:07:56.000000000 -0400
303 +#include <linux/module.h>
304 +#include <linux/skbuff.h>
305 +#include <linux/ip.h>
306 +#include <net/checksum.h>
307 +#include <linux/vs_network.h>
309 +#include <linux/netfilter/x_tables.h>
310 +#include <linux/netfilter/xt_SETXID.h>
312 +MODULE_LICENSE("GPL");
314 +MODULE_DESCRIPTION("");
315 +MODULE_ALIAS("ipt_SETXID");
318 +target_v1(struct sk_buff **pskb,
319 + const struct net_device *in,
320 + const struct net_device *out,
321 + unsigned int hooknum,
322 + const struct xt_target *target,
323 + const void *targinfo)
325 + const struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
327 + switch (setxidinfo->mode) {
328 + case XT_SET_PACKET_XID:
329 + (*pskb)->skb_tag = setxidinfo->mark;
332 + return XT_CONTINUE;
337 +checkentry_v1(const char *tablename,
339 + const struct xt_target *target,
341 + unsigned int hook_mask)
343 + struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
345 + if (setxidinfo->mode != XT_SET_PACKET_XID) {
346 + printk(KERN_WARNING "SETXID: unknown mode %u\n",
354 +static struct xt_target xt_setxid_target[] = {
359 + .checkentry = checkentry_v1,
360 + .target = target_v1,
361 + .targetsize = sizeof(struct xt_setxid_target_info_v1),
367 +static int __init init(void)
371 + err = xt_register_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
375 +static void __exit fini(void)
377 + xt_unregister_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));