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-04-03 16:45:14.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-04-03 16:45:14.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-04-03 16:45:14.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-04-03 16:45:14.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-04-03 16:45:14.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-04-03 16:45:14.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-04-03 16:45:11.000000000 -0400
83 +++ linux-2.6.22-520/include/linux/vserver/network.h 2008-04-03 16:45:14.000000000 -0400
85 #define NXC_TUN_CREATE 0x00000001
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/net/netfilter/nf_conntrack.h linux-2.6.22-520/include/net/netfilter/nf_conntrack.h
94 --- linux-2.6.22-510/include/net/netfilter/nf_conntrack.h 2007-07-08 19:32:17.000000000 -0400
95 +++ linux-2.6.22-520/include/net/netfilter/nf_conntrack.h 2008-04-03 16:45:14.000000000 -0400
97 /* Storage reserved for other modules: */
98 union nf_conntrack_proto proto;
100 + /* PLANETLAB. VNET-specific */
101 + xid_t xid[IP_CT_DIR_MAX];
103 /* features dynamically at the end: helper, nat (both optional) */
106 diff -Nurb linux-2.6.22-510/include/net/raw.h linux-2.6.22-520/include/net/raw.h
107 --- linux-2.6.22-510/include/net/raw.h 2007-07-08 19:32:17.000000000 -0400
108 +++ linux-2.6.22-520/include/net/raw.h 2008-04-03 16:45:14.000000000 -0400
111 extern struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
112 __be32 raddr, __be32 laddr,
116 extern int raw_v4_input(struct sk_buff *skb, struct iphdr *iph, int hash);
118 diff -Nurb linux-2.6.22-510/net/core/skbuff.c linux-2.6.22-520/net/core/skbuff.c
119 --- linux-2.6.22-510/net/core/skbuff.c 2007-07-08 19:32:17.000000000 -0400
120 +++ linux-2.6.22-520/net/core/skbuff.c 2008-04-03 16:45:14.000000000 -0400
122 #include <linux/rtnetlink.h>
123 #include <linux/init.h>
124 #include <linux/scatterlist.h>
125 +#include <linux/vs_network.h>
127 #include <net/protocol.h>
131 skb_reset_tail_pointer(skb);
132 skb->end = skb->tail + size;
133 + skb->skb_tag = nx_current_nid();
134 /* make sure we initialize shinfo sequentially */
135 shinfo = skb_shinfo(skb);
136 atomic_set(&shinfo->dataref, 1);
141 + /* Sapan: Cloned skbs aren't owned by anyone. Let the cloner decide who it belongs to. */
143 atomic_inc(&(skb_shinfo(skb)->dataref));
147 new->tc_index = old->tc_index;
149 skb_copy_secmark(new, old);
150 + new->skb_tag = old->skb_tag;
151 atomic_set(&new->users, 1);
152 skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
153 skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
154 diff -Nurb linux-2.6.22-510/net/core/sock.c linux-2.6.22-520/net/core/sock.c
155 --- linux-2.6.22-510/net/core/sock.c 2008-04-03 16:45:11.000000000 -0400
156 +++ linux-2.6.22-520/net/core/sock.c 2008-04-03 16:45:14.000000000 -0400
162 + if (current_vx_info()) {
166 + if (val < 0 || val > MAX_S_CONTEXT) {
175 /* Don't error on this BSD doesn't and if you think
176 about it this is right. Otherwise apps have to
178 char devname[IFNAMSIZ];
181 - if (!capable(CAP_NET_RAW)) {
182 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
186 diff -Nurb linux-2.6.22-510/net/ipv4/af_inet.c linux-2.6.22-520/net/ipv4/af_inet.c
187 --- linux-2.6.22-510/net/ipv4/af_inet.c 2008-04-03 16:45:11.000000000 -0400
188 +++ linux-2.6.22-520/net/ipv4/af_inet.c 2008-04-03 16:45:14.000000000 -0400
192 inet->sport = htons(inet->num);
193 + sk->sk_xid = vx_current_xid();
194 + sk->sk_nid = nx_current_nid();
199 if ((protocol == IPPROTO_ICMP) &&
200 nx_capable(answer->capability, NXC_RAW_ICMP))
202 + if (sock->type == SOCK_RAW &&
203 + nx_capable(answer->capability, NXC_RAW_SOCKET))
205 if (answer->capability > 0 && !capable(answer->capability))
208 diff -Nurb linux-2.6.22-510/net/ipv4/icmp.c linux-2.6.22-520/net/ipv4/icmp.c
209 --- linux-2.6.22-510/net/ipv4/icmp.c 2008-04-03 16:45:14.000000000 -0400
210 +++ linux-2.6.22-520/net/ipv4/icmp.c 2008-04-03 16:45:14.000000000 -0400
212 if ((raw_sk = sk_head(&raw_v4_htable[hash])) != NULL) {
213 while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr,
215 - skb->dev->ifindex)) != NULL) {
216 + skb->dev->ifindex, skb->skb_tag)) != NULL) {
217 raw_err(raw_sk, skb, info);
218 raw_sk = sk_next(raw_sk);
219 iph = (struct iphdr *)skb->data;
220 diff -Nurb linux-2.6.22-510/net/ipv4/ip_options.c linux-2.6.22-520/net/ipv4/ip_options.c
221 --- linux-2.6.22-510/net/ipv4/ip_options.c 2007-07-08 19:32:17.000000000 -0400
222 +++ linux-2.6.22-520/net/ipv4/ip_options.c 2008-04-03 16:45:14.000000000 -0400
227 - if (!skb && !capable(CAP_NET_RAW)) {
228 + if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
233 opt->router_alert = optptr - iph;
236 - if ((!skb && !capable(CAP_NET_RAW)) || opt->cipso) {
237 + if ((!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) || opt->cipso) {
245 - if (!skb && !capable(CAP_NET_RAW)) {
246 + if (!skb && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET)) {
250 diff -Nurb linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c
251 --- linux-2.6.22-510/net/ipv4/netfilter/ipt_LOG.c 2008-04-03 16:45:06.000000000 -0400
252 +++ linux-2.6.22-520/net/ipv4/netfilter/ipt_LOG.c 2008-04-03 16:45:14.000000000 -0400
255 logflags = NF_LOG_MASK;
257 + printk("TAG=%d ", skb->skb_tag);
259 ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
262 diff -Nurb linux-2.6.22-510/net/ipv4/raw.c linux-2.6.22-520/net/ipv4/raw.c
263 --- linux-2.6.22-510/net/ipv4/raw.c 2008-04-03 16:45:11.000000000 -0400
264 +++ linux-2.6.22-520/net/ipv4/raw.c 2008-04-03 16:45:14.000000000 -0400
267 struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
268 __be32 raddr, __be32 laddr,
272 struct hlist_node *node;
276 if (inet->num == num &&
277 !(inet->daddr && inet->daddr != raddr) &&
278 + (!sk->sk_nx_info || tag == 1 || sk->sk_nid == tag) &&
279 v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
280 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
281 goto found; /* gotcha */
284 sk = __raw_v4_lookup(__sk_head(head), iph->protocol,
285 iph->saddr, iph->daddr,
286 - skb->dev->ifindex);
287 + skb->dev->ifindex, skb->skb_tag);
293 sk = __raw_v4_lookup(sk_next(sk), iph->protocol,
294 iph->saddr, iph->daddr,
295 - skb->dev->ifindex);
296 + skb->dev->ifindex, skb->skb_tag);
299 read_unlock(&raw_v4_lock);
304 - if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
305 + if (!nx_check(0, VS_ADMIN) && !nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET) &&
307 !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
309 diff -Nurb linux-2.6.22-510/net/netfilter/Kconfig linux-2.6.22-520/net/netfilter/Kconfig
310 --- linux-2.6.22-510/net/netfilter/Kconfig 2007-07-08 19:32:17.000000000 -0400
311 +++ linux-2.6.22-520/net/netfilter/Kconfig 2008-04-03 16:45:14.000000000 -0400
314 To compile it as a module, choose M here. If unsure, say N.
316 +config NETFILTER_XT_TARGET_SETXID
317 + tristate '"SETXID" target support'
318 + depends on NETFILTER_XTABLES
320 + This option adds a `SETXID' target, which allows you to alter the
323 config NETFILTER_XT_MATCH_COMMENT
324 tristate '"comment" match support'
325 depends on NETFILTER_XTABLES
326 diff -Nurb linux-2.6.22-510/net/netfilter/Makefile linux-2.6.22-520/net/netfilter/Makefile
327 --- linux-2.6.22-510/net/netfilter/Makefile 2007-07-08 19:32:17.000000000 -0400
328 +++ linux-2.6.22-520/net/netfilter/Makefile 2008-04-03 16:45:14.000000000 -0400
330 obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
333 +obj-$(CONFIG_NETFILTER_XT_TARGET_SETXID) += xt_SETXID.o
334 obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o
335 obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
336 obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
337 diff -Nurb linux-2.6.22-510/net/netfilter/nf_conntrack_core.c linux-2.6.22-520/net/netfilter/nf_conntrack_core.c
338 --- linux-2.6.22-510/net/netfilter/nf_conntrack_core.c 2007-07-08 19:32:17.000000000 -0400
339 +++ linux-2.6.22-520/net/netfilter/nf_conntrack_core.c 2008-04-03 16:45:14.000000000 -0400
342 /* Overload tuple linked list to put us in unconfirmed list. */
343 list_add(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list, &unconfirmed);
344 + conntrack->xid[IP_CT_DIR_ORIGINAL] = -1;
345 + conntrack->xid[IP_CT_DIR_REPLY] = -1;
347 write_unlock_bh(&nf_conntrack_lock);
349 diff -Nurb linux-2.6.22-510/net/netfilter/xt_MARK.c linux-2.6.22-520/net/netfilter/xt_MARK.c
350 --- linux-2.6.22-510/net/netfilter/xt_MARK.c 2007-07-08 19:32:17.000000000 -0400
351 +++ linux-2.6.22-520/net/netfilter/xt_MARK.c 2008-04-04 17:27:41.000000000 -0400
353 * This program is free software; you can redistribute it and/or modify
354 * it under the terms of the GNU General Public License version 2 as
355 * published by the Free Software Foundation.
359 #include <linux/module.h>
360 +#include <linux/version.h>
361 #include <linux/skbuff.h>
362 #include <linux/ip.h>
363 #include <net/checksum.h>
364 +#include <net/route.h>
365 +#include <net/inet_hashtables.h>
367 +#include <net/netfilter/nf_conntrack.h>
368 #include <linux/netfilter/x_tables.h>
369 #include <linux/netfilter/xt_MARK.h>
372 MODULE_ALIAS("ipt_MARK");
373 MODULE_ALIAS("ip6t_MARK");
375 +static inline u_int16_t
376 +get_dst_port(struct nf_conntrack_tuple *tuple)
378 + switch (tuple->dst.protonum) {
380 + /* XXX Truncate 32-bit GRE key to 16 bits */
381 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
382 + return tuple->dst.u.gre.key;
384 + return htons(ntohl(tuple->dst.u.gre.key));
387 + /* Bind on ICMP echo ID */
388 + return tuple->src.u.icmp.id;
390 + return tuple->dst.u.tcp.port;
392 + return tuple->dst.u.udp.port;
394 + return tuple->dst.u.all;
398 +static inline u_int16_t
399 +get_src_port(struct nf_conntrack_tuple *tuple)
401 + switch (tuple->dst.protonum) {
403 + /* XXX Truncate 32-bit GRE key to 16 bits */
404 + return htons(ntohl(tuple->src.u.gre.key));
406 + /* Bind on ICMP echo ID */
407 + return tuple->src.u.icmp.id;
409 + return tuple->src.u.tcp.port;
411 + return tuple->src.u.udp.port;
413 + return tuple->src.u.all;
418 target_v0(struct sk_buff **pskb,
419 const struct net_device *in,
421 const void *targinfo)
423 const struct xt_mark_target_info_v1 *markinfo = targinfo;
427 switch (markinfo->mode) {
431 mark = (*pskb)->mark | markinfo->mark;
434 + case XT_MARK_COPYXID: {
435 + enum ip_conntrack_info ctinfo;
436 + struct sock *connection_sk;
439 + struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
440 + extern struct inet_hashinfo tcp_hashinfo;
441 + enum ip_conntrack_dir dir;
445 + dir = CTINFO2DIR(ctinfo);
446 + u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
447 + u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
448 + u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
453 + dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
454 + ip = ct->tuplehash[dir].tuple.dst.u3.ip;
455 + port = get_dst_port(&ct->tuplehash[dir].tuple);
457 + if (proto == 1 || proto == 17) {
458 + if (((*pskb)->mark!=-1) && (*pskb)->mark)
459 + ct->xid[0]=(*pskb)->mark;
464 + else if (proto == 6) {
466 + connection_sk = (*pskb)->sk;
467 + sock_hold(connection_sk);
470 + connection_sk = inet_lookup_established(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
473 + if (connection_sk) {
474 + if (connection_sk->sk_state == TCP_TIME_WAIT) {
475 + inet_twsk_put(inet_twsk(connection_sk));
478 + connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
479 + ct->xid[!dir]=connection_sk->sk_xid;
480 + if (connection_sk->sk_xid != 0)
481 + mark = connection_sk->sk_xid;
483 + sock_put(connection_sk);
491 (*pskb)->mark = mark;
496 if (markinfo->mode != XT_MARK_SET
497 && markinfo->mode != XT_MARK_AND
498 - && markinfo->mode != XT_MARK_OR) {
499 + && markinfo->mode != XT_MARK_OR
500 + && markinfo->mode != XT_MARK_COPYXID) {
501 printk(KERN_WARNING "MARK: unknown mode %u\n",
504 diff -Nurb linux-2.6.22-510/net/netfilter/xt_SETXID.c linux-2.6.22-520/net/netfilter/xt_SETXID.c
505 --- linux-2.6.22-510/net/netfilter/xt_SETXID.c 1969-12-31 19:00:00.000000000 -0500
506 +++ linux-2.6.22-520/net/netfilter/xt_SETXID.c 2008-04-03 16:45:14.000000000 -0400
508 +#include <linux/module.h>
509 +#include <linux/skbuff.h>
510 +#include <linux/ip.h>
511 +#include <net/checksum.h>
512 +#include <linux/vs_network.h>
514 +#include <linux/netfilter/x_tables.h>
515 +#include <linux/netfilter/xt_SETXID.h>
517 +MODULE_LICENSE("GPL");
519 +MODULE_DESCRIPTION("");
520 +MODULE_ALIAS("ipt_SETXID");
523 +target_v1(struct sk_buff **pskb,
524 + const struct net_device *in,
525 + const struct net_device *out,
526 + unsigned int hooknum,
527 + const struct xt_target *target,
528 + const void *targinfo)
530 + const struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
532 + switch (setxidinfo->mode) {
533 + case XT_SET_PACKET_XID:
534 + (*pskb)->skb_tag = setxidinfo->mark;
537 + return XT_CONTINUE;
542 +checkentry_v1(const char *tablename,
544 + const struct xt_target *target,
546 + unsigned int hook_mask)
548 + struct xt_setxid_target_info_v1 *setxidinfo = targinfo;
550 + if (setxidinfo->mode != XT_SET_PACKET_XID) {
551 + printk(KERN_WARNING "SETXID: unknown mode %u\n",
559 +static struct xt_target xt_setxid_target[] = {
564 + .checkentry = checkentry_v1,
565 + .target = target_v1,
566 + .targetsize = sizeof(struct xt_setxid_target_info_v1),
572 +static int __init init(void)
576 + err = xt_register_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
580 +static void __exit fini(void)
582 + xt_unregister_targets(xt_setxid_target, ARRAY_SIZE(xt_setxid_target));
587 diff -Nurb linux-2.6.22-510/net/packet/af_packet.c linux-2.6.22-520/net/packet/af_packet.c
588 --- linux-2.6.22-510/net/packet/af_packet.c 2007-07-08 19:32:17.000000000 -0400
589 +++ linux-2.6.22-520/net/packet/af_packet.c 2008-04-03 16:45:14.000000000 -0400
591 #include <linux/poll.h>
592 #include <linux/module.h>
593 #include <linux/init.h>
594 +#include <linux/vs_network.h>
597 #include <net/inet_common.h>
602 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
606 * Get and verify the address.
611 struct sk_filter *filter;
612 + int tag = skb->skb_tag;
614 + if (sk->sk_nx_info && !(tag == 1 || sk->sk_nid == tag))
618 filter = rcu_dereference(sk->sk_filter);
621 int ifindex, err, reserve = 0;
623 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
627 * Get and verify the address.
630 __be16 proto = (__force __be16)protocol; /* weird, but documented */
633 - if (!capable(CAP_NET_RAW))
634 + if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET))
636 if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
637 sock->type != SOCK_PACKET)
638 diff -Nurb linux-2.6.22-510/xt_MARK.c linux-2.6.22-520/xt_MARK.c
639 --- linux-2.6.22-510/xt_MARK.c 1969-12-31 19:00:00.000000000 -0500
640 +++ linux-2.6.22-520/xt_MARK.c 2008-04-04 14:26:30.000000000 -0400
642 +/* This is a module which is used for setting the NFMARK field of an skb. */
644 +/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
646 + * This program is free software; you can redistribute it and/or modify
647 + * it under the terms of the GNU General Public License version 2 as
648 + * published by the Free Software Foundation.
652 +#include <linux/module.h>
653 +#include <linux/version.h>
654 +#include <linux/skbuff.h>
655 +#include <linux/ip.h>
656 +#include <net/checksum.h>
657 +#include <net/route.h>
658 +#include <net/inet_hashtables.h>
660 +#include <net/netfilter/nf_conntrack.h>
661 +#include <linux/netfilter/x_tables.h>
662 +#include <linux/netfilter/xt_MARK.h>
664 +MODULE_LICENSE("GPL");
665 +MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
666 +MODULE_DESCRIPTION("ip[6]tables MARK modification module");
667 +MODULE_ALIAS("ipt_MARK");
668 +MODULE_ALIAS("ip6t_MARK");
670 +static inline u_int16_t
671 +get_dst_port(struct nf_conntrack_tuple *tuple)
673 + switch (tuple->dst.protonum) {
675 + /* XXX Truncate 32-bit GRE key to 16 bits */
676 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
677 + return tuple->dst.u.gre.key;
679 + return htons(ntohl(tuple->dst.u.gre.key));
682 + /* Bind on ICMP echo ID */
683 + return tuple->src.u.icmp.id;
685 + return tuple->dst.u.tcp.port;
687 + return tuple->dst.u.udp.port;
689 + return tuple->dst.u.all;
693 +static inline u_int16_t
694 +get_src_port(struct nf_conntrack_tuple *tuple)
696 + switch (tuple->dst.protonum) {
698 + /* XXX Truncate 32-bit GRE key to 16 bits */
699 + return htons(ntohl(tuple->src.u.gre.key));
701 + /* Bind on ICMP echo ID */
702 + return tuple->src.u.icmp.id;
704 + return tuple->src.u.tcp.port;
706 + return tuple->src.u.udp.port;
708 + return tuple->src.u.all;
713 +target_v0(struct sk_buff **pskb,
714 + const struct net_device *in,
715 + const struct net_device *out,
716 + unsigned int hooknum,
717 + const struct xt_target *target,
718 + const void *targinfo)
720 + const struct xt_mark_target_info *markinfo = targinfo;
722 + (*pskb)->mark = markinfo->mark;
723 + return XT_CONTINUE;
727 +target_v1(struct sk_buff **pskb,
728 + const struct net_device *in,
729 + const struct net_device *out,
730 + unsigned int hooknum,
731 + const struct xt_target *target,
732 + const void *targinfo)
734 + const struct xt_mark_target_info_v1 *markinfo = targinfo;
737 + switch (markinfo->mode) {
739 + mark = markinfo->mark;
743 + mark = (*pskb)->mark & markinfo->mark;
747 + mark = (*pskb)->mark | markinfo->mark;
750 + case XT_MARK_COPYXID: {
751 + enum ip_conntrack_info ctinfo;
752 + struct sock *connection_sk;
755 + struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
756 + extern struct inet_hashinfo tcp_hashinfo;
757 + enum ip_conntrack_dir dir;
761 + dir = CTINFO2DIR(ctinfo);
762 + u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
763 + u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
764 + u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
769 + dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
770 + ip = ct->tuplehash[dir].tuple.dst.u3.ip;
771 + port = get_dst_port(&ct->tuplehash[dir].tuple);
773 + if (proto == 1 || proto == 17) {
774 + if (((*pskb)->mark!=-1) && (*pskb)->mark)
775 + ct->xid[0]=(*pskb)->mark;
780 + else if (proto == 6) {
782 + connection_sk = (*pskb)->sk;
783 + sock_hold(connection_sk);
786 + connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
789 + if (connection_sk) {
790 + connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
791 + ct->xid[!dir]=connection_sk->sk_xid;
792 + if (connection_sk->sk_xid != 0)
793 + mark = connection_sk->sk_xid;
794 + if (connection_sk->sk_state == TCP_TIME_WAIT)
795 + inet_twsk_put(inet_twsk(connection_sk));
797 + sock_put(connection_sk);
805 + (*pskb)->mark = mark;
806 + return XT_CONTINUE;
811 +checkentry_v0(const char *tablename,
813 + const struct xt_target *target,
815 + unsigned int hook_mask)
817 + struct xt_mark_target_info *markinfo = targinfo;
819 + if (markinfo->mark > 0xffffffff) {
820 + printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
827 +checkentry_v1(const char *tablename,
829 + const struct xt_target *target,
831 + unsigned int hook_mask)
833 + struct xt_mark_target_info_v1 *markinfo = targinfo;
835 + if (markinfo->mode != XT_MARK_SET
836 + && markinfo->mode != XT_MARK_AND
837 + && markinfo->mode != XT_MARK_OR
838 + && markinfo->mode != XT_MARK_COPYXID) {
839 + printk(KERN_WARNING "MARK: unknown mode %u\n",
843 + if (markinfo->mark > 0xffffffff) {
844 + printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
850 +#ifdef CONFIG_COMPAT
851 +struct compat_xt_mark_target_info_v1 {
852 + compat_ulong_t mark;
858 +static void compat_from_user_v1(void *dst, void *src)
860 + struct compat_xt_mark_target_info_v1 *cm = src;
861 + struct xt_mark_target_info_v1 m = {
865 + memcpy(dst, &m, sizeof(m));
868 +static int compat_to_user_v1(void __user *dst, void *src)
870 + struct xt_mark_target_info_v1 *m = src;
871 + struct compat_xt_mark_target_info_v1 cm = {
875 + return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
877 +#endif /* CONFIG_COMPAT */
879 +static struct xt_target xt_mark_target[] = {
884 + .checkentry = checkentry_v0,
885 + .target = target_v0,
886 + .targetsize = sizeof(struct xt_mark_target_info),
894 + .checkentry = checkentry_v1,
895 + .target = target_v1,
896 + .targetsize = sizeof(struct xt_mark_target_info_v1),
897 +#ifdef CONFIG_COMPAT
898 + .compatsize = sizeof(struct compat_xt_mark_target_info_v1),
899 + .compat_from_user = compat_from_user_v1,
900 + .compat_to_user = compat_to_user_v1,
907 + .family = AF_INET6,
909 + .checkentry = checkentry_v0,
910 + .target = target_v0,
911 + .targetsize = sizeof(struct xt_mark_target_info),
917 +static int __init xt_mark_init(void)
919 + return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
922 +static void __exit xt_mark_fini(void)
924 + xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
927 +module_init(xt_mark_init);
928 +module_exit(xt_mark_fini);