cleanup
[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-05-05 00:06:39.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-05-05 00:06:39.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-05-05 00:06:39.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-05-05 00:06:39.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-05-05 00:06:39.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-05-05 00:06:39.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-05-05 00:06:36.000000000 -0400
83 +++ linux-2.6.22-520/include/linux/vserver/network.h    2008-05-05 00:06:39.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-05-05 00:06:39.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 +       xid_t 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-05-05 00:06:39.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/skbuff.c linux-2.6.22-520/net/core/skbuff.c
119 --- linux-2.6.22-510/net/core/skbuff.c  2007-07-08 19:32:17.000000000 -0400
120 +++ linux-2.6.22-520/net/core/skbuff.c  2008-05-05 00:06:39.000000000 -0400
121 @@ -56,6 +56,7 @@
122  #include <linux/rtnetlink.h>
123  #include <linux/init.h>
124  #include <linux/scatterlist.h>
125 +#include <linux/vs_network.h>
126  
127  #include <net/protocol.h>
128  #include <net/dst.h>
129 @@ -174,6 +175,7 @@
130         skb->data = data;
131         skb_reset_tail_pointer(skb);
132         skb->end = skb->tail + size;
133 +       skb->skb_tag = nx_current_nid();
134         /* make sure we initialize shinfo sequentially */
135         shinfo = skb_shinfo(skb);
136         atomic_set(&shinfo->dataref, 1);
137 @@ -443,6 +445,8 @@
138         C(tail);
139         C(end);
140  
141 +       /* Sapan: Cloned skbs aren't owned by anyone. Let the cloner decide who it belongs to. */
142 +
143         atomic_inc(&(skb_shinfo(skb)->dataref));
144         skb->cloned = 1;
145  
146 @@ -492,6 +496,7 @@
147         new->tc_index   = old->tc_index;
148  #endif
149         skb_copy_secmark(new, old);
150 +       new->skb_tag = old->skb_tag;
151         atomic_set(&new->users, 1);
152         skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
153         skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
154 diff -Nurb linux-2.6.22-510/net/core/sock.c linux-2.6.22-520/net/core/sock.c
155 --- linux-2.6.22-510/net/core/sock.c    2008-05-05 00:06:36.000000000 -0400
156 +++ linux-2.6.22-520/net/core/sock.c    2008-05-05 00:06:39.000000000 -0400
157 @@ -444,6 +444,19 @@
158                 }
159                 goto set_sndbuf;
160  
161 +       case SO_SETXID:
162 +               if (current_vx_info()) {
163 +                       ret = -EPERM;
164 +                       break;
165 +               }
166 +               if (val < 0 || val > MAX_S_CONTEXT) {
167 +                       ret = -EINVAL;
168 +                       break;
169 +               }
170 +               sk->sk_xid = val;
171 +               sk->sk_nid = val;
172 +               break;
173 +
174         case SO_RCVBUF:
175                 /* Don't error on this BSD doesn't and if you think
176                    about it this is right. Otherwise apps have to
177 @@ -573,7 +586,7 @@
178                 char devname[IFNAMSIZ];
179  
180                 /* Sorry... */
181 -               if (!capable(CAP_NET_RAW)) {
182 +               if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
183                         ret = -EPERM;
184                         break;
185                 }
186 diff -Nurb linux-2.6.22-510/net/ipv4/af_inet.c linux-2.6.22-520/net/ipv4/af_inet.c
187 --- linux-2.6.22-510/net/ipv4/af_inet.c 2008-05-05 00:06:36.000000000 -0400
188 +++ linux-2.6.22-520/net/ipv4/af_inet.c 2008-05-05 00:06:39.000000000 -0400
189 @@ -178,6 +178,8 @@
190                         return -EAGAIN;
191                 }
192                 inet->sport = htons(inet->num);
193 +               sk->sk_xid = vx_current_xid();
194 +               sk->sk_nid = nx_current_nid();
195         }
196         release_sock(sk);
197         return 0;
198 @@ -312,6 +314,9 @@
199         if ((protocol == IPPROTO_ICMP) &&
200                 nx_capable(answer->capability, NXC_RAW_ICMP))
201                 goto override;
202 +       if (sock->type == SOCK_RAW &&
203 +               nx_capable(answer->capability, NXC_RAW_SOCKET))
204 +               goto override;
205         if (answer->capability > 0 && !capable(answer->capability))
206                 goto out_rcu_unlock;
207  override:
208 diff -Nurb linux-2.6.22-510/net/ipv4/icmp.c linux-2.6.22-520/net/ipv4/icmp.c
209 --- linux-2.6.22-510/net/ipv4/icmp.c    2008-05-05 00:06:39.000000000 -0400
210 +++ linux-2.6.22-520/net/ipv4/icmp.c    2008-05-05 00:06:39.000000000 -0400
211 @@ -709,7 +709,7 @@
212         if ((raw_sk = sk_head(&raw_v4_htable[hash])) != NULL) {
213                 while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr,
214                                                  iph->saddr,
215 -                                                skb->dev->ifindex)) != NULL) {
216 +                                                skb->dev->ifindex, skb->skb_tag)) != NULL) {
217                         raw_err(raw_sk, skb, info);
218                         raw_sk = sk_next(raw_sk);
219                         iph = (struct iphdr *)skb->data;
220 diff -Nurb linux-2.6.22-510/net/ipv4/ip_options.c linux-2.6.22-520/net/ipv4/ip_options.c
221 --- linux-2.6.22-510/net/ipv4/ip_options.c      2007-07-08 19:32:17.000000000 -0400
222 +++ linux-2.6.22-520/net/ipv4/ip_options.c      2008-05-05 00:06:39.000000000 -0400
223 @@ -409,7 +409,7 @@
224                                         optptr[2] += 8;
225                                         break;
226                                       default:
227 -                                       if (!skb && !capable(CAP_NET_RAW)) {
228 +                                       if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
229                                                 pp_ptr = optptr + 3;
230                                                 goto error;
231                                         }
232 @@ -445,7 +445,7 @@
233                                 opt->router_alert = optptr - iph;
234                         break;
235                       case IPOPT_CIPSO:
236 -                       if ((!skb && !capable(CAP_NET_RAW)) || opt->cipso) {
237 +                       if ((!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) || opt->cipso) {
238                                 pp_ptr = optptr;
239                                 goto error;
240                         }
241 @@ -458,7 +458,7 @@
242                       case IPOPT_SEC:
243                       case IPOPT_SID:
244                       default:
245 -                       if (!skb && !capable(CAP_NET_RAW)) {
246 +                       if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
247                                 pp_ptr = optptr;
248                                 goto error;
249                         }
250 diff -Nurb linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c
251 --- linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c       2008-05-05 00:06:26.000000000 -0400
252 +++ linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c       2008-05-05 00:06:39.000000000 -0400
253 @@ -49,6 +49,8 @@
254         else
255                 logflags = NF_LOG_MASK;
256  
257 +       printk("TAG=%d ", skb->skb_tag);
258 +
259         ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
260         if (ih == NULL) {
261                 printk("TRUNCATED");
262 diff -Nurb linux-2.6.22-510/net/ipv4/raw.c linux-2.6.22-520/net/ipv4/raw.c
263 --- linux-2.6.22-510/net/ipv4/raw.c     2008-05-05 00:06:36.000000000 -0400
264 +++ linux-2.6.22-520/net/ipv4/raw.c     2008-05-05 00:06:39.000000000 -0400
265 @@ -103,7 +103,7 @@
266  
267  struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
268                              __be32 raddr, __be32 laddr,
269 -                            int dif)
270 +                            int dif, int tag)
271  {
272         struct hlist_node *node;
273  
274 @@ -112,6 +112,7 @@
275  
276                 if (inet->num == num                                    &&
277                     !(inet->daddr && inet->daddr != raddr)              &&
278 +                   (!sk->sk_nx_info || tag == 1 || sk->sk_nid == tag)  &&
279                     v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
280                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
281                         goto found; /* gotcha */
282 @@ -161,7 +162,7 @@
283                 goto out;
284         sk = __raw_v4_lookup(__sk_head(head), iph->protocol,
285                              iph->saddr, iph->daddr,
286 -                            skb->dev->ifindex);
287 +                            skb->dev->ifindex, skb->skb_tag);
288  
289         while (sk) {
290                 delivered = 1;
291 @@ -174,7 +175,7 @@
292                 }
293                 sk = __raw_v4_lookup(sk_next(sk), iph->protocol,
294                                      iph->saddr, iph->daddr,
295 -                                    skb->dev->ifindex);
296 +                                    skb->dev->ifindex, skb->skb_tag);
297         }
298  out:
299         read_unlock(&raw_v4_lock);
300 @@ -315,7 +316,7 @@
301         }
302  
303         err = -EPERM;
304 -       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
305 +       if (!nx_check(0, VS_ADMIN) && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET) &&
306                 sk->sk_nx_info &&
307                 !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
308                 goto error_free;
309 diff -Nurb linux-2.6.22-510/net/netfilter/Kconfig linux-2.6.22-520/net/netfilter/Kconfig
310 --- linux-2.6.22-510/net/netfilter/Kconfig      2007-07-08 19:32:17.000000000 -0400
311 +++ linux-2.6.22-520/net/netfilter/Kconfig      2008-05-05 00:06:39.000000000 -0400
312 @@ -389,6 +389,13 @@
313  
314           To compile it as a module, choose M here.  If unsure, say N.
315  
316 +config NETFILTER_XT_TARGET_SETXID
317 +       tristate '"SETXID" target support'
318 +       depends on NETFILTER_XTABLES
319 +       help
320 +         This option adds a `SETXID' target, which allows you to alter the
321 +         xid of a socket.
322 +
323  config NETFILTER_XT_MATCH_COMMENT
324         tristate  '"comment" match support'
325         depends on NETFILTER_XTABLES
326 diff -Nurb linux-2.6.22-510/net/netfilter/Makefile linux-2.6.22-520/net/netfilter/Makefile
327 --- linux-2.6.22-510/net/netfilter/Makefile     2007-07-08 19:32:17.000000000 -0400
328 +++ linux-2.6.22-520/net/netfilter/Makefile     2008-05-05 00:06:39.000000000 -0400
329 @@ -37,6 +37,7 @@
330  obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
331  
332  # targets
333 +obj-$(CONFIG_NETFILTER_XT_TARGET_SETXID) += xt_SETXID.o
334  obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o
335  obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
336  obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
337 diff -Nurb linux-2.6.22-510/net/netfilter/nf_conntrack_core.c linux-2.6.22-520/net/netfilter/nf_conntrack_core.c
338 --- linux-2.6.22-510/net/netfilter/nf_conntrack_core.c  2007-07-08 19:32:17.000000000 -0400
339 +++ linux-2.6.22-520/net/netfilter/nf_conntrack_core.c  2008-05-05 00:06:39.000000000 -0400
340 @@ -726,6 +726,8 @@
341  
342         /* Overload tuple linked list to put us in unconfirmed list. */
343         list_add(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list, &unconfirmed);
344 +       conntrack->xid[IP_CT_DIR_ORIGINAL] = -1;
345 +       conntrack->xid[IP_CT_DIR_REPLY] = -1;
346  
347         write_unlock_bh(&nf_conntrack_lock);
348  
349 diff -Nurb linux-2.6.22-510/net/netfilter/xt_MARK.c linux-2.6.22-520/net/netfilter/xt_MARK.c
350 --- linux-2.6.22-510/net/netfilter/xt_MARK.c    2007-07-08 19:32:17.000000000 -0400
351 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c    2008-05-09 14:09:29.000000000 -0400
352 @@ -5,13 +5,18 @@
353   * This program is free software; you can redistribute it and/or modify
354   * it under the terms of the GNU General Public License version 2 as
355   * published by the Free Software Foundation.
356 + *
357   */
358  
359  #include <linux/module.h>
360 +#include <linux/version.h>
361  #include <linux/skbuff.h>
362  #include <linux/ip.h>
363  #include <net/checksum.h>
364 +#include <net/route.h>
365 +#include <net/inet_hashtables.h>
366  
367 +#include <net/netfilter/nf_conntrack.h>
368  #include <linux/netfilter/x_tables.h>
369  #include <linux/netfilter/xt_MARK.h>
370  
371 @@ -21,6 +26,48 @@
372  MODULE_ALIAS("ipt_MARK");
373  MODULE_ALIAS("ip6t_MARK");
374  
375 +static inline u_int16_t
376 +get_dst_port(struct nf_conntrack_tuple *tuple)
377 +{
378 +       switch (tuple->dst.protonum) {
379 +       case IPPROTO_GRE:
380 +               /* XXX Truncate 32-bit GRE key to 16 bits */
381 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
382 +               return tuple->dst.u.gre.key;
383 +#else
384 +               return htons(ntohl(tuple->dst.u.gre.key));
385 +#endif  
386 +       case IPPROTO_ICMP:
387 +               /* Bind on ICMP echo ID */
388 +               return tuple->src.u.icmp.id;
389 +       case IPPROTO_TCP:
390 +               return tuple->dst.u.tcp.port;
391 +       case IPPROTO_UDP:
392 +               return tuple->dst.u.udp.port;
393 +       default:
394 +               return tuple->dst.u.all;
395 +       }
396 +}
397 +
398 +static inline u_int16_t
399 +get_src_port(struct nf_conntrack_tuple *tuple)
400 +{
401 +       switch (tuple->dst.protonum) {
402 +       case IPPROTO_GRE:
403 +               /* XXX Truncate 32-bit GRE key to 16 bits */
404 +               return htons(ntohl(tuple->src.u.gre.key));
405 +       case IPPROTO_ICMP:
406 +               /* Bind on ICMP echo ID */
407 +               return tuple->src.u.icmp.id;
408 +       case IPPROTO_TCP:
409 +               return tuple->src.u.tcp.port;
410 +       case IPPROTO_UDP:
411 +               return tuple->src.u.udp.port;
412 +       default:
413 +               return tuple->src.u.all;
414 +       }
415 +}
416 +
417  static unsigned int
418  target_v0(struct sk_buff **pskb,
419           const struct net_device *in,
420 @@ -44,7 +91,16 @@
421           const void *targinfo)
422  {
423         const struct xt_mark_target_info_v1 *markinfo = targinfo;
424 -       int mark = 0;
425 +       struct nf_conn *ct;
426 +       int mark = -1;
427 +       extern struct inet_hashinfo tcp_hashinfo;
428 +       enum ip_conntrack_dir dir;
429 +       u_int32_t src_ip;
430 +       u_int16_t src_port;
431 +       u_int16_t proto;
432 +
433 +        u_int32_t ip;
434 +        u_int16_t port;
435  
436         switch (markinfo->mode) {
437         case XT_MARK_SET:
438 @@ -58,8 +114,58 @@
439         case XT_MARK_OR:
440                 mark = (*pskb)->mark | markinfo->mark;
441                 break;
442 +
443 +               case XT_MARK_COPYXID: {
444 +                                             enum ip_conntrack_info ctinfo;
445 +                                             struct sock *connection_sk;
446 +                                             int dif;
447 +
448 +                                             ct = nf_ct_get((*pskb), &ctinfo);
449 +                                             if (!ct) 
450 +                                                     break;
451 +
452 +                                             dir = CTINFO2DIR(ctinfo);
453 +                                             src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
454 +                                             src_port = get_src_port(&ct->tuplehash[dir].tuple);
455 +                                             proto = ct->tuplehash[dir].tuple.dst.protonum;
456 +
457 +                                             dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
458 +                                             ip = ct->tuplehash[dir].tuple.dst.u3.ip;
459 +                                             port = get_dst_port(&ct->tuplehash[dir].tuple);
460 +
461 +                                             if (proto == 1 || proto == 17) {
462 +                                                     if (((*pskb)->mark!=-1) && (*pskb)->mark)
463 +                                                             ct->xid[0]=(*pskb)->mark;
464 +                                                     if (ct->xid[0]) 
465 +                                                             mark = ct->xid[0];
466 +
467 +                                             }
468 +                                             else if (proto == 6) { 
469 +                                                     if ((*pskb)->sk) {
470 +                                                             connection_sk = (*pskb)->sk;
471 +                                                             sock_hold(connection_sk);
472 +                                                     }
473 +                                                     else 
474 +                                                             connection_sk = inet_lookup_established(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
475 +                                                             
476 +
477 +                                                     if (connection_sk) {
478 +                                                             if (connection_sk->sk_state == TCP_TIME_WAIT) {
479 +                                                                     inet_twsk_put(inet_twsk(connection_sk));
480 +                                                                     break;
481 +                                                             }
482 +                                                             connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
483 +                                                             ct->xid[!dir]=connection_sk->sk_xid;
484 +                                                             if (connection_sk->sk_xid != 0) 
485 +                                                                     mark = connection_sk->sk_xid;
486 +                                                             sock_put(connection_sk);
487 +                                                     }
488 +                                             }
489 +                                             break;
490 +                                     }
491         }
492  
493 +       if (mark != -1)
494         (*pskb)->mark = mark;
495         return XT_CONTINUE;
496  }
497 @@ -92,7 +198,8 @@
498  
499         if (markinfo->mode != XT_MARK_SET
500             && markinfo->mode != XT_MARK_AND
501 -           && markinfo->mode != XT_MARK_OR) {
502 +           && markinfo->mode != XT_MARK_OR
503 +           && markinfo->mode != XT_MARK_COPYXID) {
504                 printk(KERN_WARNING "MARK: unknown mode %u\n",
505                        markinfo->mode);
506                 return 0;
507 diff -Nurb linux-2.6.22-510/net/netfilter/xt_SETXID.c linux-2.6.22-520/net/netfilter/xt_SETXID.c
508 --- linux-2.6.22-510/net/netfilter/xt_SETXID.c  1969-12-31 19:00:00.000000000 -0500
509 +++ linux-2.6.22-520/net/netfilter/xt_SETXID.c  2008-05-05 00:06:39.000000000 -0400
510 @@ -0,0 +1,79 @@
511 +#include <linux/module.h>
512 +#include <linux/skbuff.h>
513 +#include <linux/ip.h>
514 +#include <net/checksum.h>
515 +#include <linux/vs_network.h>
516 +
517 +#include <linux/netfilter/x_tables.h>
518 +#include <linux/netfilter/xt_SETXID.h>
519 +
520 +MODULE_LICENSE("GPL");
521 +MODULE_AUTHOR("");
522 +MODULE_DESCRIPTION("");
523 +MODULE_ALIAS("ipt_SETXID");
524 +
525 +static unsigned int
526 +target_v1(struct sk_buff **pskb,
527 +         const struct net_device *in,
528 +         const struct net_device *out,
529 +         unsigned int hooknum,
530 +         const struct xt_target *target,
531 +         const void *targinfo)
532 +{
533 +       const struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
534 +
535 +       switch (setxidinfo->mode) {
536 +       case XT_SET_PACKET_XID:
537 +                (*pskb)->skb_tag = setxidinfo->mark;
538 +               break;
539 +       }
540 +       return XT_CONTINUE;
541 +}
542 +
543 +
544 +static int
545 +checkentry_v1(const char *tablename,
546 +             const void *entry,
547 +             const struct xt_target *target,
548 +             void *targinfo,
549 +             unsigned int hook_mask)
550 +{
551 +       struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
552 +
553 +       if (setxidinfo->mode != XT_SET_PACKET_XID) {
554 +               printk(KERN_WARNING "SETXID: unknown mode %u\n",
555 +                      setxidinfo->mode);
556 +               return 0;
557 +       }
558 +
559 +       return 1;
560 +}
561 +
562 +static struct xt_target xt_setxid_target[] = {
563 +       {
564 +               .name           = "SETXID",
565 +               .family         = AF_INET,
566 +               .revision       = 1,
567 +               .checkentry     = checkentry_v1,
568 +               .target         = target_v1,
569 +               .targetsize     = sizeof(struct xt_setxid_target_info_v1),
570 +               .table          = "mangle",
571 +               .me             = THIS_MODULE,
572 +       }
573 +};
574 +
575 +static int __init init(void)
576 +{
577 +       int err;
578 +
579 +       err = xt_register_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
580 +       return err;
581 +}
582 +
583 +static void __exit fini(void)
584 +{
585 +       xt_unregister_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
586 +}
587 +
588 +module_init(init);
589 +module_exit(fini);
590 diff -Nurb linux-2.6.22-510/net/packet/af_packet.c linux-2.6.22-520/net/packet/af_packet.c
591 --- linux-2.6.22-510/net/packet/af_packet.c     2007-07-08 19:32:17.000000000 -0400
592 +++ linux-2.6.22-520/net/packet/af_packet.c     2008-05-05 00:06:39.000000000 -0400
593 @@ -78,6 +78,7 @@
594  #include <linux/poll.h>
595  #include <linux/module.h>
596  #include <linux/init.h>
597 +#include <linux/vs_network.h>
598  
599  #ifdef CONFIG_INET
600  #include <net/inet_common.h>
601 @@ -324,6 +325,9 @@
602         __be16 proto=0;
603         int err;
604  
605 +       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
606 +               return -EPERM;
607 +
608         /*
609          *      Get and verify the address.
610          */
611 @@ -420,6 +424,10 @@
612                                       unsigned int res)
613  {
614         struct sk_filter *filter;
615 +       int tag = skb->skb_tag;
616 +
617 +       if (sk->sk_nx_info && !(tag == 1 || sk->sk_nid == tag))
618 +               return 0;
619  
620         rcu_read_lock_bh();
621         filter = rcu_dereference(sk->sk_filter);
622 @@ -711,6 +719,9 @@
623         unsigned char *addr;
624         int ifindex, err, reserve = 0;
625  
626 +       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
627 +               return -EPERM;
628 +
629         /*
630          *      Get and verify the address.
631          */
632 @@ -984,7 +995,7 @@
633         __be16 proto = (__force __be16)protocol; /* weird, but documented */
634         int err;
635  
636 -       if (!capable(CAP_NET_RAW))
637 +       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET))
638                 return -EPERM;
639         if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
640             sock->type != SOCK_PACKET)
641 diff -Nurb linux-2.6.22-510/xt_MARK.c linux-2.6.22-520/xt_MARK.c
642 --- linux-2.6.22-510/xt_MARK.c  1969-12-31 19:00:00.000000000 -0500
643 +++ linux-2.6.22-520/xt_MARK.c  2008-05-05 00:06:39.000000000 -0400
644 @@ -0,0 +1,287 @@
645 +/* This is a module which is used for setting the NFMARK field of an skb. */
646 +
647 +/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
648 + *
649 + * This program is free software; you can redistribute it and/or modify
650 + * it under the terms of the GNU General Public License version 2 as
651 + * published by the Free Software Foundation.
652 + *
653 + */
654 +
655 +#include <linux/module.h>
656 +#include <linux/version.h>
657 +#include <linux/skbuff.h>
658 +#include <linux/ip.h>
659 +#include <net/checksum.h>
660 +#include <net/route.h>
661 +#include <net/inet_hashtables.h>
662 +
663 +#include <net/netfilter/nf_conntrack.h>
664 +#include <linux/netfilter/x_tables.h>
665 +#include <linux/netfilter/xt_MARK.h>
666 +
667 +MODULE_LICENSE("GPL");
668 +MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
669 +MODULE_DESCRIPTION("ip[6]tables MARK modification module");
670 +MODULE_ALIAS("ipt_MARK");
671 +MODULE_ALIAS("ip6t_MARK");
672 +
673 +static inline u_int16_t
674 +get_dst_port(struct nf_conntrack_tuple *tuple)
675 +{
676 +       switch (tuple->dst.protonum) {
677 +       case IPPROTO_GRE:
678 +               /* XXX Truncate 32-bit GRE key to 16 bits */
679 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
680 +               return tuple->dst.u.gre.key;
681 +#else
682 +               return htons(ntohl(tuple->dst.u.gre.key));
683 +#endif  
684 +       case IPPROTO_ICMP:
685 +               /* Bind on ICMP echo ID */
686 +               return tuple->src.u.icmp.id;
687 +       case IPPROTO_TCP:
688 +               return tuple->dst.u.tcp.port;
689 +       case IPPROTO_UDP:
690 +               return tuple->dst.u.udp.port;
691 +       default:
692 +               return tuple->dst.u.all;
693 +       }
694 +}
695 +
696 +static inline u_int16_t
697 +get_src_port(struct nf_conntrack_tuple *tuple)
698 +{
699 +       switch (tuple->dst.protonum) {
700 +       case IPPROTO_GRE:
701 +               /* XXX Truncate 32-bit GRE key to 16 bits */
702 +               return htons(ntohl(tuple->src.u.gre.key));
703 +       case IPPROTO_ICMP:
704 +               /* Bind on ICMP echo ID */
705 +               return tuple->src.u.icmp.id;
706 +       case IPPROTO_TCP:
707 +               return tuple->src.u.tcp.port;
708 +       case IPPROTO_UDP:
709 +               return tuple->src.u.udp.port;
710 +       default:
711 +               return tuple->src.u.all;
712 +       }
713 +}
714 +
715 +static unsigned int
716 +target_v0(struct sk_buff **pskb,
717 +         const struct net_device *in,
718 +         const struct net_device *out,
719 +         unsigned int hooknum,
720 +         const struct xt_target *target,
721 +         const void *targinfo)
722 +{
723 +       const struct xt_mark_target_info *markinfo = targinfo;
724 +
725 +       (*pskb)->mark = markinfo->mark;
726 +       return XT_CONTINUE;
727 +}
728 +
729 +static unsigned int
730 +target_v1(struct sk_buff **pskb,
731 +         const struct net_device *in,
732 +         const struct net_device *out,
733 +         unsigned int hooknum,
734 +         const struct xt_target *target,
735 +         const void *targinfo)
736 +{
737 +       const struct xt_mark_target_info_v1 *markinfo = targinfo;
738 +       int mark = -1;
739 +
740 +       switch (markinfo->mode) {
741 +               case XT_MARK_SET:
742 +                       mark = markinfo->mark;
743 +                       break;
744 +
745 +               case XT_MARK_AND:
746 +                       mark = (*pskb)->mark & markinfo->mark;
747 +                       break;
748 +
749 +               case XT_MARK_OR:
750 +                       mark = (*pskb)->mark | markinfo->mark;
751 +                       break;
752 +
753 +               case XT_MARK_COPYXID: {
754 +                                             enum ip_conntrack_info ctinfo;
755 +                                             struct sock *connection_sk;
756 +                                             int dif;
757 +
758 +                                             struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
759 +                                             extern struct inet_hashinfo tcp_hashinfo;
760 +                                             enum ip_conntrack_dir dir;
761 +                                             if (!ct) 
762 +                                                     break;
763 +
764 +                                             dir = CTINFO2DIR(ctinfo);
765 +                                             u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
766 +                                             u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
767 +                                             u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
768 +
769 +                                             u_int32_t ip;
770 +                                             u_int16_t port;
771 +
772 +                                             dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
773 +                                             ip = ct->tuplehash[dir].tuple.dst.u3.ip;
774 +                                             port = get_dst_port(&ct->tuplehash[dir].tuple);
775 +
776 +                                             if (proto == 1 || proto == 17) {
777 +                                                     if (((*pskb)->mark!=-1) && (*pskb)->mark)
778 +                                                             ct->xid[0]=(*pskb)->mark;
779 +                                                     if (ct->xid[0]) 
780 +                                                             mark = ct->xid[0];
781 +
782 +                                             }
783 +                                             else if (proto == 6) { 
784 +                                                     if ((*pskb)->sk) {
785 +                                                             connection_sk = (*pskb)->sk;
786 +                                                             sock_hold(connection_sk);
787 +                                                     }
788 +                                                     else {
789 +                                                             connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
790 +                                                     }
791 +
792 +                                                     if (connection_sk) {
793 +                                                             connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
794 +                                                             ct->xid[!dir]=connection_sk->sk_xid;
795 +                                                             if (connection_sk->sk_xid != 0) 
796 +                                                                     mark = connection_sk->sk_xid;
797 +                                                             if (connection_sk->sk_state == TCP_TIME_WAIT)
798 +                                                                     inet_twsk_put(inet_twsk(connection_sk));
799 +                                                             else
800 +                                                                     sock_put(connection_sk);
801 +                                                     }
802 +                                             }
803 +                                             break;
804 +                                     }
805 +       }
806 +
807 +       if (mark != -1)
808 +       (*pskb)->mark = mark;
809 +       return XT_CONTINUE;
810 +}
811 +
812 +
813 +static int
814 +checkentry_v0(const char *tablename,
815 +             const void *entry,
816 +             const struct xt_target *target,
817 +             void *targinfo,
818 +             unsigned int hook_mask)
819 +{
820 +       struct xt_mark_target_info *markinfo = targinfo;
821 +
822 +       if (markinfo->mark > 0xffffffff) {
823 +               printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
824 +               return 0;
825 +       }
826 +       return 1;
827 +}
828 +
829 +static int
830 +checkentry_v1(const char *tablename,
831 +             const void *entry,
832 +             const struct xt_target *target,
833 +             void *targinfo,
834 +             unsigned int hook_mask)
835 +{
836 +       struct xt_mark_target_info_v1 *markinfo = targinfo;
837 +
838 +       if (markinfo->mode != XT_MARK_SET
839 +           && markinfo->mode != XT_MARK_AND
840 +           && markinfo->mode != XT_MARK_OR
841 +           && markinfo->mode != XT_MARK_COPYXID) {
842 +               printk(KERN_WARNING "MARK: unknown mode %u\n",
843 +                      markinfo->mode);
844 +               return 0;
845 +       }
846 +       if (markinfo->mark > 0xffffffff) {
847 +               printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
848 +               return 0;
849 +       }
850 +       return 1;
851 +}
852 +
853 +#ifdef CONFIG_COMPAT
854 +struct compat_xt_mark_target_info_v1 {
855 +       compat_ulong_t  mark;
856 +       u_int8_t        mode;
857 +       u_int8_t        __pad1;
858 +       u_int16_t       __pad2;
859 +};
860 +
861 +static void compat_from_user_v1(void *dst, void *src)
862 +{
863 +       struct compat_xt_mark_target_info_v1 *cm = src;
864 +       struct xt_mark_target_info_v1 m = {
865 +               .mark   = cm->mark,
866 +               .mode   = cm->mode,
867 +       };
868 +       memcpy(dst, &m, sizeof(m));
869 +}
870 +
871 +static int compat_to_user_v1(void __user *dst, void *src)
872 +{
873 +       struct xt_mark_target_info_v1 *m = src;
874 +       struct compat_xt_mark_target_info_v1 cm = {
875 +               .mark   = m->mark,
876 +               .mode   = m->mode,
877 +       };
878 +       return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
879 +}
880 +#endif /* CONFIG_COMPAT */
881 +
882 +static struct xt_target xt_mark_target[] = {
883 +       {
884 +               .name           = "MARK",
885 +               .family         = AF_INET,
886 +               .revision       = 0,
887 +               .checkentry     = checkentry_v0,
888 +               .target         = target_v0,
889 +               .targetsize     = sizeof(struct xt_mark_target_info),
890 +               .table          = "mangle",
891 +               .me             = THIS_MODULE,
892 +       },
893 +       {
894 +               .name           = "MARK",
895 +               .family         = AF_INET,
896 +               .revision       = 1,
897 +               .checkentry     = checkentry_v1,
898 +               .target         = target_v1,
899 +               .targetsize     = sizeof(struct xt_mark_target_info_v1),
900 +#ifdef CONFIG_COMPAT
901 +               .compatsize     = sizeof(struct compat_xt_mark_target_info_v1),
902 +               .compat_from_user = compat_from_user_v1,
903 +               .compat_to_user = compat_to_user_v1,
904 +#endif
905 +               .table          = "mangle",
906 +               .me             = THIS_MODULE,
907 +       },
908 +       {
909 +               .name           = "MARK",
910 +               .family         = AF_INET6,
911 +               .revision       = 0,
912 +               .checkentry     = checkentry_v0,
913 +               .target         = target_v0,
914 +               .targetsize     = sizeof(struct xt_mark_target_info),
915 +               .table          = "mangle",
916 +               .me             = THIS_MODULE,
917 +       },
918 +};
919 +
920 +static int __init xt_mark_init(void)
921 +{
922 +       return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
923 +}
924 +
925 +static void __exit xt_mark_fini(void)
926 +{
927 +       xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
928 +}
929 +
930 +module_init(xt_mark_init);
931 +module_exit(xt_mark_fini);