(no commit message)
[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-06-04 11:42:32.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-06-04 11:42:32.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-06-04 11:42:32.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-06-04 11:42:32.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-06-04 11:42:32.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-06-04 11:42:32.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-06-04 11:42:27.000000000 -0400
83 +++ linux-2.6.22-520/include/linux/vserver/network.h    2008-06-04 11:42:32.000000000 -0400
84 @@ -47,6 +47,8 @@
85  #define NXC_TUN_CREATE         0x00000001
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 diff -Nurb linux-2.6.22-510/include/net/netfilter/nf_conntrack.h linux-2.6.22-520/include/net/netfilter/nf_conntrack.h
94 --- linux-2.6.22-510/include/net/netfilter/nf_conntrack.h       2007-07-08 19:32:17.000000000 -0400
95 +++ linux-2.6.22-520/include/net/netfilter/nf_conntrack.h       2008-06-04 11:42:32.000000000 -0400
96 @@ -131,6 +131,9 @@
97         /* Storage reserved for other modules: */
98         union nf_conntrack_proto proto;
99  
100 +       /* PLANETLAB. VNET-specific */
101 +       int xid[IP_CT_DIR_MAX];
102 +
103         /* features dynamically at the end: helper, nat (both optional) */
104         char data[0];
105  };
106 diff -Nurb linux-2.6.22-510/include/net/raw.h linux-2.6.22-520/include/net/raw.h
107 --- linux-2.6.22-510/include/net/raw.h  2007-07-08 19:32:17.000000000 -0400
108 +++ linux-2.6.22-520/include/net/raw.h  2008-06-04 11:42:32.000000000 -0400
109 @@ -36,7 +36,7 @@
110  
111  extern struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
112                                     __be32 raddr, __be32 laddr,
113 -                                   int dif);
114 +                                   int dif, int tag);
115  
116  extern int raw_v4_input(struct sk_buff *skb, struct iphdr *iph, int hash);
117  
118 diff -Nurb linux-2.6.22-510/net/core/dev.c linux-2.6.22-520/net/core/dev.c
119 --- linux-2.6.22-510/net/core/dev.c     2008-06-04 11:42:27.000000000 -0400
120 +++ linux-2.6.22-520/net/core/dev.c     2008-06-04 11:43:36.000000000 -0400
121 @@ -1803,6 +1803,7 @@
122   * the ingress scheduler, you just cant add policies on ingress.
123   *
124   */
125 +
126  static int ing_filter(struct sk_buff *skb)
127  {
128         struct Qdisc *q;
129 @@ -1832,13 +1833,20 @@
130  }
131  #endif
132  
133 +/* The code already makes the assumption that packet handlers run
134 + * sequentially on the same CPU. -Sapan */
135 +DEFINE_PER_CPU(int, sknid_elevator);
136 +
137  int netif_receive_skb(struct sk_buff *skb)
138  {
139         struct packet_type *ptype, *pt_prev;
140         struct net_device *orig_dev;
141         int ret = NET_RX_DROP;
142 +       int *cur_elevator=&__get_cpu_var(sknid_elevator);
143         __be16 type;
144  
145 +       *cur_elevator = 0;
146 +
147         /* if we've gotten here through NAPI, check netpoll */
148         if (skb->dev->poll && netpoll_rx(skb))
149                 return NET_RX_DROP;
150 @@ -1873,8 +1881,9 @@
151  
152         list_for_each_entry_rcu(ptype, &ptype_all, list) {
153                 if (!ptype->dev || ptype->dev == skb->dev) {
154 -                       if (pt_prev)
155 +                       if (pt_prev) {
156                                 ret = deliver_skb(skb, pt_prev, orig_dev);
157 +                       }
158                         pt_prev = ptype;
159                 }
160         }
161 @@ -1912,8 +1921,22 @@
162                 }
163         }
164  
165 +       /* We don't want the packet handlers to throw the packet away
166 +        * if we want the taps to treat it again - Sapan */
167 +       if (*cur_elevator) {
168 +               atomic_inc(&skb->users);
169 +       }
170 +
171         if (pt_prev) {
172                 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
173 +                       if (*cur_elevator > 0) {
174 +                               skb->skb_tag = *cur_elevator;
175 +                               list_for_each_entry_rcu(ptype, &ptype_all, list) {
176 +                                       if (!ptype->dev || ptype->dev == skb->dev) {
177 +                                                       ret = deliver_skb(skb, ptype, orig_dev);
178 +                                       }
179 +                               }
180 +                       }
181         } else {
182                 kfree_skb(skb);
183                 /* Jamal, now you will not able to escape explaining
184 @@ -1922,6 +1945,13 @@
185                 ret = NET_RX_DROP;
186         }
187  
188 +       if (*cur_elevator) {
189 +               /* We have a packet */
190 +               kfree_skb(skb);
191 +       }
192 +
193 +       *cur_elevator=0;
194 +
195  out:
196         rcu_read_unlock();
197         return ret;
198 @@ -3780,6 +3810,7 @@
199  EXPORT_SYMBOL(net_enable_timestamp);
200  EXPORT_SYMBOL(net_disable_timestamp);
201  EXPORT_SYMBOL(dev_get_flags);
202 +EXPORT_PER_CPU_SYMBOL(sknid_elevator);
203  
204  #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
205  EXPORT_SYMBOL(br_handle_frame_hook);
206 diff -Nurb linux-2.6.22-510/net/core/skbuff.c linux-2.6.22-520/net/core/skbuff.c
207 --- linux-2.6.22-510/net/core/skbuff.c  2007-07-08 19:32:17.000000000 -0400
208 +++ linux-2.6.22-520/net/core/skbuff.c  2008-06-04 11:42:32.000000000 -0400
209 @@ -56,6 +56,7 @@
210  #include <linux/rtnetlink.h>
211  #include <linux/init.h>
212  #include <linux/scatterlist.h>
213 +#include <linux/vs_network.h>
214  
215  #include <net/protocol.h>
216  #include <net/dst.h>
217 @@ -174,6 +175,7 @@
218         skb->data = data;
219         skb_reset_tail_pointer(skb);
220         skb->end = skb->tail + size;
221 +       if (!in_interrupt()) skb->skb_tag = nx_current_nid(); else skb->skb_tag = 0;
222         /* make sure we initialize shinfo sequentially */
223         shinfo = skb_shinfo(skb);
224         atomic_set(&shinfo->dataref, 1);
225 @@ -443,6 +445,8 @@
226         C(tail);
227         C(end);
228  
229 +       /* Sapan: Cloned skbs aren't owned by anyone. Let the cloner decide who it belongs to. */
230 +
231         atomic_inc(&(skb_shinfo(skb)->dataref));
232         skb->cloned = 1;
233  
234 @@ -492,6 +496,7 @@
235         new->tc_index   = old->tc_index;
236  #endif
237         skb_copy_secmark(new, old);
238 +       new->skb_tag = old->skb_tag;
239         atomic_set(&new->users, 1);
240         skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
241         skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
242 diff -Nurb linux-2.6.22-510/net/core/sock.c linux-2.6.22-520/net/core/sock.c
243 --- linux-2.6.22-510/net/core/sock.c    2008-06-04 11:42:27.000000000 -0400
244 +++ linux-2.6.22-520/net/core/sock.c    2008-06-04 11:42:32.000000000 -0400
245 @@ -444,6 +444,19 @@
246                 }
247                 goto set_sndbuf;
248  
249 +       case SO_SETXID:
250 +               if (current_vx_info()) {
251 +                       ret = -EPERM;
252 +                       break;
253 +               }
254 +               if (val < 0 || val > MAX_S_CONTEXT) {
255 +                       ret = -EINVAL;
256 +                       break;
257 +               }
258 +               sk->sk_xid = val;
259 +               sk->sk_nid = val;
260 +               break;
261 +
262         case SO_RCVBUF:
263                 /* Don't error on this BSD doesn't and if you think
264                    about it this is right. Otherwise apps have to
265 @@ -573,7 +586,7 @@
266                 char devname[IFNAMSIZ];
267  
268                 /* Sorry... */
269 -               if (!capable(CAP_NET_RAW)) {
270 +               if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
271                         ret = -EPERM;
272                         break;
273                 }
274 diff -Nurb linux-2.6.22-510/net/ipv4/af_inet.c linux-2.6.22-520/net/ipv4/af_inet.c
275 --- linux-2.6.22-510/net/ipv4/af_inet.c 2008-06-04 11:42:27.000000000 -0400
276 +++ linux-2.6.22-520/net/ipv4/af_inet.c 2008-06-04 11:42:32.000000000 -0400
277 @@ -178,6 +178,8 @@
278                         return -EAGAIN;
279                 }
280                 inet->sport = htons(inet->num);
281 +               sk->sk_xid = vx_current_xid();
282 +               if (!in_interrupt()) sk->sk_nid = nx_current_nid(); else sk->sk_nid=0;
283         }
284         release_sock(sk);
285         return 0;
286 @@ -312,6 +314,9 @@
287         if ((protocol == IPPROTO_ICMP) &&
288                 nx_capable(answer->capability, NXC_RAW_ICMP))
289                 goto override;
290 +       if (sock->type == SOCK_RAW &&
291 +               nx_capable(answer->capability, NXC_RAW_SOCKET))
292 +               goto override;
293         if (answer->capability > 0 && !capable(answer->capability))
294                 goto out_rcu_unlock;
295  override:
296 diff -Nurb linux-2.6.22-510/net/ipv4/icmp.c linux-2.6.22-520/net/ipv4/icmp.c
297 --- linux-2.6.22-510/net/ipv4/icmp.c    2008-06-04 11:42:31.000000000 -0400
298 +++ linux-2.6.22-520/net/ipv4/icmp.c    2008-06-04 11:42:32.000000000 -0400
299 @@ -709,7 +709,7 @@
300         if ((raw_sk = sk_head(&raw_v4_htable[hash])) != NULL) {
301                 while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr,
302                                                  iph->saddr,
303 -                                                skb->dev->ifindex)) != NULL) {
304 +                                                skb->dev->ifindex, skb->skb_tag)) != NULL) {
305                         raw_err(raw_sk, skb, info);
306                         raw_sk = sk_next(raw_sk);
307                         iph = (struct iphdr *)skb->data;
308 diff -Nurb linux-2.6.22-510/net/ipv4/ip_options.c linux-2.6.22-520/net/ipv4/ip_options.c
309 --- linux-2.6.22-510/net/ipv4/ip_options.c      2007-07-08 19:32:17.000000000 -0400
310 +++ linux-2.6.22-520/net/ipv4/ip_options.c      2008-06-04 11:42:32.000000000 -0400
311 @@ -409,7 +409,7 @@
312                                         optptr[2] += 8;
313                                         break;
314                                       default:
315 -                                       if (!skb && !capable(CAP_NET_RAW)) {
316 +                                       if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
317                                                 pp_ptr = optptr + 3;
318                                                 goto error;
319                                         }
320 @@ -445,7 +445,7 @@
321                                 opt->router_alert = optptr - iph;
322                         break;
323                       case IPOPT_CIPSO:
324 -                       if ((!skb && !capable(CAP_NET_RAW)) || opt->cipso) {
325 +                       if ((!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) || opt->cipso) {
326                                 pp_ptr = optptr;
327                                 goto error;
328                         }
329 @@ -458,7 +458,7 @@
330                       case IPOPT_SEC:
331                       case IPOPT_SID:
332                       default:
333 -                       if (!skb && !capable(CAP_NET_RAW)) {
334 +                       if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
335                                 pp_ptr = optptr;
336                                 goto error;
337                         }
338 diff -Nurb linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c
339 --- linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c       2008-06-04 11:42:21.000000000 -0400
340 +++ linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c       2008-06-04 11:42:32.000000000 -0400
341 @@ -49,6 +49,8 @@
342         else
343                 logflags = NF_LOG_MASK;
344  
345 +       printk("TAG=%d ", skb->skb_tag);
346 +
347         ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
348         if (ih == NULL) {
349                 printk("TRUNCATED");
350 diff -Nurb linux-2.6.22-510/net/ipv4/raw.c linux-2.6.22-520/net/ipv4/raw.c
351 --- linux-2.6.22-510/net/ipv4/raw.c     2008-06-04 11:42:27.000000000 -0400
352 +++ linux-2.6.22-520/net/ipv4/raw.c     2008-06-04 11:42:32.000000000 -0400
353 @@ -103,7 +103,7 @@
354  
355  struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
356                              __be32 raddr, __be32 laddr,
357 -                            int dif)
358 +                            int dif, int tag)
359  {
360         struct hlist_node *node;
361  
362 @@ -112,6 +112,7 @@
363  
364                 if (inet->num == num                                    &&
365                     !(inet->daddr && inet->daddr != raddr)              &&
366 +                   (!sk->sk_nx_info || tag == 1 || sk->sk_nid == tag)  &&
367                     v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
368                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
369                         goto found; /* gotcha */
370 @@ -161,7 +162,7 @@
371                 goto out;
372         sk = __raw_v4_lookup(__sk_head(head), iph->protocol,
373                              iph->saddr, iph->daddr,
374 -                            skb->dev->ifindex);
375 +                            skb->dev->ifindex, skb->skb_tag);
376  
377         while (sk) {
378                 delivered = 1;
379 @@ -174,7 +175,7 @@
380                 }
381                 sk = __raw_v4_lookup(sk_next(sk), iph->protocol,
382                                      iph->saddr, iph->daddr,
383 -                                    skb->dev->ifindex);
384 +                                    skb->dev->ifindex, skb->skb_tag);
385         }
386  out:
387         read_unlock(&raw_v4_lock);
388 @@ -315,7 +316,7 @@
389         }
390  
391         err = -EPERM;
392 -       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
393 +       if (!nx_check(0, VS_ADMIN) && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET) &&
394                 sk->sk_nx_info &&
395                 !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
396                 goto error_free;
397 diff -Nurb linux-2.6.22-510/net/netfilter/Kconfig linux-2.6.22-520/net/netfilter/Kconfig
398 --- linux-2.6.22-510/net/netfilter/Kconfig      2007-07-08 19:32:17.000000000 -0400
399 +++ linux-2.6.22-520/net/netfilter/Kconfig      2008-06-04 11:42:32.000000000 -0400
400 @@ -389,6 +389,13 @@
401  
402           To compile it as a module, choose M here.  If unsure, say N.
403  
404 +config NETFILTER_XT_TARGET_SETXID
405 +       tristate '"SETXID" target support'
406 +       depends on NETFILTER_XTABLES
407 +       help
408 +         This option adds a `SETXID' target, which allows you to alter the
409 +         xid of a socket.
410 +
411  config NETFILTER_XT_MATCH_COMMENT
412         tristate  '"comment" match support'
413         depends on NETFILTER_XTABLES
414 diff -Nurb linux-2.6.22-510/net/netfilter/Makefile linux-2.6.22-520/net/netfilter/Makefile
415 --- linux-2.6.22-510/net/netfilter/Makefile     2007-07-08 19:32:17.000000000 -0400
416 +++ linux-2.6.22-520/net/netfilter/Makefile     2008-06-04 11:42:32.000000000 -0400
417 @@ -37,6 +37,7 @@
418  obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
419  
420  # targets
421 +obj-$(CONFIG_NETFILTER_XT_TARGET_SETXID) += xt_SETXID.o
422  obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o
423  obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
424  obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
425 diff -Nurb linux-2.6.22-510/net/netfilter/nf_conntrack_core.c linux-2.6.22-520/net/netfilter/nf_conntrack_core.c
426 --- linux-2.6.22-510/net/netfilter/nf_conntrack_core.c  2007-07-08 19:32:17.000000000 -0400
427 +++ linux-2.6.22-520/net/netfilter/nf_conntrack_core.c  2008-06-04 11:42:32.000000000 -0400
428 @@ -726,6 +726,8 @@
429  
430         /* Overload tuple linked list to put us in unconfirmed list. */
431         list_add(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list, &unconfirmed);
432 +       conntrack->xid[IP_CT_DIR_ORIGINAL] = -1;
433 +       conntrack->xid[IP_CT_DIR_REPLY] = -1;
434  
435         write_unlock_bh(&nf_conntrack_lock);
436  
437 diff -Nurb linux-2.6.22-510/net/netfilter/xt_MARK.c linux-2.6.22-520/net/netfilter/xt_MARK.c
438 --- linux-2.6.22-510/net/netfilter/xt_MARK.c    2007-07-08 19:32:17.000000000 -0400
439 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c    2008-06-04 11:42:32.000000000 -0400
440 @@ -5,13 +5,18 @@
441   * This program is free software; you can redistribute it and/or modify
442   * it under the terms of the GNU General Public License version 2 as
443   * published by the Free Software Foundation.
444 + *
445   */
446  
447  #include <linux/module.h>
448 +#include <linux/version.h>
449  #include <linux/skbuff.h>
450  #include <linux/ip.h>
451  #include <net/checksum.h>
452 +#include <net/route.h>
453 +#include <net/inet_hashtables.h>
454  
455 +#include <net/netfilter/nf_conntrack.h>
456  #include <linux/netfilter/x_tables.h>
457  #include <linux/netfilter/xt_MARK.h>
458  
459 @@ -21,6 +26,48 @@
460  MODULE_ALIAS("ipt_MARK");
461  MODULE_ALIAS("ip6t_MARK");
462  
463 +static inline u_int16_t
464 +get_dst_port(struct nf_conntrack_tuple *tuple)
465 +{
466 +       switch (tuple->dst.protonum) {
467 +       case IPPROTO_GRE:
468 +               /* XXX Truncate 32-bit GRE key to 16 bits */
469 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
470 +               return tuple->dst.u.gre.key;
471 +#else
472 +               return htons(ntohl(tuple->dst.u.gre.key));
473 +#endif  
474 +       case IPPROTO_ICMP:
475 +               /* Bind on ICMP echo ID */
476 +               return tuple->src.u.icmp.id;
477 +       case IPPROTO_TCP:
478 +               return tuple->dst.u.tcp.port;
479 +       case IPPROTO_UDP:
480 +               return tuple->dst.u.udp.port;
481 +       default:
482 +               return tuple->dst.u.all;
483 +       }
484 +}
485 +
486 +static inline u_int16_t
487 +get_src_port(struct nf_conntrack_tuple *tuple)
488 +{
489 +       switch (tuple->dst.protonum) {
490 +       case IPPROTO_GRE:
491 +               /* XXX Truncate 32-bit GRE key to 16 bits */
492 +               return htons(ntohl(tuple->src.u.gre.key));
493 +       case IPPROTO_ICMP:
494 +               /* Bind on ICMP echo ID */
495 +               return tuple->src.u.icmp.id;
496 +       case IPPROTO_TCP:
497 +               return tuple->src.u.tcp.port;
498 +       case IPPROTO_UDP:
499 +               return tuple->src.u.udp.port;
500 +       default:
501 +               return tuple->src.u.all;
502 +       }
503 +}
504 +
505  static unsigned int
506  target_v0(struct sk_buff **pskb,
507           const struct net_device *in,
508 @@ -35,6 +82,8 @@
509         return XT_CONTINUE;
510  }
511  
512 +extern DEFINE_PER_CPU(int, sknid_elevator);
513 +
514  static unsigned int
515  target_v1(struct sk_buff **pskb,
516           const struct net_device *in,
517 @@ -44,7 +93,20 @@
518           const void *targinfo)
519  {
520         const struct xt_mark_target_info_v1 *markinfo = targinfo;
521 -       int mark = 0;
522 +       enum ip_conntrack_info ctinfo;
523 +      struct sock *connection_sk;
524 +      int dif;
525 +      struct nf_conn *ct;
526 +      extern struct inet_hashinfo tcp_hashinfo;
527 +      enum ip_conntrack_dir dir;
528 +      int *curtag;
529 +      u_int32_t src_ip;
530 +      u_int32_t dst_ip;
531 +      u_int16_t proto, src_port;
532 +      u_int32_t ip;
533 +      u_int16_t port;
534 +
535 +       int mark = -1;
536  
537         switch (markinfo->mode) {
538         case XT_MARK_SET:
539 @@ -58,13 +120,76 @@
540         case XT_MARK_OR:
541                 mark = (*pskb)->mark | markinfo->mark;
542                 break;
543 +
544 +               case XT_MARK_COPYXID: 
545 +                                             
546 +                                             ct = nf_ct_get((*pskb), &ctinfo);
547 +                                             if (!ct) 
548 +                                                     break;
549 +
550 +                                             dir = CTINFO2DIR(ctinfo);
551 +                                             src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
552 +                                             dst_ip = ct->tuplehash[dir].tuple.dst.u3.ip;
553 +                                             src_port = get_src_port(&ct->tuplehash[dir].tuple);
554 +                                             proto = ct->tuplehash[dir].tuple.dst.protonum;
555 +
556 +                                             dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
557 +                                             ip = ct->tuplehash[dir].tuple.dst.u3.ip;
558 +                                             port = get_dst_port(&ct->tuplehash[dir].tuple);
559 +
560 +                                             if (proto == 1 || proto == 17) {
561 +                                                     if ((*pskb)->mark>0) /* The packet is marked, it's going out */
562 +                                                     {
563 +                                                             if (ct->xid[0]>0 && ct->xid[0]!=(*pskb)->mark && hooknum==NF_IP_LOCAL_IN) {
564 +                                                                     /* Neil Spring's bug. */
565 +                                                                       break;
566 +                                                             }
567 +                                                             else
568 +                                                                     ct->xid[0]=(*pskb)->mark;
569 +                                                     }
570 +
571 +                                                     if (ct->xid[0] > 0) {
572 +                                                             mark = ct->xid[0];
573         }
574  
575 +                                             }
576 +                                             else if (proto == 6) { 
577 +                                                     if ((*pskb)->sk) {
578 +                                                             connection_sk = (*pskb)->sk;
579 +                                                             sock_hold(connection_sk);
580 +                                                     }
581 +                                                     else 
582 +                                                             connection_sk = inet_lookup_established(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
583 +                                                             
584 +
585 +                                                     if (connection_sk) {
586 +                                                             if (connection_sk->sk_state == TCP_TIME_WAIT) {
587 +                                                                     inet_twsk_put(inet_twsk(connection_sk));
588 +                                                                     break;
589 +                                                             }
590 +                                                             connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
591 +                                                             ct->xid[!dir]=connection_sk->sk_nid;
592 +                                                             if (connection_sk->sk_nid != 0) 
593 +                                                                     mark = connection_sk->sk_nid;
594 +                                                             sock_put(connection_sk);
595 +                                                     }
596 +                                                     else 
597 +                                                             mark = -1 ; 
598 +                                             }
599 +                                             break;
600 +       }
601 +       if (mark != -1) {
602         (*pskb)->mark = mark;
603 +       }
604 +
605 +       curtag=&__get_cpu_var(sknid_elevator);
606 +       if (mark > 0 && *curtag==-2) 
607 +       {
608 +               *curtag = mark;
609 +       }
610         return XT_CONTINUE;
611  }
612  
613 -
614  static int
615  checkentry_v0(const char *tablename,
616               const void *entry,
617 @@ -92,7 +217,8 @@
618  
619         if (markinfo->mode != XT_MARK_SET
620             && markinfo->mode != XT_MARK_AND
621 -           && markinfo->mode != XT_MARK_OR) {
622 +           && markinfo->mode != XT_MARK_OR
623 +           && markinfo->mode != XT_MARK_COPYXID) {
624                 printk(KERN_WARNING "MARK: unknown mode %u\n",
625                        markinfo->mode);
626                 return 0;
627 diff -Nurb linux-2.6.22-510/net/netfilter/xt_SETXID.c linux-2.6.22-520/net/netfilter/xt_SETXID.c
628 --- linux-2.6.22-510/net/netfilter/xt_SETXID.c  1969-12-31 19:00:00.000000000 -0500
629 +++ linux-2.6.22-520/net/netfilter/xt_SETXID.c  2008-06-04 11:42:32.000000000 -0400
630 @@ -0,0 +1,79 @@
631 +#include <linux/module.h>
632 +#include <linux/skbuff.h>
633 +#include <linux/ip.h>
634 +#include <net/checksum.h>
635 +#include <linux/vs_network.h>
636 +
637 +#include <linux/netfilter/x_tables.h>
638 +#include <linux/netfilter/xt_SETXID.h>
639 +
640 +MODULE_LICENSE("GPL");
641 +MODULE_AUTHOR("");
642 +MODULE_DESCRIPTION("");
643 +MODULE_ALIAS("ipt_SETXID");
644 +
645 +static unsigned int
646 +target_v1(struct sk_buff **pskb,
647 +         const struct net_device *in,
648 +         const struct net_device *out,
649 +         unsigned int hooknum,
650 +         const struct xt_target *target,
651 +         const void *targinfo)
652 +{
653 +       const struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
654 +
655 +       switch (setxidinfo->mode) {
656 +       case XT_SET_PACKET_XID:
657 +                (*pskb)->skb_tag = setxidinfo->mark;
658 +               break;
659 +       }
660 +       return XT_CONTINUE;
661 +}
662 +
663 +
664 +static int
665 +checkentry_v1(const char *tablename,
666 +             const void *entry,
667 +             const struct xt_target *target,
668 +             void *targinfo,
669 +             unsigned int hook_mask)
670 +{
671 +       struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
672 +
673 +       if (setxidinfo->mode != XT_SET_PACKET_XID) {
674 +               printk(KERN_WARNING "SETXID: unknown mode %u\n",
675 +                      setxidinfo->mode);
676 +               return 0;
677 +       }
678 +
679 +       return 1;
680 +}
681 +
682 +static struct xt_target xt_setxid_target[] = {
683 +       {
684 +               .name           = "SETXID",
685 +               .family         = AF_INET,
686 +               .revision       = 1,
687 +               .checkentry     = checkentry_v1,
688 +               .target         = target_v1,
689 +               .targetsize     = sizeof(struct xt_setxid_target_info_v1),
690 +               .table          = "mangle",
691 +               .me             = THIS_MODULE,
692 +       }
693 +};
694 +
695 +static int __init init(void)
696 +{
697 +       int err;
698 +
699 +       err = xt_register_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
700 +       return err;
701 +}
702 +
703 +static void __exit fini(void)
704 +{
705 +       xt_unregister_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
706 +}
707 +
708 +module_init(init);
709 +module_exit(fini);
710 diff -Nurb linux-2.6.22-510/net/packet/af_packet.c linux-2.6.22-520/net/packet/af_packet.c
711 --- linux-2.6.22-510/net/packet/af_packet.c     2007-07-08 19:32:17.000000000 -0400
712 +++ linux-2.6.22-520/net/packet/af_packet.c     2008-06-04 11:42:32.000000000 -0400
713 @@ -78,6 +78,7 @@
714  #include <linux/poll.h>
715  #include <linux/module.h>
716  #include <linux/init.h>
717 +#include <linux/vs_network.h>
718  
719  #ifdef CONFIG_INET
720  #include <net/inet_common.h>
721 @@ -324,6 +325,9 @@
722         __be16 proto=0;
723         int err;
724  
725 +       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
726 +               return -EPERM;
727 +
728         /*
729          *      Get and verify the address.
730          */
731 @@ -416,10 +420,22 @@
732         return err;
733  }
734  
735 +extern DEFINE_PER_CPU(int, sknid_elevator);
736  static inline unsigned int run_filter(struct sk_buff *skb, struct sock *sk,
737                                       unsigned int res)
738  {
739         struct sk_filter *filter;
740 +       int tag = skb->skb_tag;
741 +       int *elevator=&__get_cpu_var(sknid_elevator);
742 +
743 +       if (sk->sk_nx_info && !(tag == 1 || sk->sk_nid == tag)) {
744 +               *elevator=-2;
745 +               return 0;
746 +       }
747 +       else if (!sk->sk_nx_info && *elevator) {
748 +               /* Root has already seen this packet */
749 +               return 0;
750 +       }
751  
752         rcu_read_lock_bh();
753         filter = rcu_dereference(sk->sk_filter);
754 @@ -711,6 +727,9 @@
755         unsigned char *addr;
756         int ifindex, err, reserve = 0;
757  
758 +       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND)) 
759 +               return -EPERM;
760 +
761         /*
762          *      Get and verify the address.
763          */
764 @@ -984,7 +1003,7 @@
765         __be16 proto = (__force __be16)protocol; /* weird, but documented */
766         int err;
767  
768 -       if (!capable(CAP_NET_RAW))
769 +       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET))
770                 return -EPERM;
771         if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
772             sock->type != SOCK_PACKET)