Reset to the original
[linux-2.6.git] / linux-2.6-520-vnet+.patch
1 diff -Nurp 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  2006-06-17 21:49:35.000000000 -0400
3 +++ linux-2.6.22-520/include/linux/netfilter/xt_MARK.h  2007-12-03 15:11:08.000000000 -0500
4 @@ -11,6 +11,7 @@ enum {
5         XT_MARK_SET=0,
6         XT_MARK_AND,
7         XT_MARK_OR,
8 +       XT_MARK_COPYXID,
9  };
10  
11  struct xt_mark_target_info_v1 {
12 diff -Nurp 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        2007-12-03 15:11:08.000000000 -0500
15 @@ -0,0 +1,14 @@
16 +#ifndef _XT_SETXID_H_target
17 +#define _XT_SETXID_H_target
18 +
19 +/* Version 1 */
20 +enum {
21 +       XT_SET_PACKET_XID=0
22 +};
23 +
24 +struct xt_setxid_target_info_v1 {
25 +       unsigned long mark;
26 +       u_int8_t mode;
27 +};
28 +
29 +#endif /*_XT_SETXID_H_target*/
30 diff -Nurp 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    2006-06-17 21:49:35.000000000 -0400
32 +++ linux-2.6.22-520/include/linux/netfilter_ipv4/ipt_MARK.h    2007-12-03 15:11:08.000000000 -0500
33 @@ -9,9 +9,10 @@
34  #define ipt_mark_target_info xt_mark_target_info
35  
36  /* Version 1 */
37 -#define IPT_MARK_SET   XT_MARK_SET
38 -#define IPT_MARK_AND   XT_MARK_AND
39 -#define        IPT_MARK_OR     XT_MARK_OR
40 +#define IPT_MARK_SET           XT_MARK_SET
41 +#define IPT_MARK_AND           XT_MARK_AND
42 +#define        IPT_MARK_OR             XT_MARK_OR
43 +#define IPT_MARK_COPYXID       XT_MARK_COPYXID
44  
45  #define ipt_mark_target_info_v1 xt_mark_target_info_v1
46  
47 diff -Nurp linux-2.6.22-510/include/linux/netfilter_ipv4/ipt_SETXID.h linux-2.6.22-520/include/linux/netfilter_ipv4/ipt_SETXID.h
48 --- linux-2.6.22-510/include/linux/netfilter_ipv4/ipt_SETXID.h  1969-12-31 19:00:00.000000000 -0500
49 +++ linux-2.6.22-520/include/linux/netfilter_ipv4/ipt_SETXID.h  2007-12-03 15:11:08.000000000 -0500
50 @@ -0,0 +1,13 @@
51 +#ifndef _IPT_SETXID_H_target
52 +#define _IPT_SETXID_H_target
53 +
54 +/* Backwards compatibility for old userspace */
55 +
56 +#include <linux/netfilter/xt_SETXID.h>
57 +
58 +/* Version 1 */
59 +#define IPT_SET_PACKET_XID     XT_SET_PACKET_XID
60 +
61 +#define ipt_setxid_target_info_v1 xt_setxid_target_info_v1
62 +
63 +#endif /*_IPT_SETXID_H_target*/
64 diff -Nurp linux-2.6.22-510/include/linux/skbuff.h linux-2.6.22-520/include/linux/skbuff.h
65 --- linux-2.6.22-510/include/linux/skbuff.h     2007-07-21 18:00:24.000000000 -0400
66 +++ linux-2.6.22-520/include/linux/skbuff.h     2007-12-03 15:20:15.000000000 -0500
67 @@ -302,6 +302,7 @@ struct sk_buff {
68  #endif
69  
70         __u32                   mark;
71 +#define skb_tag                        mark
72  
73         sk_buff_data_t          transport_header;
74         sk_buff_data_t          network_header;
75 diff -Nurp linux-2.6.22-510/include/linux/socket.h linux-2.6.22-520/include/linux/socket.h
76 --- linux-2.6.22-510/include/linux/socket.h     2007-07-21 18:00:24.000000000 -0400
77 +++ linux-2.6.22-520/include/linux/socket.h     2007-12-03 15:11:08.000000000 -0500
78 @@ -288,6 +288,8 @@ struct ucred {
79  #define SOL_TIPC       271
80  #define SOL_RXRPC      272
81  
82 +#define SO_SETXID      SO_PEERCRED
83 +
84  /* IPX options */
85  #define IPX_TYPE       1
86  
87 diff -Nurp linux-2.6.22-510/include/linux/vserver/network.h linux-2.6.22-520/include/linux/vserver/network.h
88 --- linux-2.6.22-510/include/linux/vserver/network.h    2007-12-03 15:10:48.000000000 -0500
89 +++ linux-2.6.22-520/include/linux/vserver/network.h    2007-12-03 15:11:08.000000000 -0500
90 @@ -44,6 +44,8 @@ static inline uint64_t __nxf_init_set(vo
91  /* network caps */
92  
93  #define NXC_RAW_ICMP           0x00000100
94 +#define NXC_RAW_SOCKET         0x00000200
95 +#define NXC_RAW_SEND           0x00000400
96  
97  
98  /* address types */
99 diff -Nurp linux-2.6.22-510/include/net/netfilter/nf_conntrack.h linux-2.6.22-520/include/net/netfilter/nf_conntrack.h
100 --- linux-2.6.22-510/include/net/netfilter/nf_conntrack.h       2007-07-21 18:00:24.000000000 -0400
101 +++ linux-2.6.22-520/include/net/netfilter/nf_conntrack.h       2007-12-03 15:11:08.000000000 -0500
102 @@ -131,6 +131,9 @@ struct nf_conn
103         /* Storage reserved for other modules: */
104         union nf_conntrack_proto proto;
105  
106 +       /* PLANETLAB. VNET-specific */
107 +       xid_t xid[IP_CT_DIR_MAX];
108 +
109         /* features dynamically at the end: helper, nat (both optional) */
110         char data[0];
111  };
112 diff -Nurp linux-2.6.22-510/include/net/raw.h linux-2.6.22-520/include/net/raw.h
113 --- linux-2.6.22-510/include/net/raw.h  2007-05-04 09:55:46.000000000 -0400
114 +++ linux-2.6.22-520/include/net/raw.h  2007-12-03 15:11:08.000000000 -0500
115 @@ -36,7 +36,7 @@ extern rwlock_t raw_v4_lock;
116  
117  extern struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
118                                     __be32 raddr, __be32 laddr,
119 -                                   int dif);
120 +                                   int dif, int tag);
121  
122  extern int raw_v4_input(struct sk_buff *skb, struct iphdr *iph, int hash);
123  
124 diff -Nurp linux-2.6.22-510/net/core/skbuff.c linux-2.6.22-520/net/core/skbuff.c
125 --- linux-2.6.22-510/net/core/skbuff.c  2007-07-21 18:00:25.000000000 -0400
126 +++ linux-2.6.22-520/net/core/skbuff.c  2007-12-03 15:11:08.000000000 -0500
127 @@ -56,6 +56,7 @@
128  #include <linux/rtnetlink.h>
129  #include <linux/init.h>
130  #include <linux/scatterlist.h>
131 +#include <linux/vs_network.h>
132  
133  #include <net/protocol.h>
134  #include <net/dst.h>
135 @@ -174,6 +175,7 @@ struct sk_buff *__alloc_skb(unsigned int
136         skb->data = data;
137         skb_reset_tail_pointer(skb);
138         skb->end = skb->tail + size;
139 +       skb->skb_tag = nx_current_nid();
140         /* make sure we initialize shinfo sequentially */
141         shinfo = skb_shinfo(skb);
142         atomic_set(&shinfo->dataref, 1);
143 @@ -443,6 +445,8 @@ struct sk_buff *skb_clone(struct sk_buff
144         C(tail);
145         C(end);
146  
147 +       /* Sapan: Cloned skbs aren't owned by anyone. Let the cloner decide who it belongs to. */
148 +
149         atomic_inc(&(skb_shinfo(skb)->dataref));
150         skb->cloned = 1;
151  
152 @@ -492,6 +496,7 @@ static void copy_skb_header(struct sk_bu
153         new->tc_index   = old->tc_index;
154  #endif
155         skb_copy_secmark(new, old);
156 +       new->skb_tag = old->skb_tag;
157         atomic_set(&new->users, 1);
158         skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
159         skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
160 diff -Nurp linux-2.6.22-510/net/core/sock.c linux-2.6.22-520/net/core/sock.c
161 --- linux-2.6.22-510/net/core/sock.c    2007-12-03 15:10:56.000000000 -0500
162 +++ linux-2.6.22-520/net/core/sock.c    2007-12-03 15:11:08.000000000 -0500
163 @@ -444,6 +444,19 @@ set_sndbuf:
164                 }
165                 goto set_sndbuf;
166  
167 +       case SO_SETXID:
168 +               if (current_vx_info()) {
169 +                       ret = -EPERM;
170 +                       break;
171 +               }
172 +               if (val < 0 || val > MAX_S_CONTEXT) {
173 +                       ret = -EINVAL;
174 +                       break;
175 +               }
176 +               sk->sk_xid = val;
177 +               sk->sk_nid = val;
178 +               break;
179 +
180         case SO_RCVBUF:
181                 /* Don't error on this BSD doesn't and if you think
182                    about it this is right. Otherwise apps have to
183 @@ -573,7 +586,7 @@ set_rcvbuf:
184                 char devname[IFNAMSIZ];
185  
186                 /* Sorry... */
187 -               if (!capable(CAP_NET_RAW)) {
188 +               if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
189                         ret = -EPERM;
190                         break;
191                 }
192 diff -Nurp linux-2.6.22-510/net/ipv4/af_inet.c linux-2.6.22-520/net/ipv4/af_inet.c
193 --- linux-2.6.22-510/net/ipv4/af_inet.c 2007-12-03 15:10:56.000000000 -0500
194 +++ linux-2.6.22-520/net/ipv4/af_inet.c 2007-12-03 15:11:08.000000000 -0500
195 @@ -178,6 +178,8 @@ static int inet_autobind(struct sock *sk
196                         return -EAGAIN;
197                 }
198                 inet->sport = htons(inet->num);
199 +               sk->sk_xid = vx_current_xid();
200 +               sk->sk_nid = nx_current_nid();
201         }
202         release_sock(sk);
203         return 0;
204 diff -Nurp linux-2.6.22-510/net/ipv4/icmp.c linux-2.6.22-520/net/ipv4/icmp.c
205 --- linux-2.6.22-510/net/ipv4/icmp.c    2007-12-03 15:11:06.000000000 -0500
206 +++ linux-2.6.22-520/net/ipv4/icmp.c    2007-12-03 15:11:08.000000000 -0500
207 @@ -709,7 +709,7 @@ static void icmp_unreach(struct sk_buff 
208         if ((raw_sk = sk_head(&raw_v4_htable[hash])) != NULL) {
209                 while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr,
210                                                  iph->saddr,
211 -                                                skb->dev->ifindex)) != NULL) {
212 +                                                skb->dev->ifindex, skb->skb_tag)) != NULL) {
213                         raw_err(raw_sk, skb, info);
214                         raw_sk = sk_next(raw_sk);
215                         iph = (struct iphdr *)skb->data;
216 diff -Nurp linux-2.6.22-510/net/ipv4/ip_options.c linux-2.6.22-520/net/ipv4/ip_options.c
217 --- linux-2.6.22-510/net/ipv4/ip_options.c      2007-07-21 18:00:25.000000000 -0400
218 +++ linux-2.6.22-520/net/ipv4/ip_options.c      2007-12-03 15:11:08.000000000 -0500
219 @@ -409,7 +409,7 @@ int ip_options_compile(struct ip_options
220                                         optptr[2] += 8;
221                                         break;
222                                       default:
223 -                                       if (!skb && !capable(CAP_NET_RAW)) {
224 +                                       if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
225                                                 pp_ptr = optptr + 3;
226                                                 goto error;
227                                         }
228 @@ -445,7 +445,7 @@ int ip_options_compile(struct ip_options
229                                 opt->router_alert = optptr - iph;
230                         break;
231                       case IPOPT_CIPSO:
232 -                       if ((!skb && !capable(CAP_NET_RAW)) || opt->cipso) {
233 +                       if ((!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) || opt->cipso) {
234                                 pp_ptr = optptr;
235                                 goto error;
236                         }
237 @@ -458,7 +458,7 @@ int ip_options_compile(struct ip_options
238                       case IPOPT_SEC:
239                       case IPOPT_SID:
240                       default:
241 -                       if (!skb && !capable(CAP_NET_RAW)) {
242 +                       if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
243                                 pp_ptr = optptr;
244                                 goto error;
245                         }
246 diff -Nurp linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c
247 --- linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c       2007-12-03 15:10:26.000000000 -0500
248 +++ linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c       2007-12-03 15:11:08.000000000 -0500
249 @@ -49,6 +49,8 @@ static void dump_packet(const struct nf_
250         else
251                 logflags = NF_LOG_MASK;
252  
253 +       printk("TAG=%d ", skb->skb_tag);
254 +
255         ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
256         if (ih == NULL) {
257                 printk("TRUNCATED");
258 diff -Nurp linux-2.6.22-510/net/ipv4/raw.c linux-2.6.22-520/net/ipv4/raw.c
259 --- linux-2.6.22-510/net/ipv4/raw.c     2007-12-03 15:10:56.000000000 -0500
260 +++ linux-2.6.22-520/net/ipv4/raw.c     2007-12-03 15:11:08.000000000 -0500
261 @@ -103,7 +103,7 @@ static void raw_v4_unhash(struct sock *s
262  
263  struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
264                              __be32 raddr, __be32 laddr,
265 -                            int dif)
266 +                            int dif, int tag)
267  {
268         struct hlist_node *node;
269  
270 @@ -112,6 +112,7 @@ struct sock *__raw_v4_lookup(struct sock
271  
272                 if (inet->num == num                                    &&
273                     !(inet->daddr && inet->daddr != raddr)              &&
274 +                   (!sk->sk_nx_info || tag == 1 || sk->sk_nid == tag)  &&
275                     v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
276                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
277                         goto found; /* gotcha */
278 @@ -161,7 +162,7 @@ int raw_v4_input(struct sk_buff *skb, st
279                 goto out;
280         sk = __raw_v4_lookup(__sk_head(head), iph->protocol,
281                              iph->saddr, iph->daddr,
282 -                            skb->dev->ifindex);
283 +                            skb->dev->ifindex, skb->skb_tag);
284  
285         while (sk) {
286                 delivered = 1;
287 @@ -174,7 +175,7 @@ int raw_v4_input(struct sk_buff *skb, st
288                 }
289                 sk = __raw_v4_lookup(sk_next(sk), iph->protocol,
290                                      iph->saddr, iph->daddr,
291 -                                    skb->dev->ifindex);
292 +                                    skb->dev->ifindex, skb->skb_tag);
293         }
294  out:
295         read_unlock(&raw_v4_lock);
296 @@ -315,7 +316,7 @@ static int raw_send_hdrinc(struct sock *
297         }
298  
299         err = -EPERM;
300 -       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
301 +       if (!nx_check(0, VS_ADMIN) && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET) &&
302                 sk->sk_nx_info &&
303                 !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
304                 goto error_free;
305 diff -Nurp linux-2.6.22-510/net/netfilter/Kconfig linux-2.6.22-520/net/netfilter/Kconfig
306 --- linux-2.6.22-510/net/netfilter/Kconfig      2007-07-21 18:00:27.000000000 -0400
307 +++ linux-2.6.22-520/net/netfilter/Kconfig      2007-12-03 15:11:08.000000000 -0500
308 @@ -389,6 +389,13 @@ config NETFILTER_XT_TARGET_TCPMSS
309  
310           To compile it as a module, choose M here.  If unsure, say N.
311  
312 +config NETFILTER_XT_TARGET_SETXID
313 +       tristate '"SETXID" target support'
314 +       depends on NETFILTER_XTABLES
315 +       help
316 +         This option adds a `SETXID' target, which allows you to alter the
317 +         xid of a socket.
318 +
319  config NETFILTER_XT_MATCH_COMMENT
320         tristate  '"comment" match support'
321         depends on NETFILTER_XTABLES
322 diff -Nurp linux-2.6.22-510/net/netfilter/Makefile linux-2.6.22-520/net/netfilter/Makefile
323 --- linux-2.6.22-510/net/netfilter/Makefile     2007-07-21 17:58:59.000000000 -0400
324 +++ linux-2.6.22-520/net/netfilter/Makefile     2007-12-03 15:11:08.000000000 -0500
325 @@ -37,6 +37,7 @@ obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_co
326  obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
327  
328  # targets
329 +obj-$(CONFIG_NETFILTER_XT_TARGET_SETXID) += xt_SETXID.o
330  obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o
331  obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
332  obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
333 diff -Nurp linux-2.6.22-510/net/netfilter/nf_conntrack_core.c linux-2.6.22-520/net/netfilter/nf_conntrack_core.c
334 --- linux-2.6.22-510/net/netfilter/nf_conntrack_core.c  2007-07-21 18:00:27.000000000 -0400
335 +++ linux-2.6.22-520/net/netfilter/nf_conntrack_core.c  2007-12-03 15:11:08.000000000 -0500
336 @@ -726,6 +726,8 @@ init_conntrack(const struct nf_conntrack
337  
338         /* Overload tuple linked list to put us in unconfirmed list. */
339         list_add(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list, &unconfirmed);
340 +       conntrack->xid[IP_CT_DIR_ORIGINAL] = -1;
341 +       conntrack->xid[IP_CT_DIR_REPLY] = -1;
342  
343         write_unlock_bh(&nf_conntrack_lock);
344  
345 diff -Nurp linux-2.6.22-510/net/netfilter/xt_MARK.c linux-2.6.22-520/net/netfilter/xt_MARK.c
346 --- linux-2.6.22-510/net/netfilter/xt_MARK.c    2007-07-21 17:59:00.000000000 -0400
347 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c    2007-12-03 15:11:08.000000000 -0500
348 @@ -5,13 +5,18 @@
349   * This program is free software; you can redistribute it and/or modify
350   * it under the terms of the GNU General Public License version 2 as
351   * published by the Free Software Foundation.
352 + *
353   */
354  
355  #include <linux/module.h>
356 +#include <linux/version.h>
357  #include <linux/skbuff.h>
358  #include <linux/ip.h>
359  #include <net/checksum.h>
360 +#include <net/route.h>
361 +#include <net/inet_hashtables.h>
362  
363 +#include <net/netfilter/nf_conntrack.h>
364  #include <linux/netfilter/x_tables.h>
365  #include <linux/netfilter/xt_MARK.h>
366  
367 @@ -21,6 +26,48 @@ MODULE_DESCRIPTION("ip[6]tables MARK mod
368  MODULE_ALIAS("ipt_MARK");
369  MODULE_ALIAS("ip6t_MARK");
370  
371 +static inline u_int16_t
372 +get_dst_port(struct nf_conntrack_tuple *tuple)
373 +{
374 +       switch (tuple->dst.protonum) {
375 +       case IPPROTO_GRE:
376 +               /* XXX Truncate 32-bit GRE key to 16 bits */
377 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
378 +               return tuple->dst.u.gre.key;
379 +#else
380 +               return htons(ntohl(tuple->dst.u.gre.key));
381 +#endif  
382 +       case IPPROTO_ICMP:
383 +               /* Bind on ICMP echo ID */
384 +               return tuple->src.u.icmp.id;
385 +       case IPPROTO_TCP:
386 +               return tuple->dst.u.tcp.port;
387 +       case IPPROTO_UDP:
388 +               return tuple->dst.u.udp.port;
389 +       default:
390 +               return tuple->dst.u.all;
391 +       }
392 +}
393 +
394 +static inline u_int16_t
395 +get_src_port(struct nf_conntrack_tuple *tuple)
396 +{
397 +       switch (tuple->dst.protonum) {
398 +       case IPPROTO_GRE:
399 +               /* XXX Truncate 32-bit GRE key to 16 bits */
400 +               return htons(ntohl(tuple->src.u.gre.key));
401 +       case IPPROTO_ICMP:
402 +               /* Bind on ICMP echo ID */
403 +               return tuple->src.u.icmp.id;
404 +       case IPPROTO_TCP:
405 +               return tuple->src.u.tcp.port;
406 +       case IPPROTO_UDP:
407 +               return tuple->src.u.udp.port;
408 +       default:
409 +               return tuple->src.u.all;
410 +       }
411 +}
412 +
413  static unsigned int
414  target_v0(struct sk_buff **pskb,
415           const struct net_device *in,
416 @@ -44,7 +91,7 @@ target_v1(struct sk_buff **pskb,
417           const void *targinfo)
418  {
419         const struct xt_mark_target_info_v1 *markinfo = targinfo;
420 -       int mark = 0;
421 +       int mark = -1;
422  
423         switch (markinfo->mode) {
424         case XT_MARK_SET:
425 @@ -58,9 +105,52 @@ target_v1(struct sk_buff **pskb,
426         case XT_MARK_OR:
427                 mark = (*pskb)->mark | markinfo->mark;
428                 break;
429 +
430 +       case XT_MARK_COPYXID: {
431 +               enum ip_conntrack_info ctinfo;
432 +               struct sock *connection_sk;
433 +               int dif;
434 +
435 +               struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
436 +               extern struct inet_hashinfo tcp_hashinfo;
437 +               enum ip_conntrack_dir dir;
438 +
439 +               if (!ct) 
440 +                       break;
441 +               dir = CTINFO2DIR(ctinfo);
442 +               u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
443 +               u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
444 +
445 +               u_int32_t ip;
446 +               u_int16_t port;
447 +
448 +               dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
449 +               ip = ct->tuplehash[dir].tuple.dst.u3.ip;
450 +               port = get_dst_port(&ct->tuplehash[dir].tuple);
451 +
452 +               if ((*pskb)->sk) 
453 +                       connection_sk = (*pskb)->sk;
454 +               else {
455 +                       connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
456 +               }
457 +
458 +               if (connection_sk) {
459 +#ifdef REQUIRESFIXFROMSAPAN
460 +                       connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
461 +                       ct->xid[!dir]=connection_sk->sk_xid;
462 +                       /*connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = connection_sk->sk_xid;*/
463 +                       if (connection_sk->sk_xid != 0) 
464 +                               mark = connection_sk->sk_xid;
465 +#endif
466 +                       if (connection_sk != (*pskb)->sk)
467 +                               sock_put(connection_sk);
468 +               }
469 +               break;
470 +               }
471         }
472  
473 -       (*pskb)->mark = mark;
474 +       if (mark != -1)
475 +               (*pskb)->mark = mark;
476         return XT_CONTINUE;
477  }
478  
479 @@ -92,7 +182,8 @@ checkentry_v1(const char *tablename,
480  
481         if (markinfo->mode != XT_MARK_SET
482             && markinfo->mode != XT_MARK_AND
483 -           && markinfo->mode != XT_MARK_OR) {
484 +           && markinfo->mode != XT_MARK_OR
485 +           && markinfo->mode != XT_MARK_COPYXID) {
486                 printk(KERN_WARNING "MARK: unknown mode %u\n",
487                        markinfo->mode);
488                 return 0;
489 diff -Nurp linux-2.6.22-510/net/netfilter/xt_SETXID.c linux-2.6.22-520/net/netfilter/xt_SETXID.c
490 --- linux-2.6.22-510/net/netfilter/xt_SETXID.c  1969-12-31 19:00:00.000000000 -0500
491 +++ linux-2.6.22-520/net/netfilter/xt_SETXID.c  2007-12-03 15:11:08.000000000 -0500
492 @@ -0,0 +1,79 @@
493 +#include <linux/module.h>
494 +#include <linux/skbuff.h>
495 +#include <linux/ip.h>
496 +#include <net/checksum.h>
497 +#include <linux/vs_network.h>
498 +
499 +#include <linux/netfilter/x_tables.h>
500 +#include <linux/netfilter/xt_SETXID.h>
501 +
502 +MODULE_LICENSE("GPL");
503 +MODULE_AUTHOR("");
504 +MODULE_DESCRIPTION("");
505 +MODULE_ALIAS("ipt_SETXID");
506 +
507 +static unsigned int
508 +target_v1(struct sk_buff **pskb,
509 +         const struct net_device *in,
510 +         const struct net_device *out,
511 +         unsigned int hooknum,
512 +         const struct xt_target *target,
513 +         const void *targinfo)
514 +{
515 +       const struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
516 +
517 +       switch (setxidinfo->mode) {
518 +       case XT_SET_PACKET_XID:
519 +                (*pskb)->skb_tag = setxidinfo->mark;
520 +               break;
521 +       }
522 +       return XT_CONTINUE;
523 +}
524 +
525 +
526 +static int
527 +checkentry_v1(const char *tablename,
528 +             const void *entry,
529 +             const struct xt_target *target,
530 +             void *targinfo,
531 +             unsigned int hook_mask)
532 +{
533 +       struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
534 +
535 +       if (setxidinfo->mode != XT_SET_PACKET_XID) {
536 +               printk(KERN_WARNING "SETXID: unknown mode %u\n",
537 +                      setxidinfo->mode);
538 +               return 0;
539 +       }
540 +
541 +       return 1;
542 +}
543 +
544 +static struct xt_target xt_setxid_target[] = {
545 +       {
546 +               .name           = "SETXID",
547 +               .family         = AF_INET,
548 +               .revision       = 1,
549 +               .checkentry     = checkentry_v1,
550 +               .target         = target_v1,
551 +               .targetsize     = sizeof(struct xt_setxid_target_info_v1),
552 +               .table          = "mangle",
553 +               .me             = THIS_MODULE,
554 +       }
555 +};
556 +
557 +static int __init init(void)
558 +{
559 +       int err;
560 +
561 +       err = xt_register_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
562 +       return err;
563 +}
564 +
565 +static void __exit fini(void)
566 +{
567 +       xt_unregister_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
568 +}
569 +
570 +module_init(init);
571 +module_exit(fini);
572 diff -Nurp linux-2.6.22-510/net/packet/af_packet.c linux-2.6.22-520/net/packet/af_packet.c
573 --- linux-2.6.22-510/net/packet/af_packet.c     2007-07-21 18:00:27.000000000 -0400
574 +++ linux-2.6.22-520/net/packet/af_packet.c     2007-12-03 15:11:08.000000000 -0500
575 @@ -78,6 +78,7 @@
576  #include <linux/poll.h>
577  #include <linux/module.h>
578  #include <linux/init.h>
579 +#include <linux/vs_network.h>
580  
581  #ifdef CONFIG_INET
582  #include <net/inet_common.h>
583 @@ -420,6 +421,10 @@ static inline unsigned int run_filter(st
584                                       unsigned int res)
585  {
586         struct sk_filter *filter;
587 +       int tag = skb->skb_tag;
588 +
589 +       if (sk->sk_nx_info && !(tag == 1 || sk->sk_nid == tag))
590 +               return 0;
591  
592         rcu_read_lock_bh();
593         filter = rcu_dereference(sk->sk_filter);
594 @@ -984,7 +989,7 @@ static int packet_create(struct socket *
595         __be16 proto = (__force __be16)protocol; /* weird, but documented */
596         int err;
597  
598 -       if (!capable(CAP_NET_RAW))
599 +       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
600                 return -EPERM;
601         if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
602             sock->type != SOCK_PACKET)