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