Upgraded teh VNET+ patch based on 4.2.
[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-14 16:29:22.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-14 16:29:22.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-14 16:29:22.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-14 16:29:22.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-14 16:29:22.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-14 16:29:22.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-14 16:28:36.000000000 -0400
83 +++ linux-2.6.22-520/include/linux/vserver/network.h    2008-03-14 16:29:22.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 diff -Nurb linux-2.6.22-510/include/linux/vserver/network.h.orig linux-2.6.22-520/include/linux/vserver/network.h.orig
94 --- linux-2.6.22-510/include/linux/vserver/network.h.orig       1969-12-31 19:00:00.000000000 -0500
95 +++ linux-2.6.22-520/include/linux/vserver/network.h.orig       2008-03-14 16:29:27.000000000 -0400
96 @@ -0,0 +1,143 @@
97 +#ifndef _VX_NETWORK_H
98 +#define _VX_NETWORK_H
99 +
100 +#include <linux/types.h>
101 +
102 +
103 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
104 +
105 +
106 +/* network flags */
107 +
108 +#define NXF_INFO_PRIVATE       0x00000008
109 +
110 +#define NXF_SINGLE_IP          0x00000100
111 +#define NXF_LBACK_REMAP                0x00000200
112 +
113 +#define NXF_HIDE_NETIF         0x02000000
114 +#define NXF_HIDE_LBACK         0x04000000
115 +
116 +#define NXF_STATE_SETUP                (1ULL << 32)
117 +#define NXF_STATE_ADMIN                (1ULL << 34)
118 +
119 +#define NXF_SC_HELPER          (1ULL << 36)
120 +#define NXF_PERSISTENT         (1ULL << 38)
121 +
122 +#define NXF_ONE_TIME           (0x0005ULL << 32)
123 +
124 +
125 +#define        NXF_INIT_SET            (__nxf_init_set())
126 +
127 +static inline uint64_t __nxf_init_set(void) {
128 +       return    NXF_STATE_ADMIN
129 +#ifdef CONFIG_VSERVER_AUTO_LBACK
130 +               | NXF_LBACK_REMAP
131 +               | NXF_HIDE_LBACK
132 +#endif
133 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
134 +               | NXF_SINGLE_IP
135 +#endif
136 +               | NXF_HIDE_NETIF;
137 +}
138 +
139 +
140 +/* network caps */
141 +
142 +#define NXC_RAW_ICMP           0x00000100
143 +
144 +
145 +/* address types */
146 +
147 +#define NXA_TYPE_IPV4          0x0001
148 +#define NXA_TYPE_IPV6          0x0002
149 +
150 +#define NXA_TYPE_NONE          0x0000
151 +#define NXA_TYPE_ANY           0x00FF
152 +
153 +#define NXA_TYPE_ADDR          0x0010
154 +#define NXA_TYPE_MASK          0x0020
155 +#define NXA_TYPE_RANGE         0x0040
156 +
157 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
158 +
159 +#define NXA_MOD_BCAST          0x0100
160 +#define NXA_MOD_LBACK          0x0200
161 +
162 +#define NXA_LOOPBACK           0x1000
163 +
164 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
165 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
166 +
167 +#ifdef __KERNEL__
168 +
169 +#include <linux/list.h>
170 +#include <linux/spinlock.h>
171 +#include <linux/rcupdate.h>
172 +#include <linux/in.h>
173 +#include <linux/in6.h>
174 +#include <asm/atomic.h>
175 +
176 +struct nx_addr_v4 {
177 +       struct nx_addr_v4 *next;
178 +       struct in_addr ip[2];
179 +       struct in_addr mask;
180 +       uint16_t type;
181 +       uint16_t flags;
182 +};
183 +
184 +struct nx_addr_v6 {
185 +       struct nx_addr_v6 *next;
186 +       struct in6_addr ip;
187 +       struct in6_addr mask;
188 +       uint32_t prefix;
189 +       uint16_t type;
190 +       uint16_t flags;
191 +};
192 +
193 +struct nx_info {
194 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
195 +       nid_t nx_id;                    /* vnet id */
196 +       atomic_t nx_usecnt;             /* usage count */
197 +       atomic_t nx_tasks;              /* tasks count */
198 +       int nx_state;                   /* context state */
199 +
200 +       uint64_t nx_flags;              /* network flag word */
201 +       uint64_t nx_ncaps;              /* network capabilities */
202 +
203 +       struct in_addr v4_lback;        /* Loopback address */
204 +       struct in_addr v4_bcast;        /* Broadcast address */
205 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
206 +#ifdef CONFIG_IPV6
207 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
208 +#endif
209 +       char nx_name[65];               /* network context name */
210 +};
211 +
212 +
213 +/* status flags */
214 +
215 +#define NXS_HASHED      0x0001
216 +#define NXS_SHUTDOWN    0x0100
217 +#define NXS_RELEASED    0x8000
218 +
219 +extern struct nx_info *lookup_nx_info(int);
220 +
221 +extern int get_nid_list(int, unsigned int *, int);
222 +extern int nid_is_hashed(nid_t);
223 +
224 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
225 +
226 +extern long vs_net_change(struct nx_info *, unsigned int);
227 +
228 +struct sock;
229 +
230 +
231 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
232 +#ifdef  CONFIG_IPV6
233 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
234 +#else
235 +#define NX_IPV6(n)     (0)
236 +#endif
237 +
238 +#endif /* __KERNEL__ */
239 +#endif /* _VX_NETWORK_H */
240 diff -Nurb linux-2.6.22-510/include/linux/vserver/network.h.orig.orig linux-2.6.22-520/include/linux/vserver/network.h.orig.orig
241 --- linux-2.6.22-510/include/linux/vserver/network.h.orig.orig  1969-12-31 19:00:00.000000000 -0500
242 +++ linux-2.6.22-520/include/linux/vserver/network.h.orig.orig  2008-03-14 16:28:36.000000000 -0400
243 @@ -0,0 +1,143 @@
244 +#ifndef _VX_NETWORK_H
245 +#define _VX_NETWORK_H
246 +
247 +#include <linux/types.h>
248 +
249 +
250 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
251 +
252 +
253 +/* network flags */
254 +
255 +#define NXF_INFO_PRIVATE       0x00000008
256 +
257 +#define NXF_SINGLE_IP          0x00000100
258 +#define NXF_LBACK_REMAP                0x00000200
259 +
260 +#define NXF_HIDE_NETIF         0x02000000
261 +#define NXF_HIDE_LBACK         0x04000000
262 +
263 +#define NXF_STATE_SETUP                (1ULL << 32)
264 +#define NXF_STATE_ADMIN                (1ULL << 34)
265 +
266 +#define NXF_SC_HELPER          (1ULL << 36)
267 +#define NXF_PERSISTENT         (1ULL << 38)
268 +
269 +#define NXF_ONE_TIME           (0x0005ULL << 32)
270 +
271 +
272 +#define        NXF_INIT_SET            (__nxf_init_set())
273 +
274 +static inline uint64_t __nxf_init_set(void) {
275 +       return    NXF_STATE_ADMIN
276 +#ifdef CONFIG_VSERVER_AUTO_LBACK
277 +               | NXF_LBACK_REMAP
278 +               | NXF_HIDE_LBACK
279 +#endif
280 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
281 +               | NXF_SINGLE_IP
282 +#endif
283 +               | NXF_HIDE_NETIF;
284 +}
285 +
286 +
287 +/* network caps */
288 +
289 +#define NXC_RAW_ICMP           0x00000100
290 +
291 +
292 +/* address types */
293 +
294 +#define NXA_TYPE_IPV4          0x0001
295 +#define NXA_TYPE_IPV6          0x0002
296 +
297 +#define NXA_TYPE_NONE          0x0000
298 +#define NXA_TYPE_ANY           0x00FF
299 +
300 +#define NXA_TYPE_ADDR          0x0010
301 +#define NXA_TYPE_MASK          0x0020
302 +#define NXA_TYPE_RANGE         0x0040
303 +
304 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
305 +
306 +#define NXA_MOD_BCAST          0x0100
307 +#define NXA_MOD_LBACK          0x0200
308 +
309 +#define NXA_LOOPBACK           0x1000
310 +
311 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
312 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
313 +
314 +#ifdef __KERNEL__
315 +
316 +#include <linux/list.h>
317 +#include <linux/spinlock.h>
318 +#include <linux/rcupdate.h>
319 +#include <linux/in.h>
320 +#include <linux/in6.h>
321 +#include <asm/atomic.h>
322 +
323 +struct nx_addr_v4 {
324 +       struct nx_addr_v4 *next;
325 +       struct in_addr ip[2];
326 +       struct in_addr mask;
327 +       uint16_t type;
328 +       uint16_t flags;
329 +};
330 +
331 +struct nx_addr_v6 {
332 +       struct nx_addr_v6 *next;
333 +       struct in6_addr ip;
334 +       struct in6_addr mask;
335 +       uint32_t prefix;
336 +       uint16_t type;
337 +       uint16_t flags;
338 +};
339 +
340 +struct nx_info {
341 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
342 +       nid_t nx_id;                    /* vnet id */
343 +       atomic_t nx_usecnt;             /* usage count */
344 +       atomic_t nx_tasks;              /* tasks count */
345 +       int nx_state;                   /* context state */
346 +
347 +       uint64_t nx_flags;              /* network flag word */
348 +       uint64_t nx_ncaps;              /* network capabilities */
349 +
350 +       struct in_addr v4_lback;        /* Loopback address */
351 +       struct in_addr v4_bcast;        /* Broadcast address */
352 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
353 +#ifdef CONFIG_IPV6
354 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
355 +#endif
356 +       char nx_name[65];               /* network context name */
357 +};
358 +
359 +
360 +/* status flags */
361 +
362 +#define NXS_HASHED      0x0001
363 +#define NXS_SHUTDOWN    0x0100
364 +#define NXS_RELEASED    0x8000
365 +
366 +extern struct nx_info *lookup_nx_info(int);
367 +
368 +extern int get_nid_list(int, unsigned int *, int);
369 +extern int nid_is_hashed(nid_t);
370 +
371 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
372 +
373 +extern long vs_net_change(struct nx_info *, unsigned int);
374 +
375 +struct sock;
376 +
377 +
378 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
379 +#ifdef  CONFIG_IPV6
380 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
381 +#else
382 +#define NX_IPV6(n)     (0)
383 +#endif
384 +
385 +#endif /* __KERNEL__ */
386 +#endif /* _VX_NETWORK_H */
387 diff -Nurb linux-2.6.22-510/include/net/netfilter/nf_conntrack.h linux-2.6.22-520/include/net/netfilter/nf_conntrack.h
388 --- linux-2.6.22-510/include/net/netfilter/nf_conntrack.h       2007-07-08 19:32:17.000000000 -0400
389 +++ linux-2.6.22-520/include/net/netfilter/nf_conntrack.h       2008-03-14 16:29:27.000000000 -0400
390 @@ -131,6 +131,9 @@
391         /* Storage reserved for other modules: */
392         union nf_conntrack_proto proto;
393  
394 +       /* PLANETLAB. VNET-specific */
395 +       xid_t xid[IP_CT_DIR_MAX];
396 +
397         /* features dynamically at the end: helper, nat (both optional) */
398         char data[0];
399  };
400 diff -Nurb linux-2.6.22-510/include/net/raw.h linux-2.6.22-520/include/net/raw.h
401 --- linux-2.6.22-510/include/net/raw.h  2007-07-08 19:32:17.000000000 -0400
402 +++ linux-2.6.22-520/include/net/raw.h  2008-03-14 16:29:27.000000000 -0400
403 @@ -36,7 +36,7 @@
404  
405  extern struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
406                                     __be32 raddr, __be32 laddr,
407 -                                   int dif);
408 +                                   int dif, int tag);
409  
410  extern int raw_v4_input(struct sk_buff *skb, struct iphdr *iph, int hash);
411  
412 diff -Nurb linux-2.6.22-510/net/core/skbuff.c linux-2.6.22-520/net/core/skbuff.c
413 --- linux-2.6.22-510/net/core/skbuff.c  2007-07-08 19:32:17.000000000 -0400
414 +++ linux-2.6.22-520/net/core/skbuff.c  2008-03-14 16:29:27.000000000 -0400
415 @@ -56,6 +56,7 @@
416  #include <linux/rtnetlink.h>
417  #include <linux/init.h>
418  #include <linux/scatterlist.h>
419 +#include <linux/vs_network.h>
420  
421  #include <net/protocol.h>
422  #include <net/dst.h>
423 @@ -174,6 +175,7 @@
424         skb->data = data;
425         skb_reset_tail_pointer(skb);
426         skb->end = skb->tail + size;
427 +       skb->skb_tag = nx_current_nid();
428         /* make sure we initialize shinfo sequentially */
429         shinfo = skb_shinfo(skb);
430         atomic_set(&shinfo->dataref, 1);
431 @@ -443,6 +445,8 @@
432         C(tail);
433         C(end);
434  
435 +       /* Sapan: Cloned skbs aren't owned by anyone. Let the cloner decide who it belongs to. */
436 +
437         atomic_inc(&(skb_shinfo(skb)->dataref));
438         skb->cloned = 1;
439  
440 @@ -492,6 +496,7 @@
441         new->tc_index   = old->tc_index;
442  #endif
443         skb_copy_secmark(new, old);
444 +       new->skb_tag = old->skb_tag;
445         atomic_set(&new->users, 1);
446         skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
447         skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
448 diff -Nurb linux-2.6.22-510/net/core/sock.c linux-2.6.22-520/net/core/sock.c
449 --- linux-2.6.22-510/net/core/sock.c    2008-03-14 16:28:36.000000000 -0400
450 +++ linux-2.6.22-520/net/core/sock.c    2008-03-14 16:29:27.000000000 -0400
451 @@ -444,6 +444,19 @@
452                 }
453                 goto set_sndbuf;
454  
455 +       case SO_SETXID:
456 +               if (current_vx_info()) {
457 +                       ret = -EPERM;
458 +                       break;
459 +               }
460 +               if (val < 0 || val > MAX_S_CONTEXT) {
461 +                       ret = -EINVAL;
462 +                       break;
463 +               }
464 +               sk->sk_xid = val;
465 +               sk->sk_nid = val;
466 +               break;
467 +
468         case SO_RCVBUF:
469                 /* Don't error on this BSD doesn't and if you think
470                    about it this is right. Otherwise apps have to
471 @@ -573,7 +586,7 @@
472                 char devname[IFNAMSIZ];
473  
474                 /* Sorry... */
475 -               if (!capable(CAP_NET_RAW)) {
476 +               if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
477                         ret = -EPERM;
478                         break;
479                 }
480 diff -Nurb linux-2.6.22-510/net/ipv4/af_inet.c linux-2.6.22-520/net/ipv4/af_inet.c
481 --- linux-2.6.22-510/net/ipv4/af_inet.c 2008-03-14 16:28:36.000000000 -0400
482 +++ linux-2.6.22-520/net/ipv4/af_inet.c 2008-03-14 16:29:27.000000000 -0400
483 @@ -178,6 +178,8 @@
484                         return -EAGAIN;
485                 }
486                 inet->sport = htons(inet->num);
487 +               sk->sk_xid = vx_current_xid();
488 +               sk->sk_nid = nx_current_nid();
489         }
490         release_sock(sk);
491         return 0;
492 @@ -312,6 +314,9 @@
493         if ((protocol == IPPROTO_ICMP) &&
494                 nx_capable(answer->capability, NXC_RAW_ICMP))
495                 goto override;
496 +       if (sock->type == SOCK_RAW &&
497 +               nx_capable(answer->capability, NXC_RAW_SOCKET))
498 +               goto override;
499         if (answer->capability > 0 && !capable(answer->capability))
500                 goto out_rcu_unlock;
501  override:
502 diff -Nurb linux-2.6.22-510/net/ipv4/icmp.c linux-2.6.22-520/net/ipv4/icmp.c
503 --- linux-2.6.22-510/net/ipv4/icmp.c    2008-03-14 16:28:42.000000000 -0400
504 +++ linux-2.6.22-520/net/ipv4/icmp.c    2008-03-14 16:29:27.000000000 -0400
505 @@ -709,7 +709,7 @@
506         if ((raw_sk = sk_head(&raw_v4_htable[hash])) != NULL) {
507                 while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr,
508                                                  iph->saddr,
509 -                                                skb->dev->ifindex)) != NULL) {
510 +                                                skb->dev->ifindex, skb->skb_tag)) != NULL) {
511                         raw_err(raw_sk, skb, info);
512                         raw_sk = sk_next(raw_sk);
513                         iph = (struct iphdr *)skb->data;
514 diff -Nurb linux-2.6.22-510/net/ipv4/ip_options.c linux-2.6.22-520/net/ipv4/ip_options.c
515 --- linux-2.6.22-510/net/ipv4/ip_options.c      2007-07-08 19:32:17.000000000 -0400
516 +++ linux-2.6.22-520/net/ipv4/ip_options.c      2008-03-14 16:29:27.000000000 -0400
517 @@ -409,7 +409,7 @@
518                                         optptr[2] += 8;
519                                         break;
520                                       default:
521 -                                       if (!skb && !capable(CAP_NET_RAW)) {
522 +                                       if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
523                                                 pp_ptr = optptr + 3;
524                                                 goto error;
525                                         }
526 @@ -445,7 +445,7 @@
527                                 opt->router_alert = optptr - iph;
528                         break;
529                       case IPOPT_CIPSO:
530 -                       if ((!skb && !capable(CAP_NET_RAW)) || opt->cipso) {
531 +                       if ((!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) || opt->cipso) {
532                                 pp_ptr = optptr;
533                                 goto error;
534                         }
535 @@ -458,7 +458,7 @@
536                       case IPOPT_SEC:
537                       case IPOPT_SID:
538                       default:
539 -                       if (!skb && !capable(CAP_NET_RAW)) {
540 +                       if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
541                                 pp_ptr = optptr;
542                                 goto error;
543                         }
544 diff -Nurb linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c
545 --- linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c       2008-03-14 16:28:20.000000000 -0400
546 +++ linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c       2008-03-14 16:29:27.000000000 -0400
547 @@ -49,6 +49,8 @@
548         else
549                 logflags = NF_LOG_MASK;
550  
551 +       printk("TAG=%d ", skb->skb_tag);
552 +
553         ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
554         if (ih == NULL) {
555                 printk("TRUNCATED");
556 diff -Nurb linux-2.6.22-510/net/ipv4/raw.c linux-2.6.22-520/net/ipv4/raw.c
557 --- linux-2.6.22-510/net/ipv4/raw.c     2008-03-14 16:28:36.000000000 -0400
558 +++ linux-2.6.22-520/net/ipv4/raw.c     2008-03-14 16:29:27.000000000 -0400
559 @@ -103,7 +103,7 @@
560  
561  struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
562                              __be32 raddr, __be32 laddr,
563 -                            int dif)
564 +                            int dif, int tag)
565  {
566         struct hlist_node *node;
567  
568 @@ -112,6 +112,7 @@
569  
570                 if (inet->num == num                                    &&
571                     !(inet->daddr && inet->daddr != raddr)              &&
572 +                   (!sk->sk_nx_info || tag == 1 || sk->sk_nid == tag)  &&
573                     v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
574                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
575                         goto found; /* gotcha */
576 @@ -161,7 +162,7 @@
577                 goto out;
578         sk = __raw_v4_lookup(__sk_head(head), iph->protocol,
579                              iph->saddr, iph->daddr,
580 -                            skb->dev->ifindex);
581 +                            skb->dev->ifindex, skb->skb_tag);
582  
583         while (sk) {
584                 delivered = 1;
585 @@ -174,7 +175,7 @@
586                 }
587                 sk = __raw_v4_lookup(sk_next(sk), iph->protocol,
588                                      iph->saddr, iph->daddr,
589 -                                    skb->dev->ifindex);
590 +                                    skb->dev->ifindex, skb->skb_tag);
591         }
592  out:
593         read_unlock(&raw_v4_lock);
594 @@ -315,7 +316,7 @@
595         }
596  
597         err = -EPERM;
598 -       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
599 +       if (!nx_check(0, VS_ADMIN) && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET) &&
600                 sk->sk_nx_info &&
601                 !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
602                 goto error_free;
603 diff -Nurb linux-2.6.22-510/net/netfilter/Kconfig linux-2.6.22-520/net/netfilter/Kconfig
604 --- linux-2.6.22-510/net/netfilter/Kconfig      2007-07-08 19:32:17.000000000 -0400
605 +++ linux-2.6.22-520/net/netfilter/Kconfig      2008-03-14 16:29:27.000000000 -0400
606 @@ -389,6 +389,13 @@
607  
608           To compile it as a module, choose M here.  If unsure, say N.
609  
610 +config NETFILTER_XT_TARGET_SETXID
611 +       tristate '"SETXID" target support'
612 +       depends on NETFILTER_XTABLES
613 +       help
614 +         This option adds a `SETXID' target, which allows you to alter the
615 +         xid of a socket.
616 +
617  config NETFILTER_XT_MATCH_COMMENT
618         tristate  '"comment" match support'
619         depends on NETFILTER_XTABLES
620 diff -Nurb linux-2.6.22-510/net/netfilter/Makefile linux-2.6.22-520/net/netfilter/Makefile
621 --- linux-2.6.22-510/net/netfilter/Makefile     2007-07-08 19:32:17.000000000 -0400
622 +++ linux-2.6.22-520/net/netfilter/Makefile     2008-03-14 16:29:27.000000000 -0400
623 @@ -37,6 +37,7 @@
624  obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
625  
626  # targets
627 +obj-$(CONFIG_NETFILTER_XT_TARGET_SETXID) += xt_SETXID.o
628  obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o
629  obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
630  obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
631 diff -Nurb linux-2.6.22-510/net/netfilter/nf_conntrack_core.c linux-2.6.22-520/net/netfilter/nf_conntrack_core.c
632 --- linux-2.6.22-510/net/netfilter/nf_conntrack_core.c  2007-07-08 19:32:17.000000000 -0400
633 +++ linux-2.6.22-520/net/netfilter/nf_conntrack_core.c  2008-03-14 16:29:27.000000000 -0400
634 @@ -726,6 +726,8 @@
635  
636         /* Overload tuple linked list to put us in unconfirmed list. */
637         list_add(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list, &unconfirmed);
638 +       conntrack->xid[IP_CT_DIR_ORIGINAL] = -1;
639 +       conntrack->xid[IP_CT_DIR_REPLY] = -1;
640  
641         write_unlock_bh(&nf_conntrack_lock);
642  
643 diff -Nurb linux-2.6.22-510/net/netfilter/xt_MARK.c linux-2.6.22-520/net/netfilter/xt_MARK.c
644 --- linux-2.6.22-510/net/netfilter/xt_MARK.c    2007-07-08 19:32:17.000000000 -0400
645 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c    2008-03-14 16:29:27.000000000 -0400
646 @@ -5,13 +5,18 @@
647   * This program is free software; you can redistribute it and/or modify
648   * it under the terms of the GNU General Public License version 2 as
649   * published by the Free Software Foundation.
650 + *
651   */
652  
653  #include <linux/module.h>
654 +#include <linux/version.h>
655  #include <linux/skbuff.h>
656  #include <linux/ip.h>
657  #include <net/checksum.h>
658 +#include <net/route.h>
659 +#include <net/inet_hashtables.h>
660  
661 +#include <net/netfilter/nf_conntrack.h>
662  #include <linux/netfilter/x_tables.h>
663  #include <linux/netfilter/xt_MARK.h>
664  
665 @@ -21,6 +26,48 @@
666  MODULE_ALIAS("ipt_MARK");
667  MODULE_ALIAS("ip6t_MARK");
668  
669 +static inline u_int16_t
670 +get_dst_port(struct nf_conntrack_tuple *tuple)
671 +{
672 +       switch (tuple->dst.protonum) {
673 +       case IPPROTO_GRE:
674 +               /* XXX Truncate 32-bit GRE key to 16 bits */
675 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
676 +               return tuple->dst.u.gre.key;
677 +#else
678 +               return htons(ntohl(tuple->dst.u.gre.key));
679 +#endif  
680 +       case IPPROTO_ICMP:
681 +               /* Bind on ICMP echo ID */
682 +               return tuple->src.u.icmp.id;
683 +       case IPPROTO_TCP:
684 +               return tuple->dst.u.tcp.port;
685 +       case IPPROTO_UDP:
686 +               return tuple->dst.u.udp.port;
687 +       default:
688 +               return tuple->dst.u.all;
689 +       }
690 +}
691 +
692 +static inline u_int16_t
693 +get_src_port(struct nf_conntrack_tuple *tuple)
694 +{
695 +       switch (tuple->dst.protonum) {
696 +       case IPPROTO_GRE:
697 +               /* XXX Truncate 32-bit GRE key to 16 bits */
698 +               return htons(ntohl(tuple->src.u.gre.key));
699 +       case IPPROTO_ICMP:
700 +               /* Bind on ICMP echo ID */
701 +               return tuple->src.u.icmp.id;
702 +       case IPPROTO_TCP:
703 +               return tuple->src.u.tcp.port;
704 +       case IPPROTO_UDP:
705 +               return tuple->src.u.udp.port;
706 +       default:
707 +               return tuple->src.u.all;
708 +       }
709 +}
710 +
711  static unsigned int
712  target_v0(struct sk_buff **pskb,
713           const struct net_device *in,
714 @@ -44,7 +91,7 @@
715           const void *targinfo)
716  {
717         const struct xt_mark_target_info_v1 *markinfo = targinfo;
718 -       int mark = 0;
719 +       int mark = -1;
720  
721         switch (markinfo->mode) {
722         case XT_MARK_SET:
723 @@ -58,8 +105,58 @@
724         case XT_MARK_OR:
725                 mark = (*pskb)->mark | markinfo->mark;
726                 break;
727 +
728 +       case XT_MARK_COPYXID: {
729 +               enum ip_conntrack_info ctinfo;
730 +               struct sock *connection_sk;
731 +               int dif;
732 +
733 +               struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
734 +               extern struct inet_hashinfo tcp_hashinfo;
735 +               enum ip_conntrack_dir dir;
736 +               if (!ct) 
737 +                       break;
738 +
739 +               dir = CTINFO2DIR(ctinfo);
740 +               u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
741 +               u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
742 +               u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
743 +
744 +               u_int32_t ip;
745 +               u_int16_t port;
746 +
747 +               dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
748 +               ip = ct->tuplehash[dir].tuple.dst.u3.ip;
749 +               port = get_dst_port(&ct->tuplehash[dir].tuple);
750 +
751 +               if (proto == 1 || proto == 17) {
752 +                       if (((*pskb)->mark!=-1) && (*pskb)->mark)
753 +                               ct->xid[0]=(*pskb)->mark;
754 +                       if (ct->xid[0]) 
755 +                               mark = ct->xid[0];
756 +
757 +               }
758 +               else if (proto == 6) { 
759 +                               if ((*pskb)->sk) 
760 +                                       connection_sk = (*pskb)->sk;
761 +                               else {
762 +                                       connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
763 +                               }
764 +
765 +                               if (connection_sk) {
766 +                                       connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
767 +                                       ct->xid[!dir]=connection_sk->sk_xid;
768 +                                       if (connection_sk->sk_xid != 0) 
769 +                                               mark = connection_sk->sk_xid;
770 +                                       if (connection_sk != (*pskb)->sk)
771 +                                               sock_put(connection_sk);
772 +                               }
773 +                               break;
774 +                               }
775 +                             }
776         }
777  
778 +       if (mark != -1)
779         (*pskb)->mark = mark;
780         return XT_CONTINUE;
781  }
782 @@ -92,7 +189,8 @@
783  
784         if (markinfo->mode != XT_MARK_SET
785             && markinfo->mode != XT_MARK_AND
786 -           && markinfo->mode != XT_MARK_OR) {
787 +           && markinfo->mode != XT_MARK_OR
788 +           && markinfo->mode != XT_MARK_COPYXID) {
789                 printk(KERN_WARNING "MARK: unknown mode %u\n",
790                        markinfo->mode);
791                 return 0;
792 diff -Nurb linux-2.6.22-510/net/netfilter/xt_MARK.c.orig linux-2.6.22-520/net/netfilter/xt_MARK.c.orig
793 --- linux-2.6.22-510/net/netfilter/xt_MARK.c.orig       1969-12-31 19:00:00.000000000 -0500
794 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c.orig       2008-03-14 16:29:27.000000000 -0400
795 @@ -0,0 +1,284 @@
796 +/* This is a module which is used for setting the NFMARK field of an skb. */
797 +
798 +/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
799 + *
800 + * This program is free software; you can redistribute it and/or modify
801 + * it under the terms of the GNU General Public License version 2 as
802 + * published by the Free Software Foundation.
803 + *
804 + */
805 +
806 +#include <linux/module.h>
807 +#include <linux/version.h>
808 +#include <linux/skbuff.h>
809 +#include <linux/ip.h>
810 +#include <net/checksum.h>
811 +#include <net/route.h>
812 +#include <net/inet_hashtables.h>
813 +
814 +#include <net/netfilter/nf_conntrack.h>
815 +#include <linux/netfilter/x_tables.h>
816 +#include <linux/netfilter/xt_MARK.h>
817 +
818 +MODULE_LICENSE("GPL");
819 +MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
820 +MODULE_DESCRIPTION("ip[6]tables MARK modification module");
821 +MODULE_ALIAS("ipt_MARK");
822 +MODULE_ALIAS("ip6t_MARK");
823 +
824 +static inline u_int16_t
825 +get_dst_port(struct nf_conntrack_tuple *tuple)
826 +{
827 +       switch (tuple->dst.protonum) {
828 +       case IPPROTO_GRE:
829 +               /* XXX Truncate 32-bit GRE key to 16 bits */
830 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
831 +               return tuple->dst.u.gre.key;
832 +#else
833 +               return htons(ntohl(tuple->dst.u.gre.key));
834 +#endif  
835 +       case IPPROTO_ICMP:
836 +               /* Bind on ICMP echo ID */
837 +               return tuple->src.u.icmp.id;
838 +       case IPPROTO_TCP:
839 +               return tuple->dst.u.tcp.port;
840 +       case IPPROTO_UDP:
841 +               return tuple->dst.u.udp.port;
842 +       default:
843 +               return tuple->dst.u.all;
844 +       }
845 +}
846 +
847 +static inline u_int16_t
848 +get_src_port(struct nf_conntrack_tuple *tuple)
849 +{
850 +       switch (tuple->dst.protonum) {
851 +       case IPPROTO_GRE:
852 +               /* XXX Truncate 32-bit GRE key to 16 bits */
853 +               return htons(ntohl(tuple->src.u.gre.key));
854 +       case IPPROTO_ICMP:
855 +               /* Bind on ICMP echo ID */
856 +               return tuple->src.u.icmp.id;
857 +       case IPPROTO_TCP:
858 +               return tuple->src.u.tcp.port;
859 +       case IPPROTO_UDP:
860 +               return tuple->src.u.udp.port;
861 +       default:
862 +               return tuple->src.u.all;
863 +       }
864 +}
865 +
866 +static unsigned int
867 +target_v0(struct sk_buff **pskb,
868 +         const struct net_device *in,
869 +         const struct net_device *out,
870 +         unsigned int hooknum,
871 +         const struct xt_target *target,
872 +         const void *targinfo)
873 +{
874 +       const struct xt_mark_target_info *markinfo = targinfo;
875 +
876 +       (*pskb)->mark = markinfo->mark;
877 +       return XT_CONTINUE;
878 +}
879 +
880 +static unsigned int
881 +target_v1(struct sk_buff **pskb,
882 +         const struct net_device *in,
883 +         const struct net_device *out,
884 +         unsigned int hooknum,
885 +         const struct xt_target *target,
886 +         const void *targinfo)
887 +{
888 +       const struct xt_mark_target_info_v1 *markinfo = targinfo;
889 +       int mark = -1;
890 +
891 +       switch (markinfo->mode) {
892 +       case XT_MARK_SET:
893 +               mark = markinfo->mark;
894 +               break;
895 +
896 +       case XT_MARK_AND:
897 +               mark = (*pskb)->mark & markinfo->mark;
898 +               break;
899 +
900 +       case XT_MARK_OR:
901 +               mark = (*pskb)->mark | markinfo->mark;
902 +               break;
903 +
904 +       case XT_MARK_COPYXID: {
905 +               enum ip_conntrack_info ctinfo;
906 +               struct sock *connection_sk;
907 +               int dif;
908 +
909 +               struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
910 +               extern struct inet_hashinfo tcp_hashinfo;
911 +               enum ip_conntrack_dir dir;
912 +               if (!ct) 
913 +                       break;
914 +
915 +               dir = CTINFO2DIR(ctinfo);
916 +               u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
917 +               u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
918 +               u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
919 +
920 +               u_int32_t ip;
921 +               u_int16_t port;
922 +
923 +               dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
924 +               ip = ct->tuplehash[dir].tuple.dst.u3.ip;
925 +               port = get_dst_port(&ct->tuplehash[dir].tuple);
926 +
927 +               if (proto == 1) {
928 +                       if (((*pskb)->mark!=-1) && (*pskb)->mark)
929 +                               ct->xid[0]=(*pskb)->mark;
930 +                       if (ct->xid[0]) 
931 +                               mark = ct->xid[0];
932 +                       printk(KERN_CRIT "%d %d\n",ct->xid[0],(*pskb)->mark);
933 +
934 +               }
935 +               else if (proto == 6) {
936 +                               if ((*pskb)->sk) 
937 +                                       connection_sk = (*pskb)->sk;
938 +                               else {
939 +                                       connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
940 +                               }
941 +
942 +                               if (connection_sk) {
943 +                                       connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
944 +                                       ct->xid[!dir]=connection_sk->sk_xid;
945 +                                       if (connection_sk->sk_xid != 0) 
946 +                                               mark = connection_sk->sk_xid;
947 +                                       if (connection_sk != (*pskb)->sk)
948 +                                               sock_put(connection_sk);
949 +                               }
950 +                               break;
951 +                               }
952 +                             }
953 +       }
954 +
955 +       if (mark != -1)
956 +       (*pskb)->mark = mark;
957 +       return XT_CONTINUE;
958 +}
959 +
960 +
961 +static int
962 +checkentry_v0(const char *tablename,
963 +             const void *entry,
964 +             const struct xt_target *target,
965 +             void *targinfo,
966 +             unsigned int hook_mask)
967 +{
968 +       struct xt_mark_target_info *markinfo = targinfo;
969 +
970 +       if (markinfo->mark > 0xffffffff) {
971 +               printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
972 +               return 0;
973 +       }
974 +       return 1;
975 +}
976 +
977 +static int
978 +checkentry_v1(const char *tablename,
979 +             const void *entry,
980 +             const struct xt_target *target,
981 +             void *targinfo,
982 +             unsigned int hook_mask)
983 +{
984 +       struct xt_mark_target_info_v1 *markinfo = targinfo;
985 +
986 +       if (markinfo->mode != XT_MARK_SET
987 +           && markinfo->mode != XT_MARK_AND
988 +           && markinfo->mode != XT_MARK_OR
989 +           && markinfo->mode != XT_MARK_COPYXID) {
990 +               printk(KERN_WARNING "MARK: unknown mode %u\n",
991 +                      markinfo->mode);
992 +               return 0;
993 +       }
994 +       if (markinfo->mark > 0xffffffff) {
995 +               printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
996 +               return 0;
997 +       }
998 +       return 1;
999 +}
1000 +
1001 +#ifdef CONFIG_COMPAT
1002 +struct compat_xt_mark_target_info_v1 {
1003 +       compat_ulong_t  mark;
1004 +       u_int8_t        mode;
1005 +       u_int8_t        __pad1;
1006 +       u_int16_t       __pad2;
1007 +};
1008 +
1009 +static void compat_from_user_v1(void *dst, void *src)
1010 +{
1011 +       struct compat_xt_mark_target_info_v1 *cm = src;
1012 +       struct xt_mark_target_info_v1 m = {
1013 +               .mark   = cm->mark,
1014 +               .mode   = cm->mode,
1015 +       };
1016 +       memcpy(dst, &m, sizeof(m));
1017 +}
1018 +
1019 +static int compat_to_user_v1(void __user *dst, void *src)
1020 +{
1021 +       struct xt_mark_target_info_v1 *m = src;
1022 +       struct compat_xt_mark_target_info_v1 cm = {
1023 +               .mark   = m->mark,
1024 +               .mode   = m->mode,
1025 +       };
1026 +       return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
1027 +}
1028 +#endif /* CONFIG_COMPAT */
1029 +
1030 +static struct xt_target xt_mark_target[] = {
1031 +       {
1032 +               .name           = "MARK",
1033 +               .family         = AF_INET,
1034 +               .revision       = 0,
1035 +               .checkentry     = checkentry_v0,
1036 +               .target         = target_v0,
1037 +               .targetsize     = sizeof(struct xt_mark_target_info),
1038 +               .table          = "mangle",
1039 +               .me             = THIS_MODULE,
1040 +       },
1041 +       {
1042 +               .name           = "MARK",
1043 +               .family         = AF_INET,
1044 +               .revision       = 1,
1045 +               .checkentry     = checkentry_v1,
1046 +               .target         = target_v1,
1047 +               .targetsize     = sizeof(struct xt_mark_target_info_v1),
1048 +#ifdef CONFIG_COMPAT
1049 +               .compatsize     = sizeof(struct compat_xt_mark_target_info_v1),
1050 +               .compat_from_user = compat_from_user_v1,
1051 +               .compat_to_user = compat_to_user_v1,
1052 +#endif
1053 +               .table          = "mangle",
1054 +               .me             = THIS_MODULE,
1055 +       },
1056 +       {
1057 +               .name           = "MARK",
1058 +               .family         = AF_INET6,
1059 +               .revision       = 0,
1060 +               .checkentry     = checkentry_v0,
1061 +               .target         = target_v0,
1062 +               .targetsize     = sizeof(struct xt_mark_target_info),
1063 +               .table          = "mangle",
1064 +               .me             = THIS_MODULE,
1065 +       },
1066 +};
1067 +
1068 +static int __init xt_mark_init(void)
1069 +{
1070 +       return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
1071 +}
1072 +
1073 +static void __exit xt_mark_fini(void)
1074 +{
1075 +       xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
1076 +}
1077 +
1078 +module_init(xt_mark_init);
1079 +module_exit(xt_mark_fini);
1080 diff -Nurb linux-2.6.22-510/net/netfilter/xt_SETXID.c linux-2.6.22-520/net/netfilter/xt_SETXID.c
1081 --- linux-2.6.22-510/net/netfilter/xt_SETXID.c  1969-12-31 19:00:00.000000000 -0500
1082 +++ linux-2.6.22-520/net/netfilter/xt_SETXID.c  2008-03-14 16:29:27.000000000 -0400
1083 @@ -0,0 +1,79 @@
1084 +#include <linux/module.h>
1085 +#include <linux/skbuff.h>
1086 +#include <linux/ip.h>
1087 +#include <net/checksum.h>
1088 +#include <linux/vs_network.h>
1089 +
1090 +#include <linux/netfilter/x_tables.h>
1091 +#include <linux/netfilter/xt_SETXID.h>
1092 +
1093 +MODULE_LICENSE("GPL");
1094 +MODULE_AUTHOR("");
1095 +MODULE_DESCRIPTION("");
1096 +MODULE_ALIAS("ipt_SETXID");
1097 +
1098 +static unsigned int
1099 +target_v1(struct sk_buff **pskb,
1100 +         const struct net_device *in,
1101 +         const struct net_device *out,
1102 +         unsigned int hooknum,
1103 +         const struct xt_target *target,
1104 +         const void *targinfo)
1105 +{
1106 +       const struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
1107 +
1108 +       switch (setxidinfo->mode) {
1109 +       case XT_SET_PACKET_XID:
1110 +                (*pskb)->skb_tag = setxidinfo->mark;
1111 +               break;
1112 +       }
1113 +       return XT_CONTINUE;
1114 +}
1115 +
1116 +
1117 +static int
1118 +checkentry_v1(const char *tablename,
1119 +             const void *entry,
1120 +             const struct xt_target *target,
1121 +             void *targinfo,
1122 +             unsigned int hook_mask)
1123 +{
1124 +       struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
1125 +
1126 +       if (setxidinfo->mode != XT_SET_PACKET_XID) {
1127 +               printk(KERN_WARNING "SETXID: unknown mode %u\n",
1128 +                      setxidinfo->mode);
1129 +               return 0;
1130 +       }
1131 +
1132 +       return 1;
1133 +}
1134 +
1135 +static struct xt_target xt_setxid_target[] = {
1136 +       {
1137 +               .name           = "SETXID",
1138 +               .family         = AF_INET,
1139 +               .revision       = 1,
1140 +               .checkentry     = checkentry_v1,
1141 +               .target         = target_v1,
1142 +               .targetsize     = sizeof(struct xt_setxid_target_info_v1),
1143 +               .table          = "mangle",
1144 +               .me             = THIS_MODULE,
1145 +       }
1146 +};
1147 +
1148 +static int __init init(void)
1149 +{
1150 +       int err;
1151 +
1152 +       err = xt_register_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
1153 +       return err;
1154 +}
1155 +
1156 +static void __exit fini(void)
1157 +{
1158 +       xt_unregister_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
1159 +}
1160 +
1161 +module_init(init);
1162 +module_exit(fini);
1163 diff -Nurb linux-2.6.22-510/net/packet/af_packet.c linux-2.6.22-520/net/packet/af_packet.c
1164 --- linux-2.6.22-510/net/packet/af_packet.c     2007-07-08 19:32:17.000000000 -0400
1165 +++ linux-2.6.22-520/net/packet/af_packet.c     2008-03-14 16:29:27.000000000 -0400
1166 @@ -78,6 +78,7 @@
1167  #include <linux/poll.h>
1168  #include <linux/module.h>
1169  #include <linux/init.h>
1170 +#include <linux/vs_network.h>
1171  
1172  #ifdef CONFIG_INET
1173  #include <net/inet_common.h>
1174 @@ -324,6 +325,9 @@
1175         __be16 proto=0;
1176         int err;
1177  
1178 +       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
1179 +               return -EPERM;
1180 +
1181         /*
1182          *      Get and verify the address.
1183          */
1184 @@ -420,6 +424,10 @@
1185                                       unsigned int res)
1186  {
1187         struct sk_filter *filter;
1188 +       int tag = skb->skb_tag;
1189 +
1190 +       if (sk->sk_nx_info && !(tag == 1 || sk->sk_nid == tag))
1191 +               return 0;
1192  
1193         rcu_read_lock_bh();
1194         filter = rcu_dereference(sk->sk_filter);
1195 @@ -711,6 +719,9 @@
1196         unsigned char *addr;
1197         int ifindex, err, reserve = 0;
1198  
1199 +       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
1200 +               return -EPERM;
1201 +
1202         /*
1203          *      Get and verify the address.
1204          */
1205 @@ -984,7 +995,7 @@
1206         __be16 proto = (__force __be16)protocol; /* weird, but documented */
1207         int err;
1208  
1209 -       if (!capable(CAP_NET_RAW))
1210 +       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET))
1211                 return -EPERM;
1212         if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
1213             sock->type != SOCK_PACKET)