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
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
16 +#ifndef _XT_SETXID_H_target
17 +#define _XT_SETXID_H_target
24 +struct xt_setxid_target_info_v1 {
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
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
39 #define ipt_mark_target_info_v1 xt_mark_target_info_v1
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
45 +#ifndef _IPT_SETXID_H_target
46 +#define _IPT_SETXID_H_target
48 +/* Backwards compatibility for old userspace */
50 +#include <linux/netfilter/xt_SETXID.h>
53 +#define IPT_SET_PACKET_XID XT_SET_PACKET_XID
55 +#define ipt_setxid_target_info_v1 xt_setxid_target_info_v1
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
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
76 +#define SO_SETXID SO_PEERCRED
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
87 #define NXC_RAW_ICMP 0x00000100
88 +#define NXC_RAW_SOCKET 0x00000200
89 +#define NXC_RAW_SEND 0x00000400
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
97 +#ifndef _VX_NETWORK_H
98 +#define _VX_NETWORK_H
100 +#include <linux/types.h>
103 +#define MAX_N_CONTEXT 65535 /* Arbitrary limit */
108 +#define NXF_INFO_PRIVATE 0x00000008
110 +#define NXF_SINGLE_IP 0x00000100
111 +#define NXF_LBACK_REMAP 0x00000200
113 +#define NXF_HIDE_NETIF 0x02000000
114 +#define NXF_HIDE_LBACK 0x04000000
116 +#define NXF_STATE_SETUP (1ULL << 32)
117 +#define NXF_STATE_ADMIN (1ULL << 34)
119 +#define NXF_SC_HELPER (1ULL << 36)
120 +#define NXF_PERSISTENT (1ULL << 38)
122 +#define NXF_ONE_TIME (0x0005ULL << 32)
125 +#define NXF_INIT_SET (__nxf_init_set())
127 +static inline uint64_t __nxf_init_set(void) {
128 + return NXF_STATE_ADMIN
129 +#ifdef CONFIG_VSERVER_AUTO_LBACK
133 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
142 +#define NXC_RAW_ICMP 0x00000100
147 +#define NXA_TYPE_IPV4 0x0001
148 +#define NXA_TYPE_IPV6 0x0002
150 +#define NXA_TYPE_NONE 0x0000
151 +#define NXA_TYPE_ANY 0x00FF
153 +#define NXA_TYPE_ADDR 0x0010
154 +#define NXA_TYPE_MASK 0x0020
155 +#define NXA_TYPE_RANGE 0x0040
157 +#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
159 +#define NXA_MOD_BCAST 0x0100
160 +#define NXA_MOD_LBACK 0x0200
162 +#define NXA_LOOPBACK 0x1000
164 +#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
165 +#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
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>
177 + struct nx_addr_v4 *next;
178 + struct in_addr ip[2];
179 + struct in_addr mask;
185 + struct nx_addr_v6 *next;
186 + struct in6_addr ip;
187 + struct in6_addr mask;
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 */
200 + uint64_t nx_flags; /* network flag word */
201 + uint64_t nx_ncaps; /* network capabilities */
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 */
207 + struct nx_addr_v6 v6; /* First/Single ipv6 address */
209 + char nx_name[65]; /* network context name */
215 +#define NXS_HASHED 0x0001
216 +#define NXS_SHUTDOWN 0x0100
217 +#define NXS_RELEASED 0x8000
219 +extern struct nx_info *lookup_nx_info(int);
221 +extern int get_nid_list(int, unsigned int *, int);
222 +extern int nid_is_hashed(nid_t);
224 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
226 +extern long vs_net_change(struct nx_info *, unsigned int);
231 +#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
233 +#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
235 +#define NX_IPV6(n) (0)
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
244 +#ifndef _VX_NETWORK_H
245 +#define _VX_NETWORK_H
247 +#include <linux/types.h>
250 +#define MAX_N_CONTEXT 65535 /* Arbitrary limit */
255 +#define NXF_INFO_PRIVATE 0x00000008
257 +#define NXF_SINGLE_IP 0x00000100
258 +#define NXF_LBACK_REMAP 0x00000200
260 +#define NXF_HIDE_NETIF 0x02000000
261 +#define NXF_HIDE_LBACK 0x04000000
263 +#define NXF_STATE_SETUP (1ULL << 32)
264 +#define NXF_STATE_ADMIN (1ULL << 34)
266 +#define NXF_SC_HELPER (1ULL << 36)
267 +#define NXF_PERSISTENT (1ULL << 38)
269 +#define NXF_ONE_TIME (0x0005ULL << 32)
272 +#define NXF_INIT_SET (__nxf_init_set())
274 +static inline uint64_t __nxf_init_set(void) {
275 + return NXF_STATE_ADMIN
276 +#ifdef CONFIG_VSERVER_AUTO_LBACK
280 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
289 +#define NXC_RAW_ICMP 0x00000100
294 +#define NXA_TYPE_IPV4 0x0001
295 +#define NXA_TYPE_IPV6 0x0002
297 +#define NXA_TYPE_NONE 0x0000
298 +#define NXA_TYPE_ANY 0x00FF
300 +#define NXA_TYPE_ADDR 0x0010
301 +#define NXA_TYPE_MASK 0x0020
302 +#define NXA_TYPE_RANGE 0x0040
304 +#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
306 +#define NXA_MOD_BCAST 0x0100
307 +#define NXA_MOD_LBACK 0x0200
309 +#define NXA_LOOPBACK 0x1000
311 +#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
312 +#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
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>
324 + struct nx_addr_v4 *next;
325 + struct in_addr ip[2];
326 + struct in_addr mask;
332 + struct nx_addr_v6 *next;
333 + struct in6_addr ip;
334 + struct in6_addr mask;
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 */
347 + uint64_t nx_flags; /* network flag word */
348 + uint64_t nx_ncaps; /* network capabilities */
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 */
354 + struct nx_addr_v6 v6; /* First/Single ipv6 address */
356 + char nx_name[65]; /* network context name */
362 +#define NXS_HASHED 0x0001
363 +#define NXS_SHUTDOWN 0x0100
364 +#define NXS_RELEASED 0x8000
366 +extern struct nx_info *lookup_nx_info(int);
368 +extern int get_nid_list(int, unsigned int *, int);
369 +extern int nid_is_hashed(nid_t);
371 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
373 +extern long vs_net_change(struct nx_info *, unsigned int);
378 +#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
380 +#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
382 +#define NX_IPV6(n) (0)
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
391 /* Storage reserved for other modules: */
392 union nf_conntrack_proto proto;
394 + /* PLANETLAB. VNET-specific */
395 + xid_t xid[IP_CT_DIR_MAX];
397 /* features dynamically at the end: helper, nat (both optional) */
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
405 extern struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
406 __be32 raddr, __be32 laddr,
410 extern int raw_v4_input(struct sk_buff *skb, struct iphdr *iph, int hash);
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
416 #include <linux/rtnetlink.h>
417 #include <linux/init.h>
418 #include <linux/scatterlist.h>
419 +#include <linux/vs_network.h>
421 #include <net/protocol.h>
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);
435 + /* Sapan: Cloned skbs aren't owned by anyone. Let the cloner decide who it belongs to. */
437 atomic_inc(&(skb_shinfo(skb)->dataref));
441 new->tc_index = old->tc_index;
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
456 + if (current_vx_info()) {
460 + if (val < 0 || val > MAX_S_CONTEXT) {
469 /* Don't error on this BSD doesn't and if you think
470 about it this is right. Otherwise apps have to
472 char devname[IFNAMSIZ];
475 - if (!capable(CAP_NET_RAW)) {
476 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
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
486 inet->sport = htons(inet->num);
487 + sk->sk_xid = vx_current_xid();
488 + sk->sk_nid = nx_current_nid();
493 if ((protocol == IPPROTO_ICMP) &&
494 nx_capable(answer->capability, NXC_RAW_ICMP))
496 + if (sock->type == SOCK_RAW &&
497 + nx_capable(answer->capability, NXC_RAW_SOCKET))
499 if (answer->capability > 0 && !capable(answer->capability))
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
506 if ((raw_sk = sk_head(&raw_v4_htable[hash])) != NULL) {
507 while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr,
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
521 - if (!skb && !capable(CAP_NET_RAW)) {
522 + if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
527 opt->router_alert = optptr - iph;
530 - if ((!skb && !capable(CAP_NET_RAW)) || opt->cipso) {
531 + if ((!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) || opt->cipso) {
539 - if (!skb && !capable(CAP_NET_RAW)) {
540 + if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
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
549 logflags = NF_LOG_MASK;
551 + printk("TAG=%d ", skb->skb_tag);
553 ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
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
561 struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
562 __be32 raddr, __be32 laddr,
566 struct hlist_node *node;
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 */
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);
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);
593 read_unlock(&raw_v4_lock);
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) &&
601 !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
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
608 To compile it as a module, choose M here. If unsure, say N.
610 +config NETFILTER_XT_TARGET_SETXID
611 + tristate '"SETXID" target support'
612 + depends on NETFILTER_XTABLES
614 + This option adds a `SETXID' target, which allows you to alter the
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
624 obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
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
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;
641 write_unlock_bh(&nf_conntrack_lock);
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
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.
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>
661 +#include <net/netfilter/nf_conntrack.h>
662 #include <linux/netfilter/x_tables.h>
663 #include <linux/netfilter/xt_MARK.h>
666 MODULE_ALIAS("ipt_MARK");
667 MODULE_ALIAS("ip6t_MARK");
669 +static inline u_int16_t
670 +get_dst_port(struct nf_conntrack_tuple *tuple)
672 + switch (tuple->dst.protonum) {
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;
678 + return htons(ntohl(tuple->dst.u.gre.key));
681 + /* Bind on ICMP echo ID */
682 + return tuple->src.u.icmp.id;
684 + return tuple->dst.u.tcp.port;
686 + return tuple->dst.u.udp.port;
688 + return tuple->dst.u.all;
692 +static inline u_int16_t
693 +get_src_port(struct nf_conntrack_tuple *tuple)
695 + switch (tuple->dst.protonum) {
697 + /* XXX Truncate 32-bit GRE key to 16 bits */
698 + return htons(ntohl(tuple->src.u.gre.key));
700 + /* Bind on ICMP echo ID */
701 + return tuple->src.u.icmp.id;
703 + return tuple->src.u.tcp.port;
705 + return tuple->src.u.udp.port;
707 + return tuple->src.u.all;
712 target_v0(struct sk_buff **pskb,
713 const struct net_device *in,
715 const void *targinfo)
717 const struct xt_mark_target_info_v1 *markinfo = targinfo;
721 switch (markinfo->mode) {
725 mark = (*pskb)->mark | markinfo->mark;
728 + case XT_MARK_COPYXID: {
729 + enum ip_conntrack_info ctinfo;
730 + struct sock *connection_sk;
733 + struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
734 + extern struct inet_hashinfo tcp_hashinfo;
735 + enum ip_conntrack_dir dir;
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;
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);
751 + if (proto == 1 || proto == 17) {
752 + if (((*pskb)->mark!=-1) && (*pskb)->mark)
753 + ct->xid[0]=(*pskb)->mark;
758 + else if (proto == 6) {
760 + connection_sk = (*pskb)->sk;
762 + connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
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);
779 (*pskb)->mark = mark;
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",
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
796 +/* This is a module which is used for setting the NFMARK field of an skb. */
798 +/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
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.
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>
814 +#include <net/netfilter/nf_conntrack.h>
815 +#include <linux/netfilter/x_tables.h>
816 +#include <linux/netfilter/xt_MARK.h>
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");
824 +static inline u_int16_t
825 +get_dst_port(struct nf_conntrack_tuple *tuple)
827 + switch (tuple->dst.protonum) {
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;
833 + return htons(ntohl(tuple->dst.u.gre.key));
836 + /* Bind on ICMP echo ID */
837 + return tuple->src.u.icmp.id;
839 + return tuple->dst.u.tcp.port;
841 + return tuple->dst.u.udp.port;
843 + return tuple->dst.u.all;
847 +static inline u_int16_t
848 +get_src_port(struct nf_conntrack_tuple *tuple)
850 + switch (tuple->dst.protonum) {
852 + /* XXX Truncate 32-bit GRE key to 16 bits */
853 + return htons(ntohl(tuple->src.u.gre.key));
855 + /* Bind on ICMP echo ID */
856 + return tuple->src.u.icmp.id;
858 + return tuple->src.u.tcp.port;
860 + return tuple->src.u.udp.port;
862 + return tuple->src.u.all;
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)
874 + const struct xt_mark_target_info *markinfo = targinfo;
876 + (*pskb)->mark = markinfo->mark;
877 + return XT_CONTINUE;
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)
888 + const struct xt_mark_target_info_v1 *markinfo = targinfo;
891 + switch (markinfo->mode) {
893 + mark = markinfo->mark;
897 + mark = (*pskb)->mark & markinfo->mark;
901 + mark = (*pskb)->mark | markinfo->mark;
904 + case XT_MARK_COPYXID: {
905 + enum ip_conntrack_info ctinfo;
906 + struct sock *connection_sk;
909 + struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
910 + extern struct inet_hashinfo tcp_hashinfo;
911 + enum ip_conntrack_dir dir;
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;
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);
928 + if (((*pskb)->mark!=-1) && (*pskb)->mark)
929 + ct->xid[0]=(*pskb)->mark;
932 + printk(KERN_CRIT "%d %d\n",ct->xid[0],(*pskb)->mark);
935 + else if (proto == 6) {
937 + connection_sk = (*pskb)->sk;
939 + connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
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);
956 + (*pskb)->mark = mark;
957 + return XT_CONTINUE;
962 +checkentry_v0(const char *tablename,
964 + const struct xt_target *target,
966 + unsigned int hook_mask)
968 + struct xt_mark_target_info *markinfo = targinfo;
970 + if (markinfo->mark > 0xffffffff) {
971 + printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
978 +checkentry_v1(const char *tablename,
980 + const struct xt_target *target,
982 + unsigned int hook_mask)
984 + struct xt_mark_target_info_v1 *markinfo = targinfo;
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",
994 + if (markinfo->mark > 0xffffffff) {
995 + printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
1001 +#ifdef CONFIG_COMPAT
1002 +struct compat_xt_mark_target_info_v1 {
1003 + compat_ulong_t mark;
1009 +static void compat_from_user_v1(void *dst, void *src)
1011 + struct compat_xt_mark_target_info_v1 *cm = src;
1012 + struct xt_mark_target_info_v1 m = {
1016 + memcpy(dst, &m, sizeof(m));
1019 +static int compat_to_user_v1(void __user *dst, void *src)
1021 + struct xt_mark_target_info_v1 *m = src;
1022 + struct compat_xt_mark_target_info_v1 cm = {
1026 + return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
1028 +#endif /* CONFIG_COMPAT */
1030 +static struct xt_target xt_mark_target[] = {
1033 + .family = AF_INET,
1035 + .checkentry = checkentry_v0,
1036 + .target = target_v0,
1037 + .targetsize = sizeof(struct xt_mark_target_info),
1038 + .table = "mangle",
1039 + .me = THIS_MODULE,
1043 + .family = AF_INET,
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,
1053 + .table = "mangle",
1054 + .me = THIS_MODULE,
1058 + .family = AF_INET6,
1060 + .checkentry = checkentry_v0,
1061 + .target = target_v0,
1062 + .targetsize = sizeof(struct xt_mark_target_info),
1063 + .table = "mangle",
1064 + .me = THIS_MODULE,
1068 +static int __init xt_mark_init(void)
1070 + return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
1073 +static void __exit xt_mark_fini(void)
1075 + xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
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
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>
1090 +#include <linux/netfilter/x_tables.h>
1091 +#include <linux/netfilter/xt_SETXID.h>
1093 +MODULE_LICENSE("GPL");
1095 +MODULE_DESCRIPTION("");
1096 +MODULE_ALIAS("ipt_SETXID");
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)
1106 + const struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
1108 + switch (setxidinfo->mode) {
1109 + case XT_SET_PACKET_XID:
1110 + (*pskb)->skb_tag = setxidinfo->mark;
1113 + return XT_CONTINUE;
1118 +checkentry_v1(const char *tablename,
1119 + const void *entry,
1120 + const struct xt_target *target,
1122 + unsigned int hook_mask)
1124 + struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
1126 + if (setxidinfo->mode != XT_SET_PACKET_XID) {
1127 + printk(KERN_WARNING "SETXID: unknown mode %u\n",
1128 + setxidinfo->mode);
1135 +static struct xt_target xt_setxid_target[] = {
1138 + .family = AF_INET,
1140 + .checkentry = checkentry_v1,
1141 + .target = target_v1,
1142 + .targetsize = sizeof(struct xt_setxid_target_info_v1),
1143 + .table = "mangle",
1144 + .me = THIS_MODULE,
1148 +static int __init init(void)
1152 + err = xt_register_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
1156 +static void __exit fini(void)
1158 + xt_unregister_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
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
1167 #include <linux/poll.h>
1168 #include <linux/module.h>
1169 #include <linux/init.h>
1170 +#include <linux/vs_network.h>
1173 #include <net/inet_common.h>
1178 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
1182 * Get and verify the address.
1184 @@ -420,6 +424,10 @@
1187 struct sk_filter *filter;
1188 + int tag = skb->skb_tag;
1190 + if (sk->sk_nx_info && !(tag == 1 || sk->sk_nid == tag))
1194 filter = rcu_dereference(sk->sk_filter);
1196 unsigned char *addr;
1197 int ifindex, err, reserve = 0;
1199 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
1203 * Get and verify the address.
1206 __be16 proto = (__force __be16)protocol; /* weird, but documented */
1209 - if (!capable(CAP_NET_RAW))
1210 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET))
1212 if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
1213 sock->type != SOCK_PACKET)