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-02-20 04:13:12.000000000 -0500
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-02-20 04:13:12.000000000 -0500
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-02-20 04:13:12.000000000 -0500
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-02-20 04:13:12.000000000 -0500
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-02-20 04:13:12.000000000 -0500
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-02-20 04:13:12.000000000 -0500
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-02-20 04:13:10.000000000 -0500
83 +++ linux-2.6.22-520/include/linux/vserver/network.h 2008-02-20 04:13:12.000000000 -0500
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-02-20 04:13:12.000000000 -0500
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
112 +#define NXF_LBACK_ALLOW 0x00000400
114 +#define NXF_HIDE_NETIF 0x02000000
115 +#define NXF_HIDE_LBACK 0x04000000
117 +#define NXF_STATE_SETUP (1ULL << 32)
118 +#define NXF_STATE_ADMIN (1ULL << 34)
120 +#define NXF_SC_HELPER (1ULL << 36)
121 +#define NXF_PERSISTENT (1ULL << 38)
123 +#define NXF_ONE_TIME (0x0005ULL << 32)
126 +#define NXF_INIT_SET (__nxf_init_set())
128 +static inline uint64_t __nxf_init_set(void) {
129 + return NXF_STATE_ADMIN
130 +#ifdef CONFIG_VSERVER_AUTO_LBACK
134 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
143 +#define NXC_RAW_ICMP 0x00000100
148 +#define NXA_TYPE_IPV4 0x0001
149 +#define NXA_TYPE_IPV6 0x0002
151 +#define NXA_TYPE_NONE 0x0000
152 +#define NXA_TYPE_ANY 0x00FF
154 +#define NXA_TYPE_ADDR 0x0010
155 +#define NXA_TYPE_MASK 0x0020
156 +#define NXA_TYPE_RANGE 0x0040
158 +#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
160 +#define NXA_MOD_BCAST 0x0100
161 +#define NXA_MOD_LBACK 0x0200
163 +#define NXA_LOOPBACK 0x1000
165 +#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
166 +#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
170 +#include <linux/list.h>
171 +#include <linux/spinlock.h>
172 +#include <linux/rcupdate.h>
173 +#include <linux/in.h>
174 +#include <linux/in6.h>
175 +#include <asm/atomic.h>
178 + struct nx_addr_v4 *next;
179 + struct in_addr ip[2];
180 + struct in_addr mask;
186 + struct nx_addr_v6 *next;
187 + struct in6_addr ip;
188 + struct in6_addr mask;
195 + struct hlist_node nx_hlist; /* linked list of nxinfos */
196 + nid_t nx_id; /* vnet id */
197 + atomic_t nx_usecnt; /* usage count */
198 + atomic_t nx_tasks; /* tasks count */
199 + int nx_state; /* context state */
201 + uint64_t nx_flags; /* network flag word */
202 + uint64_t nx_ncaps; /* network capabilities */
204 + struct in_addr v4_lback; /* Loopback address */
205 + struct in_addr v4_bcast; /* Broadcast address */
206 + struct nx_addr_v4 v4; /* First/Single ipv4 address */
208 + struct nx_addr_v6 v6; /* First/Single ipv6 address */
210 + char nx_name[65]; /* network context name */
216 +#define NXS_HASHED 0x0001
217 +#define NXS_SHUTDOWN 0x0100
218 +#define NXS_RELEASED 0x8000
220 +extern struct nx_info *lookup_nx_info(int);
222 +extern int get_nid_list(int, unsigned int *, int);
223 +extern int nid_is_hashed(nid_t);
225 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
227 +extern long vs_net_change(struct nx_info *, unsigned int);
232 +#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
234 +#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
236 +#define NX_IPV6(n) (0)
239 +#endif /* __KERNEL__ */
240 +#endif /* _VX_NETWORK_H */
241 diff -Nurb linux-2.6.22-510/include/net/netfilter/nf_conntrack.h linux-2.6.22-520/include/net/netfilter/nf_conntrack.h
242 --- linux-2.6.22-510/include/net/netfilter/nf_conntrack.h 2007-07-08 19:32:17.000000000 -0400
243 +++ linux-2.6.22-520/include/net/netfilter/nf_conntrack.h 2008-02-20 04:13:12.000000000 -0500
245 /* Storage reserved for other modules: */
246 union nf_conntrack_proto proto;
248 + /* PLANETLAB. VNET-specific */
249 + xid_t xid[IP_CT_DIR_MAX];
251 /* features dynamically at the end: helper, nat (both optional) */
254 diff -Nurb linux-2.6.22-510/include/net/raw.h linux-2.6.22-520/include/net/raw.h
255 --- linux-2.6.22-510/include/net/raw.h 2007-07-08 19:32:17.000000000 -0400
256 +++ linux-2.6.22-520/include/net/raw.h 2008-02-20 04:13:12.000000000 -0500
259 extern struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
260 __be32 raddr, __be32 laddr,
264 extern int raw_v4_input(struct sk_buff *skb, struct iphdr *iph, int hash);
266 diff -Nurb linux-2.6.22-510/net/core/skbuff.c linux-2.6.22-520/net/core/skbuff.c
267 --- linux-2.6.22-510/net/core/skbuff.c 2007-07-08 19:32:17.000000000 -0400
268 +++ linux-2.6.22-520/net/core/skbuff.c 2008-02-20 04:13:12.000000000 -0500
270 #include <linux/rtnetlink.h>
271 #include <linux/init.h>
272 #include <linux/scatterlist.h>
273 +#include <linux/vs_network.h>
275 #include <net/protocol.h>
279 skb_reset_tail_pointer(skb);
280 skb->end = skb->tail + size;
281 + skb->skb_tag = nx_current_nid();
282 /* make sure we initialize shinfo sequentially */
283 shinfo = skb_shinfo(skb);
284 atomic_set(&shinfo->dataref, 1);
289 + /* Sapan: Cloned skbs aren't owned by anyone. Let the cloner decide who it belongs to. */
291 atomic_inc(&(skb_shinfo(skb)->dataref));
295 new->tc_index = old->tc_index;
297 skb_copy_secmark(new, old);
298 + new->skb_tag = old->skb_tag;
299 atomic_set(&new->users, 1);
300 skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
301 skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
302 diff -Nurb linux-2.6.22-510/net/core/sock.c linux-2.6.22-520/net/core/sock.c
303 --- linux-2.6.22-510/net/core/sock.c 2008-02-20 04:13:09.000000000 -0500
304 +++ linux-2.6.22-520/net/core/sock.c 2008-02-20 04:13:12.000000000 -0500
310 + if (current_vx_info()) {
314 + if (val < 0 || val > MAX_S_CONTEXT) {
323 /* Don't error on this BSD doesn't and if you think
324 about it this is right. Otherwise apps have to
326 char devname[IFNAMSIZ];
329 - if (!capable(CAP_NET_RAW)) {
330 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
334 diff -Nurb linux-2.6.22-510/net/ipv4/af_inet.c linux-2.6.22-520/net/ipv4/af_inet.c
335 --- linux-2.6.22-510/net/ipv4/af_inet.c 2008-02-20 04:13:09.000000000 -0500
336 +++ linux-2.6.22-520/net/ipv4/af_inet.c 2008-02-20 04:13:12.000000000 -0500
340 inet->sport = htons(inet->num);
341 + sk->sk_xid = vx_current_xid();
342 + sk->sk_nid = nx_current_nid();
347 if ((protocol == IPPROTO_ICMP) &&
348 nx_capable(answer->capability, NXC_RAW_ICMP))
350 + if (sock->type == SOCK_RAW &&
351 + nx_capable(answer->capability, NXC_RAW_SOCKET))
353 if (answer->capability > 0 && !capable(answer->capability))
356 diff -Nurb linux-2.6.22-510/net/ipv4/icmp.c linux-2.6.22-520/net/ipv4/icmp.c
357 --- linux-2.6.22-510/net/ipv4/icmp.c 2008-02-20 04:13:12.000000000 -0500
358 +++ linux-2.6.22-520/net/ipv4/icmp.c 2008-02-20 04:13:12.000000000 -0500
360 if ((raw_sk = sk_head(&raw_v4_htable[hash])) != NULL) {
361 while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr,
363 - skb->dev->ifindex)) != NULL) {
364 + skb->dev->ifindex, skb->skb_tag)) != NULL) {
365 raw_err(raw_sk, skb, info);
366 raw_sk = sk_next(raw_sk);
367 iph = (struct iphdr *)skb->data;
368 diff -Nurb linux-2.6.22-510/net/ipv4/ip_options.c linux-2.6.22-520/net/ipv4/ip_options.c
369 --- linux-2.6.22-510/net/ipv4/ip_options.c 2007-07-08 19:32:17.000000000 -0400
370 +++ linux-2.6.22-520/net/ipv4/ip_options.c 2008-02-20 04:13:12.000000000 -0500
375 - if (!skb && !capable(CAP_NET_RAW)) {
376 + if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
381 opt->router_alert = optptr - iph;
384 - if ((!skb && !capable(CAP_NET_RAW)) || opt->cipso) {
385 + if ((!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) || opt->cipso) {
393 - if (!skb && !capable(CAP_NET_RAW)) {
394 + if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
398 diff -Nurb linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c
399 --- linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c 2008-02-20 04:13:05.000000000 -0500
400 +++ linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c 2008-02-20 04:13:12.000000000 -0500
403 logflags = NF_LOG_MASK;
405 + printk("TAG=%d ", skb->skb_tag);
407 ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
410 diff -Nurb linux-2.6.22-510/net/ipv4/raw.c linux-2.6.22-520/net/ipv4/raw.c
411 --- linux-2.6.22-510/net/ipv4/raw.c 2008-02-20 04:13:09.000000000 -0500
412 +++ linux-2.6.22-520/net/ipv4/raw.c 2008-02-20 04:13:12.000000000 -0500
415 struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
416 __be32 raddr, __be32 laddr,
420 struct hlist_node *node;
424 if (inet->num == num &&
425 !(inet->daddr && inet->daddr != raddr) &&
426 + (!sk->sk_nx_info || tag == 1 || sk->sk_nid == tag) &&
427 v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
428 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
429 goto found; /* gotcha */
432 sk = __raw_v4_lookup(__sk_head(head), iph->protocol,
433 iph->saddr, iph->daddr,
434 - skb->dev->ifindex);
435 + skb->dev->ifindex, skb->skb_tag);
441 sk = __raw_v4_lookup(sk_next(sk), iph->protocol,
442 iph->saddr, iph->daddr,
443 - skb->dev->ifindex);
444 + skb->dev->ifindex, skb->skb_tag);
447 read_unlock(&raw_v4_lock);
452 - if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
453 + if (!nx_check(0, VS_ADMIN) && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET) &&
455 !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
457 diff -Nurb linux-2.6.22-510/net/netfilter/Kconfig linux-2.6.22-520/net/netfilter/Kconfig
458 --- linux-2.6.22-510/net/netfilter/Kconfig 2007-07-08 19:32:17.000000000 -0400
459 +++ linux-2.6.22-520/net/netfilter/Kconfig 2008-02-20 04:13:12.000000000 -0500
462 To compile it as a module, choose M here. If unsure, say N.
464 +config NETFILTER_XT_TARGET_SETXID
465 + tristate '"SETXID" target support'
466 + depends on NETFILTER_XTABLES
468 + This option adds a `SETXID' target, which allows you to alter the
471 config NETFILTER_XT_MATCH_COMMENT
472 tristate '"comment" match support'
473 depends on NETFILTER_XTABLES
474 diff -Nurb linux-2.6.22-510/net/netfilter/Makefile linux-2.6.22-520/net/netfilter/Makefile
475 --- linux-2.6.22-510/net/netfilter/Makefile 2007-07-08 19:32:17.000000000 -0400
476 +++ linux-2.6.22-520/net/netfilter/Makefile 2008-02-20 04:13:12.000000000 -0500
478 obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
481 +obj-$(CONFIG_NETFILTER_XT_TARGET_SETXID) += xt_SETXID.o
482 obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o
483 obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
484 obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
485 diff -Nurb linux-2.6.22-510/net/netfilter/nf_conntrack_core.c linux-2.6.22-520/net/netfilter/nf_conntrack_core.c
486 --- linux-2.6.22-510/net/netfilter/nf_conntrack_core.c 2007-07-08 19:32:17.000000000 -0400
487 +++ linux-2.6.22-520/net/netfilter/nf_conntrack_core.c 2008-02-20 04:13:12.000000000 -0500
490 /* Overload tuple linked list to put us in unconfirmed list. */
491 list_add(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list, &unconfirmed);
492 + conntrack->xid[IP_CT_DIR_ORIGINAL] = -1;
493 + conntrack->xid[IP_CT_DIR_REPLY] = -1;
495 write_unlock_bh(&nf_conntrack_lock);
497 diff -Nurb linux-2.6.22-510/net/netfilter/xt_MARK.c linux-2.6.22-520/net/netfilter/xt_MARK.c
498 --- linux-2.6.22-510/net/netfilter/xt_MARK.c 2007-07-08 19:32:17.000000000 -0400
499 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c 2008-02-20 06:56:29.000000000 -0500
501 * This program is free software; you can redistribute it and/or modify
502 * it under the terms of the GNU General Public License version 2 as
503 * published by the Free Software Foundation.
507 #include <linux/module.h>
508 +#include <linux/version.h>
509 #include <linux/skbuff.h>
510 #include <linux/ip.h>
511 #include <net/checksum.h>
512 +#include <net/route.h>
513 +#include <net/inet_hashtables.h>
515 +#include <net/netfilter/nf_conntrack.h>
516 #include <linux/netfilter/x_tables.h>
517 #include <linux/netfilter/xt_MARK.h>
520 MODULE_ALIAS("ipt_MARK");
521 MODULE_ALIAS("ip6t_MARK");
523 +static inline u_int16_t
524 +get_dst_port(struct nf_conntrack_tuple *tuple)
526 + switch (tuple->dst.protonum) {
528 + /* XXX Truncate 32-bit GRE key to 16 bits */
529 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
530 + return tuple->dst.u.gre.key;
532 + return htons(ntohl(tuple->dst.u.gre.key));
535 + /* Bind on ICMP echo ID */
536 + return tuple->src.u.icmp.id;
538 + return tuple->dst.u.tcp.port;
540 + return tuple->dst.u.udp.port;
542 + return tuple->dst.u.all;
546 +static inline u_int16_t
547 +get_src_port(struct nf_conntrack_tuple *tuple)
549 + switch (tuple->dst.protonum) {
551 + /* XXX Truncate 32-bit GRE key to 16 bits */
552 + return htons(ntohl(tuple->src.u.gre.key));
554 + /* Bind on ICMP echo ID */
555 + return tuple->src.u.icmp.id;
557 + return tuple->src.u.tcp.port;
559 + return tuple->src.u.udp.port;
561 + return tuple->src.u.all;
566 target_v0(struct sk_buff **pskb,
567 const struct net_device *in,
569 const void *targinfo)
571 const struct xt_mark_target_info_v1 *markinfo = targinfo;
575 switch (markinfo->mode) {
579 mark = (*pskb)->mark | markinfo->mark;
582 + case XT_MARK_COPYXID: {
583 + enum ip_conntrack_info ctinfo;
584 + struct sock *connection_sk;
587 + struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
588 + extern struct inet_hashinfo tcp_hashinfo;
589 + enum ip_conntrack_dir dir;
593 + dir = CTINFO2DIR(ctinfo);
594 + u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
595 + u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
596 + u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
601 + dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
602 + ip = ct->tuplehash[dir].tuple.dst.u3.ip;
603 + port = get_dst_port(&ct->tuplehash[dir].tuple);
605 + if (proto == 1 || proto == 17) {
606 + if (((*pskb)->mark!=-1) && (*pskb)->mark)
607 + ct->xid[0]=(*pskb)->mark;
612 + else if (proto == 6) {
614 + connection_sk = (*pskb)->sk;
616 + connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
619 + if (connection_sk) {
620 + connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
621 + ct->xid[!dir]=connection_sk->sk_xid;
622 + if (connection_sk->sk_xid != 0)
623 + mark = connection_sk->sk_xid;
624 + if (connection_sk != (*pskb)->sk)
625 + sock_put(connection_sk);
633 (*pskb)->mark = mark;
638 if (markinfo->mode != XT_MARK_SET
639 && markinfo->mode != XT_MARK_AND
640 - && markinfo->mode != XT_MARK_OR) {
641 + && markinfo->mode != XT_MARK_OR
642 + && markinfo->mode != XT_MARK_COPYXID) {
643 printk(KERN_WARNING "MARK: unknown mode %u\n",
646 diff -Nurb linux-2.6.22-510/net/netfilter/xt_MARK.c.orig linux-2.6.22-520/net/netfilter/xt_MARK.c.orig
647 --- linux-2.6.22-510/net/netfilter/xt_MARK.c.orig 1969-12-31 19:00:00.000000000 -0500
648 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c.orig 2008-02-20 06:54:56.000000000 -0500
650 +/* This is a module which is used for setting the NFMARK field of an skb. */
652 +/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
654 + * This program is free software; you can redistribute it and/or modify
655 + * it under the terms of the GNU General Public License version 2 as
656 + * published by the Free Software Foundation.
660 +#include <linux/module.h>
661 +#include <linux/version.h>
662 +#include <linux/skbuff.h>
663 +#include <linux/ip.h>
664 +#include <net/checksum.h>
665 +#include <net/route.h>
666 +#include <net/inet_hashtables.h>
668 +#include <net/netfilter/nf_conntrack.h>
669 +#include <linux/netfilter/x_tables.h>
670 +#include <linux/netfilter/xt_MARK.h>
672 +MODULE_LICENSE("GPL");
673 +MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
674 +MODULE_DESCRIPTION("ip[6]tables MARK modification module");
675 +MODULE_ALIAS("ipt_MARK");
676 +MODULE_ALIAS("ip6t_MARK");
678 +static inline u_int16_t
679 +get_dst_port(struct nf_conntrack_tuple *tuple)
681 + switch (tuple->dst.protonum) {
683 + /* XXX Truncate 32-bit GRE key to 16 bits */
684 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
685 + return tuple->dst.u.gre.key;
687 + return htons(ntohl(tuple->dst.u.gre.key));
690 + /* Bind on ICMP echo ID */
691 + return tuple->src.u.icmp.id;
693 + return tuple->dst.u.tcp.port;
695 + return tuple->dst.u.udp.port;
697 + return tuple->dst.u.all;
701 +static inline u_int16_t
702 +get_src_port(struct nf_conntrack_tuple *tuple)
704 + switch (tuple->dst.protonum) {
706 + /* XXX Truncate 32-bit GRE key to 16 bits */
707 + return htons(ntohl(tuple->src.u.gre.key));
709 + /* Bind on ICMP echo ID */
710 + return tuple->src.u.icmp.id;
712 + return tuple->src.u.tcp.port;
714 + return tuple->src.u.udp.port;
716 + return tuple->src.u.all;
721 +target_v0(struct sk_buff **pskb,
722 + const struct net_device *in,
723 + const struct net_device *out,
724 + unsigned int hooknum,
725 + const struct xt_target *target,
726 + const void *targinfo)
728 + const struct xt_mark_target_info *markinfo = targinfo;
730 + (*pskb)->mark = markinfo->mark;
731 + return XT_CONTINUE;
735 +target_v1(struct sk_buff **pskb,
736 + const struct net_device *in,
737 + const struct net_device *out,
738 + unsigned int hooknum,
739 + const struct xt_target *target,
740 + const void *targinfo)
742 + const struct xt_mark_target_info_v1 *markinfo = targinfo;
745 + switch (markinfo->mode) {
747 + mark = markinfo->mark;
751 + mark = (*pskb)->mark & markinfo->mark;
755 + mark = (*pskb)->mark | markinfo->mark;
758 + case XT_MARK_COPYXID: {
759 + enum ip_conntrack_info ctinfo;
760 + struct sock *connection_sk;
763 + struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
764 + extern struct inet_hashinfo tcp_hashinfo;
765 + enum ip_conntrack_dir dir;
769 + dir = CTINFO2DIR(ctinfo);
770 + u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
771 + u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
772 + u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
777 + dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
778 + ip = ct->tuplehash[dir].tuple.dst.u3.ip;
779 + port = get_dst_port(&ct->tuplehash[dir].tuple);
782 + if (((*pskb)->mark!=-1) && (*pskb)->mark)
783 + ct->xid[0]=(*pskb)->mark;
786 + printk(KERN_CRIT "%d %d\n",ct->xid[0],(*pskb)->mark);
789 + else if (proto == 6) {
791 + connection_sk = (*pskb)->sk;
793 + connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
796 + if (connection_sk) {
797 + connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
798 + ct->xid[!dir]=connection_sk->sk_xid;
799 + if (connection_sk->sk_xid != 0)
800 + mark = connection_sk->sk_xid;
801 + if (connection_sk != (*pskb)->sk)
802 + sock_put(connection_sk);
810 + (*pskb)->mark = mark;
811 + return XT_CONTINUE;
816 +checkentry_v0(const char *tablename,
818 + const struct xt_target *target,
820 + unsigned int hook_mask)
822 + struct xt_mark_target_info *markinfo = targinfo;
824 + if (markinfo->mark > 0xffffffff) {
825 + printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
832 +checkentry_v1(const char *tablename,
834 + const struct xt_target *target,
836 + unsigned int hook_mask)
838 + struct xt_mark_target_info_v1 *markinfo = targinfo;
840 + if (markinfo->mode != XT_MARK_SET
841 + && markinfo->mode != XT_MARK_AND
842 + && markinfo->mode != XT_MARK_OR
843 + && markinfo->mode != XT_MARK_COPYXID) {
844 + printk(KERN_WARNING "MARK: unknown mode %u\n",
848 + if (markinfo->mark > 0xffffffff) {
849 + printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
855 +#ifdef CONFIG_COMPAT
856 +struct compat_xt_mark_target_info_v1 {
857 + compat_ulong_t mark;
863 +static void compat_from_user_v1(void *dst, void *src)
865 + struct compat_xt_mark_target_info_v1 *cm = src;
866 + struct xt_mark_target_info_v1 m = {
870 + memcpy(dst, &m, sizeof(m));
873 +static int compat_to_user_v1(void __user *dst, void *src)
875 + struct xt_mark_target_info_v1 *m = src;
876 + struct compat_xt_mark_target_info_v1 cm = {
880 + return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
882 +#endif /* CONFIG_COMPAT */
884 +static struct xt_target xt_mark_target[] = {
889 + .checkentry = checkentry_v0,
890 + .target = target_v0,
891 + .targetsize = sizeof(struct xt_mark_target_info),
899 + .checkentry = checkentry_v1,
900 + .target = target_v1,
901 + .targetsize = sizeof(struct xt_mark_target_info_v1),
902 +#ifdef CONFIG_COMPAT
903 + .compatsize = sizeof(struct compat_xt_mark_target_info_v1),
904 + .compat_from_user = compat_from_user_v1,
905 + .compat_to_user = compat_to_user_v1,
912 + .family = AF_INET6,
914 + .checkentry = checkentry_v0,
915 + .target = target_v0,
916 + .targetsize = sizeof(struct xt_mark_target_info),
922 +static int __init xt_mark_init(void)
924 + return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
927 +static void __exit xt_mark_fini(void)
929 + xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
932 +module_init(xt_mark_init);
933 +module_exit(xt_mark_fini);
934 diff -Nurb linux-2.6.22-510/net/netfilter/xt_SETXID.c linux-2.6.22-520/net/netfilter/xt_SETXID.c
935 --- linux-2.6.22-510/net/netfilter/xt_SETXID.c 1969-12-31 19:00:00.000000000 -0500
936 +++ linux-2.6.22-520/net/netfilter/xt_SETXID.c 2008-02-20 04:13:13.000000000 -0500
938 +#include <linux/module.h>
939 +#include <linux/skbuff.h>
940 +#include <linux/ip.h>
941 +#include <net/checksum.h>
942 +#include <linux/vs_network.h>
944 +#include <linux/netfilter/x_tables.h>
945 +#include <linux/netfilter/xt_SETXID.h>
947 +MODULE_LICENSE("GPL");
949 +MODULE_DESCRIPTION("");
950 +MODULE_ALIAS("ipt_SETXID");
953 +target_v1(struct sk_buff **pskb,
954 + const struct net_device *in,
955 + const struct net_device *out,
956 + unsigned int hooknum,
957 + const struct xt_target *target,
958 + const void *targinfo)
960 + const struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
962 + switch (setxidinfo->mode) {
963 + case XT_SET_PACKET_XID:
964 + (*pskb)->skb_tag = setxidinfo->mark;
967 + return XT_CONTINUE;
972 +checkentry_v1(const char *tablename,
974 + const struct xt_target *target,
976 + unsigned int hook_mask)
978 + struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
980 + if (setxidinfo->mode != XT_SET_PACKET_XID) {
981 + printk(KERN_WARNING "SETXID: unknown mode %u\n",
989 +static struct xt_target xt_setxid_target[] = {
994 + .checkentry = checkentry_v1,
995 + .target = target_v1,
996 + .targetsize = sizeof(struct xt_setxid_target_info_v1),
1002 +static int __init init(void)
1006 + err = xt_register_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
1010 +static void __exit fini(void)
1012 + xt_unregister_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
1017 diff -Nurb linux-2.6.22-510/net/packet/af_packet.c linux-2.6.22-520/net/packet/af_packet.c
1018 --- linux-2.6.22-510/net/packet/af_packet.c 2007-07-08 19:32:17.000000000 -0400
1019 +++ linux-2.6.22-520/net/packet/af_packet.c 2008-02-20 04:13:13.000000000 -0500
1021 #include <linux/poll.h>
1022 #include <linux/module.h>
1023 #include <linux/init.h>
1024 +#include <linux/vs_network.h>
1027 #include <net/inet_common.h>
1032 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
1036 * Get and verify the address.
1038 @@ -420,6 +424,10 @@
1041 struct sk_filter *filter;
1042 + int tag = skb->skb_tag;
1044 + if (sk->sk_nx_info && !(tag == 1 || sk->sk_nid == tag))
1048 filter = rcu_dereference(sk->sk_filter);
1050 unsigned char *addr;
1051 int ifindex, err, reserve = 0;
1053 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
1057 * Get and verify the address.
1060 __be16 proto = (__force __be16)protocol; /* weird, but documented */
1063 - if (!capable(CAP_NET_RAW))
1064 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET))
1066 if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
1067 sock->type != SOCK_PACKET)