1 diff -Nurb linux-2.6.22-510/include/linux/netfilter/xt_MARK.h linux-2.6.22-520/include/linux/netfilter/xt_MARK.h
2 --- linux-2.6.22-510/include/linux/netfilter/xt_MARK.h 2007-07-08 19:32:17.000000000 -0400
3 +++ linux-2.6.22-520/include/linux/netfilter/xt_MARK.h 2008-03-20 01:27:27.000000000 -0400
11 struct xt_mark_target_info_v1 {
12 diff -Nurb linux-2.6.22-510/include/linux/netfilter/xt_SETXID.h linux-2.6.22-520/include/linux/netfilter/xt_SETXID.h
13 --- linux-2.6.22-510/include/linux/netfilter/xt_SETXID.h 1969-12-31 19:00:00.000000000 -0500
14 +++ linux-2.6.22-520/include/linux/netfilter/xt_SETXID.h 2008-03-20 01:27:27.000000000 -0400
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-20 01:27:27.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-20 01:27:27.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-20 01:27:27.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-20 01:27:27.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-20 01:27:21.000000000 -0400
83 +++ linux-2.6.22-520/include/linux/vserver/network.h 2008-03-20 01:27:27.000000000 -0400
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.orig linux-2.6.22-520/include/linux/vserver/network.h.orig.orig
94 --- linux-2.6.22-510/include/linux/vserver/network.h.orig.orig 1969-12-31 19:00:00.000000000 -0500
95 +++ linux-2.6.22-520/include/linux/vserver/network.h.orig.orig 2008-03-20 01:27: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/net/netfilter/nf_conntrack.h linux-2.6.22-520/include/net/netfilter/nf_conntrack.h
241 --- linux-2.6.22-510/include/net/netfilter/nf_conntrack.h 2007-07-08 19:32:17.000000000 -0400
242 +++ linux-2.6.22-520/include/net/netfilter/nf_conntrack.h 2008-03-20 01:27:27.000000000 -0400
244 /* Storage reserved for other modules: */
245 union nf_conntrack_proto proto;
247 + /* PLANETLAB. VNET-specific */
248 + xid_t xid[IP_CT_DIR_MAX];
250 /* features dynamically at the end: helper, nat (both optional) */
253 diff -Nurb linux-2.6.22-510/include/net/raw.h linux-2.6.22-520/include/net/raw.h
254 --- linux-2.6.22-510/include/net/raw.h 2007-07-08 19:32:17.000000000 -0400
255 +++ linux-2.6.22-520/include/net/raw.h 2008-03-20 01:27:27.000000000 -0400
258 extern struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
259 __be32 raddr, __be32 laddr,
263 extern int raw_v4_input(struct sk_buff *skb, struct iphdr *iph, int hash);
265 diff -Nurb linux-2.6.22-510/net/core/skbuff.c linux-2.6.22-520/net/core/skbuff.c
266 --- linux-2.6.22-510/net/core/skbuff.c 2007-07-08 19:32:17.000000000 -0400
267 +++ linux-2.6.22-520/net/core/skbuff.c 2008-03-20 01:27:27.000000000 -0400
269 #include <linux/rtnetlink.h>
270 #include <linux/init.h>
271 #include <linux/scatterlist.h>
272 +#include <linux/vs_network.h>
274 #include <net/protocol.h>
278 skb_reset_tail_pointer(skb);
279 skb->end = skb->tail + size;
280 + skb->skb_tag = nx_current_nid();
281 /* make sure we initialize shinfo sequentially */
282 shinfo = skb_shinfo(skb);
283 atomic_set(&shinfo->dataref, 1);
288 + /* Sapan: Cloned skbs aren't owned by anyone. Let the cloner decide who it belongs to. */
290 atomic_inc(&(skb_shinfo(skb)->dataref));
294 new->tc_index = old->tc_index;
296 skb_copy_secmark(new, old);
297 + new->skb_tag = old->skb_tag;
298 atomic_set(&new->users, 1);
299 skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
300 skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
301 diff -Nurb linux-2.6.22-510/net/core/sock.c linux-2.6.22-520/net/core/sock.c
302 --- linux-2.6.22-510/net/core/sock.c 2008-03-20 01:27:22.000000000 -0400
303 +++ linux-2.6.22-520/net/core/sock.c 2008-03-20 01:27:27.000000000 -0400
309 + if (current_vx_info()) {
313 + if (val < 0 || val > MAX_S_CONTEXT) {
322 /* Don't error on this BSD doesn't and if you think
323 about it this is right. Otherwise apps have to
325 char devname[IFNAMSIZ];
328 - if (!capable(CAP_NET_RAW)) {
329 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
333 diff -Nurb linux-2.6.22-510/net/ipv4/af_inet.c linux-2.6.22-520/net/ipv4/af_inet.c
334 --- linux-2.6.22-510/net/ipv4/af_inet.c 2008-03-20 01:27:22.000000000 -0400
335 +++ linux-2.6.22-520/net/ipv4/af_inet.c 2008-03-20 01:27:27.000000000 -0400
339 inet->sport = htons(inet->num);
340 + sk->sk_xid = vx_current_xid();
341 + sk->sk_nid = nx_current_nid();
346 if ((protocol == IPPROTO_ICMP) &&
347 nx_capable(answer->capability, NXC_RAW_ICMP))
349 + if (sock->type == SOCK_RAW &&
350 + nx_capable(answer->capability, NXC_RAW_SOCKET))
352 if (answer->capability > 0 && !capable(answer->capability))
355 diff -Nurb linux-2.6.22-510/net/ipv4/icmp.c linux-2.6.22-520/net/ipv4/icmp.c
356 --- linux-2.6.22-510/net/ipv4/icmp.c 2008-03-20 01:27:26.000000000 -0400
357 +++ linux-2.6.22-520/net/ipv4/icmp.c 2008-03-20 01:27:27.000000000 -0400
359 if ((raw_sk = sk_head(&raw_v4_htable[hash])) != NULL) {
360 while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr,
362 - skb->dev->ifindex)) != NULL) {
363 + skb->dev->ifindex, skb->skb_tag)) != NULL) {
364 raw_err(raw_sk, skb, info);
365 raw_sk = sk_next(raw_sk);
366 iph = (struct iphdr *)skb->data;
367 diff -Nurb linux-2.6.22-510/net/ipv4/ip_options.c linux-2.6.22-520/net/ipv4/ip_options.c
368 --- linux-2.6.22-510/net/ipv4/ip_options.c 2007-07-08 19:32:17.000000000 -0400
369 +++ linux-2.6.22-520/net/ipv4/ip_options.c 2008-03-20 01:27:27.000000000 -0400
374 - if (!skb && !capable(CAP_NET_RAW)) {
375 + if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
380 opt->router_alert = optptr - iph;
383 - if ((!skb && !capable(CAP_NET_RAW)) || opt->cipso) {
384 + if ((!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) || opt->cipso) {
392 - if (!skb && !capable(CAP_NET_RAW)) {
393 + if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
397 diff -Nurb linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c
398 --- linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c 2008-03-20 01:27:10.000000000 -0400
399 +++ linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c 2008-03-20 01:27:27.000000000 -0400
402 logflags = NF_LOG_MASK;
404 + printk("TAG=%d ", skb->skb_tag);
406 ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
409 diff -Nurb linux-2.6.22-510/net/ipv4/raw.c linux-2.6.22-520/net/ipv4/raw.c
410 --- linux-2.6.22-510/net/ipv4/raw.c 2008-03-20 01:27:22.000000000 -0400
411 +++ linux-2.6.22-520/net/ipv4/raw.c 2008-03-20 01:27:27.000000000 -0400
414 struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
415 __be32 raddr, __be32 laddr,
419 struct hlist_node *node;
423 if (inet->num == num &&
424 !(inet->daddr && inet->daddr != raddr) &&
425 + (!sk->sk_nx_info || tag == 1 || sk->sk_nid == tag) &&
426 v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
427 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
428 goto found; /* gotcha */
431 sk = __raw_v4_lookup(__sk_head(head), iph->protocol,
432 iph->saddr, iph->daddr,
433 - skb->dev->ifindex);
434 + skb->dev->ifindex, skb->skb_tag);
440 sk = __raw_v4_lookup(sk_next(sk), iph->protocol,
441 iph->saddr, iph->daddr,
442 - skb->dev->ifindex);
443 + skb->dev->ifindex, skb->skb_tag);
446 read_unlock(&raw_v4_lock);
451 - if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
452 + if (!nx_check(0, VS_ADMIN) && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET) &&
454 !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
456 diff -Nurb linux-2.6.22-510/net/netfilter/Kconfig linux-2.6.22-520/net/netfilter/Kconfig
457 --- linux-2.6.22-510/net/netfilter/Kconfig 2007-07-08 19:32:17.000000000 -0400
458 +++ linux-2.6.22-520/net/netfilter/Kconfig 2008-03-20 01:27:27.000000000 -0400
461 To compile it as a module, choose M here. If unsure, say N.
463 +config NETFILTER_XT_TARGET_SETXID
464 + tristate '"SETXID" target support'
465 + depends on NETFILTER_XTABLES
467 + This option adds a `SETXID' target, which allows you to alter the
470 config NETFILTER_XT_MATCH_COMMENT
471 tristate '"comment" match support'
472 depends on NETFILTER_XTABLES
473 diff -Nurb linux-2.6.22-510/net/netfilter/Makefile linux-2.6.22-520/net/netfilter/Makefile
474 --- linux-2.6.22-510/net/netfilter/Makefile 2007-07-08 19:32:17.000000000 -0400
475 +++ linux-2.6.22-520/net/netfilter/Makefile 2008-03-20 01:27:27.000000000 -0400
477 obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
480 +obj-$(CONFIG_NETFILTER_XT_TARGET_SETXID) += xt_SETXID.o
481 obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o
482 obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
483 obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
484 diff -Nurb linux-2.6.22-510/net/netfilter/nf_conntrack_core.c linux-2.6.22-520/net/netfilter/nf_conntrack_core.c
485 --- linux-2.6.22-510/net/netfilter/nf_conntrack_core.c 2007-07-08 19:32:17.000000000 -0400
486 +++ linux-2.6.22-520/net/netfilter/nf_conntrack_core.c 2008-03-20 01:27:27.000000000 -0400
489 /* Overload tuple linked list to put us in unconfirmed list. */
490 list_add(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list, &unconfirmed);
491 + conntrack->xid[IP_CT_DIR_ORIGINAL] = -1;
492 + conntrack->xid[IP_CT_DIR_REPLY] = -1;
494 write_unlock_bh(&nf_conntrack_lock);
496 diff -Nurb linux-2.6.22-510/net/netfilter/xt_MARK.c linux-2.6.22-520/net/netfilter/xt_MARK.c
497 --- linux-2.6.22-510/net/netfilter/xt_MARK.c 2007-07-08 19:32:17.000000000 -0400
498 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c 2008-03-20 01:30:14.000000000 -0400
500 * This program is free software; you can redistribute it and/or modify
501 * it under the terms of the GNU General Public License version 2 as
502 * published by the Free Software Foundation.
506 #include <linux/module.h>
507 +#include <linux/version.h>
508 #include <linux/skbuff.h>
509 #include <linux/ip.h>
510 #include <net/checksum.h>
511 +#include <net/route.h>
512 +#include <net/inet_hashtables.h>
514 +#include <net/netfilter/nf_conntrack.h>
515 #include <linux/netfilter/x_tables.h>
516 #include <linux/netfilter/xt_MARK.h>
519 MODULE_ALIAS("ipt_MARK");
520 MODULE_ALIAS("ip6t_MARK");
522 +static inline u_int16_t
523 +get_dst_port(struct nf_conntrack_tuple *tuple)
525 + switch (tuple->dst.protonum) {
527 + /* XXX Truncate 32-bit GRE key to 16 bits */
528 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
529 + return tuple->dst.u.gre.key;
531 + return htons(ntohl(tuple->dst.u.gre.key));
534 + /* Bind on ICMP echo ID */
535 + return tuple->src.u.icmp.id;
537 + return tuple->dst.u.tcp.port;
539 + return tuple->dst.u.udp.port;
541 + return tuple->dst.u.all;
545 +static inline u_int16_t
546 +get_src_port(struct nf_conntrack_tuple *tuple)
548 + switch (tuple->dst.protonum) {
550 + /* XXX Truncate 32-bit GRE key to 16 bits */
551 + return htons(ntohl(tuple->src.u.gre.key));
553 + /* Bind on ICMP echo ID */
554 + return tuple->src.u.icmp.id;
556 + return tuple->src.u.tcp.port;
558 + return tuple->src.u.udp.port;
560 + return tuple->src.u.all;
565 target_v0(struct sk_buff **pskb,
566 const struct net_device *in,
568 const void *targinfo)
570 const struct xt_mark_target_info_v1 *markinfo = targinfo;
574 switch (markinfo->mode) {
578 mark = (*pskb)->mark | markinfo->mark;
581 + case XT_MARK_COPYXID: {
582 + enum ip_conntrack_info ctinfo;
583 + struct sock *connection_sk;
586 + struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
587 + extern struct inet_hashinfo tcp_hashinfo;
588 + enum ip_conntrack_dir dir;
592 + dir = CTINFO2DIR(ctinfo);
593 + u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
594 + u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
595 + u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
600 + dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
601 + ip = ct->tuplehash[dir].tuple.dst.u3.ip;
602 + port = get_dst_port(&ct->tuplehash[dir].tuple);
604 + if (proto == 1 || proto == 17) {
605 + if (((*pskb)->mark!=-1) && (*pskb)->mark)
606 + ct->xid[0]=(*pskb)->mark;
611 + else if (proto == 6) {
614 + connection_sk = (*pskb)->sk;
616 + connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
619 + connection_sk = (*pskb)->sk;
621 + if (connection_sk) {
622 + connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
623 + ct->xid[!dir]=connection_sk->sk_xid;
624 + if (connection_sk->sk_xid != 0)
625 + mark = connection_sk->sk_xid;
626 + if (connection_sk != (*pskb)->sk)
627 + sock_put(connection_sk);
635 (*pskb)->mark = mark;
640 if (markinfo->mode != XT_MARK_SET
641 && markinfo->mode != XT_MARK_AND
642 - && markinfo->mode != XT_MARK_OR) {
643 + && markinfo->mode != XT_MARK_OR
644 + && markinfo->mode != XT_MARK_COPYXID) {
645 printk(KERN_WARNING "MARK: unknown mode %u\n",
648 diff -Nurb linux-2.6.22-510/net/netfilter/xt_MARK.c.orig linux-2.6.22-520/net/netfilter/xt_MARK.c.orig
649 --- linux-2.6.22-510/net/netfilter/xt_MARK.c.orig 1969-12-31 19:00:00.000000000 -0500
650 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c.orig 2008-03-20 01:27:27.000000000 -0400
652 +/* This is a module which is used for setting the NFMARK field of an skb. */
654 +/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
656 + * This program is free software; you can redistribute it and/or modify
657 + * it under the terms of the GNU General Public License version 2 as
658 + * published by the Free Software Foundation.
662 +#include <linux/module.h>
663 +#include <linux/version.h>
664 +#include <linux/skbuff.h>
665 +#include <linux/ip.h>
666 +#include <net/checksum.h>
667 +#include <net/route.h>
668 +#include <net/inet_hashtables.h>
670 +#include <net/netfilter/nf_conntrack.h>
671 +#include <linux/netfilter/x_tables.h>
672 +#include <linux/netfilter/xt_MARK.h>
674 +MODULE_LICENSE("GPL");
675 +MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
676 +MODULE_DESCRIPTION("ip[6]tables MARK modification module");
677 +MODULE_ALIAS("ipt_MARK");
678 +MODULE_ALIAS("ip6t_MARK");
680 +static inline u_int16_t
681 +get_dst_port(struct nf_conntrack_tuple *tuple)
683 + switch (tuple->dst.protonum) {
685 + /* XXX Truncate 32-bit GRE key to 16 bits */
686 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
687 + return tuple->dst.u.gre.key;
689 + return htons(ntohl(tuple->dst.u.gre.key));
692 + /* Bind on ICMP echo ID */
693 + return tuple->src.u.icmp.id;
695 + return tuple->dst.u.tcp.port;
697 + return tuple->dst.u.udp.port;
699 + return tuple->dst.u.all;
703 +static inline u_int16_t
704 +get_src_port(struct nf_conntrack_tuple *tuple)
706 + switch (tuple->dst.protonum) {
708 + /* XXX Truncate 32-bit GRE key to 16 bits */
709 + return htons(ntohl(tuple->src.u.gre.key));
711 + /* Bind on ICMP echo ID */
712 + return tuple->src.u.icmp.id;
714 + return tuple->src.u.tcp.port;
716 + return tuple->src.u.udp.port;
718 + return tuple->src.u.all;
723 +target_v0(struct sk_buff **pskb,
724 + const struct net_device *in,
725 + const struct net_device *out,
726 + unsigned int hooknum,
727 + const struct xt_target *target,
728 + const void *targinfo)
730 + const struct xt_mark_target_info *markinfo = targinfo;
732 + (*pskb)->mark = markinfo->mark;
733 + return XT_CONTINUE;
737 +target_v1(struct sk_buff **pskb,
738 + const struct net_device *in,
739 + const struct net_device *out,
740 + unsigned int hooknum,
741 + const struct xt_target *target,
742 + const void *targinfo)
744 + const struct xt_mark_target_info_v1 *markinfo = targinfo;
747 + switch (markinfo->mode) {
749 + mark = markinfo->mark;
753 + mark = (*pskb)->mark & markinfo->mark;
757 + mark = (*pskb)->mark | markinfo->mark;
760 + case XT_MARK_COPYXID: {
761 + enum ip_conntrack_info ctinfo;
762 + struct sock *connection_sk=NULL;
765 + struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
766 + extern struct inet_hashinfo tcp_hashinfo;
767 + enum ip_conntrack_dir dir;
771 + dir = CTINFO2DIR(ctinfo);
772 + u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
773 + u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
774 + u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
779 + dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
780 + ip = ct->tuplehash[dir].tuple.dst.u3.ip;
781 + port = get_dst_port(&ct->tuplehash[dir].tuple);
784 + if (((*pskb)->mark!=-1) && (*pskb)->mark)
785 + ct->xid[0]=(*pskb)->mark;
788 + printk(KERN_CRIT "%d %d\n",ct->xid[0],(*pskb)->mark);
791 + else if (proto == 6) {
793 + connection_sk = (*pskb)->sk;
795 + connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
798 + if (connection_sk) {
799 + connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
800 + ct->xid[!dir]=connection_sk->sk_xid;
801 + if (connection_sk->sk_xid != 0)
802 + mark = connection_sk->sk_xid;
803 + if (connection_sk != (*pskb)->sk)
804 + sock_put(connection_sk);
812 + (*pskb)->mark = mark;
813 + return XT_CONTINUE;
818 +checkentry_v0(const char *tablename,
820 + const struct xt_target *target,
822 + unsigned int hook_mask)
824 + struct xt_mark_target_info *markinfo = targinfo;
826 + if (markinfo->mark > 0xffffffff) {
827 + printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
834 +checkentry_v1(const char *tablename,
836 + const struct xt_target *target,
838 + unsigned int hook_mask)
840 + struct xt_mark_target_info_v1 *markinfo = targinfo;
842 + if (markinfo->mode != XT_MARK_SET
843 + && markinfo->mode != XT_MARK_AND
844 + && markinfo->mode != XT_MARK_OR
845 + && markinfo->mode != XT_MARK_COPYXID) {
846 + printk(KERN_WARNING "MARK: unknown mode %u\n",
850 + if (markinfo->mark > 0xffffffff) {
851 + printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
857 +#ifdef CONFIG_COMPAT
858 +struct compat_xt_mark_target_info_v1 {
859 + compat_ulong_t mark;
865 +static void compat_from_user_v1(void *dst, void *src)
867 + struct compat_xt_mark_target_info_v1 *cm = src;
868 + struct xt_mark_target_info_v1 m = {
872 + memcpy(dst, &m, sizeof(m));
875 +static int compat_to_user_v1(void __user *dst, void *src)
877 + struct xt_mark_target_info_v1 *m = src;
878 + struct compat_xt_mark_target_info_v1 cm = {
882 + return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
884 +#endif /* CONFIG_COMPAT */
886 +static struct xt_target xt_mark_target[] = {
891 + .checkentry = checkentry_v0,
892 + .target = target_v0,
893 + .targetsize = sizeof(struct xt_mark_target_info),
901 + .checkentry = checkentry_v1,
902 + .target = target_v1,
903 + .targetsize = sizeof(struct xt_mark_target_info_v1),
904 +#ifdef CONFIG_COMPAT
905 + .compatsize = sizeof(struct compat_xt_mark_target_info_v1),
906 + .compat_from_user = compat_from_user_v1,
907 + .compat_to_user = compat_to_user_v1,
914 + .family = AF_INET6,
916 + .checkentry = checkentry_v0,
917 + .target = target_v0,
918 + .targetsize = sizeof(struct xt_mark_target_info),
924 +static int __init xt_mark_init(void)
926 + return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
929 +static void __exit xt_mark_fini(void)
931 + xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
934 +module_init(xt_mark_init);
935 +module_exit(xt_mark_fini);
936 diff -Nurb linux-2.6.22-510/net/netfilter/xt_SETXID.c linux-2.6.22-520/net/netfilter/xt_SETXID.c
937 --- linux-2.6.22-510/net/netfilter/xt_SETXID.c 1969-12-31 19:00:00.000000000 -0500
938 +++ linux-2.6.22-520/net/netfilter/xt_SETXID.c 2008-03-20 01:27:27.000000000 -0400
940 +#include <linux/module.h>
941 +#include <linux/skbuff.h>
942 +#include <linux/ip.h>
943 +#include <net/checksum.h>
944 +#include <linux/vs_network.h>
946 +#include <linux/netfilter/x_tables.h>
947 +#include <linux/netfilter/xt_SETXID.h>
949 +MODULE_LICENSE("GPL");
951 +MODULE_DESCRIPTION("");
952 +MODULE_ALIAS("ipt_SETXID");
955 +target_v1(struct sk_buff **pskb,
956 + const struct net_device *in,
957 + const struct net_device *out,
958 + unsigned int hooknum,
959 + const struct xt_target *target,
960 + const void *targinfo)
962 + const struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
964 + switch (setxidinfo->mode) {
965 + case XT_SET_PACKET_XID:
966 + (*pskb)->skb_tag = setxidinfo->mark;
969 + return XT_CONTINUE;
974 +checkentry_v1(const char *tablename,
976 + const struct xt_target *target,
978 + unsigned int hook_mask)
980 + struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
982 + if (setxidinfo->mode != XT_SET_PACKET_XID) {
983 + printk(KERN_WARNING "SETXID: unknown mode %u\n",
991 +static struct xt_target xt_setxid_target[] = {
996 + .checkentry = checkentry_v1,
997 + .target = target_v1,
998 + .targetsize = sizeof(struct xt_setxid_target_info_v1),
1000 + .me = THIS_MODULE,
1004 +static int __init init(void)
1008 + err = xt_register_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
1012 +static void __exit fini(void)
1014 + xt_unregister_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
1019 diff -Nurb linux-2.6.22-510/net/packet/af_packet.c linux-2.6.22-520/net/packet/af_packet.c
1020 --- linux-2.6.22-510/net/packet/af_packet.c 2007-07-08 19:32:17.000000000 -0400
1021 +++ linux-2.6.22-520/net/packet/af_packet.c 2008-03-20 01:27:27.000000000 -0400
1023 #include <linux/poll.h>
1024 #include <linux/module.h>
1025 #include <linux/init.h>
1026 +#include <linux/vs_network.h>
1029 #include <net/inet_common.h>
1034 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
1038 * Get and verify the address.
1040 @@ -420,6 +424,10 @@
1043 struct sk_filter *filter;
1044 + int tag = skb->skb_tag;
1046 + if (sk->sk_nx_info && !(tag == 1 || sk->sk_nid == tag))
1050 filter = rcu_dereference(sk->sk_filter);
1052 unsigned char *addr;
1053 int ifindex, err, reserve = 0;
1055 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
1059 * Get and verify the address.
1062 __be16 proto = (__force __be16)protocol; /* weird, but documented */
1065 - if (!capable(CAP_NET_RAW))
1066 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET))
1068 if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
1069 sock->type != SOCK_PACKET)