summaryrefslogtreecommitdiffstats
path: root/src/conntrack/copy.c
blob: e03abc8c172fff2bfc62d2994fb043c9e42fb4a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * (C) 2008 by Pablo Neira Ayuso <pablo@netfilter.org>
 *
 * This software may be used and distributed according to the terms
 * of the GNU General Public License, incorporated herein by reference.
 */

#include "internal.h"

#define TS_ORIG								\
({									\
	((1 << ATTR_ORIG_IPV4_SRC) | (1 << ATTR_ORIG_IPV4_DST) |	\
	 (1 << ATTR_ORIG_IPV6_SRC) | (1 << ATTR_ORIG_IPV6_DST) |	\
	 (1 << ATTR_ORIG_PORT_SRC) | (1 << ATTR_ORIG_PORT_DST) | 	\
	 (1 << ATTR_ORIG_L3PROTO)  | (1 << ATTR_ORIG_L4PROTO)  | 	\
	 (1 << ATTR_ICMP_TYPE)	   | (1 << ATTR_ICMP_CODE)     | 	\
	 (1 << ATTR_ICMP_ID));						\
})

#define TS_REPL								\
({									\
	((1 << ATTR_REPL_IPV4_SRC) | (1 << ATTR_REPL_IPV4_DST) | 	\
	 (1 << ATTR_REPL_IPV6_SRC) | (1 << ATTR_REPL_IPV6_DST) | 	\
	 (1 << ATTR_REPL_PORT_SRC) | (1 << ATTR_REPL_PORT_DST) | 	\
	 (1 << ATTR_REPL_L3PROTO)  | (1 << ATTR_REPL_L4PROTO)  |	\
	 (1 << ATTR_ICMP_TYPE)	   | (1 << ATTR_ICMP_CODE)     | 	\
	 (1 << ATTR_ICMP_ID));						\
})

#define TUPLE_SET(dir) (dir == __DIR_ORIG ? TS_ORIG : TS_REPL)

void __copy_tuple(struct nf_conntrack *ct2,
		  const struct nf_conntrack *ct1,
		  int dir)
{
	memcpy(&ct2->tuple[dir].src,
	       &ct1->tuple[dir].src,
	       sizeof(union __nfct_address));

	memcpy(&ct2->tuple[dir].dst,
	       &ct1->tuple[dir].dst,
	       sizeof(union __nfct_address));

	ct2->tuple[dir].l3protonum = ct1->tuple[dir].l3protonum;
	ct2->tuple[dir].protonum = ct1->tuple[dir].protonum;

	memcpy(&ct2->tuple[dir].l4src,
	       &ct1->tuple[dir].l4src,
	       sizeof(union __nfct_l4));

	memcpy(&ct2->tuple[dir].l4dst,
	       &ct1->tuple[dir].l4dst,
	       sizeof(union __nfct_l4));

	/* XXX: this is safe but better convert bitset to uint64_t */
	ct2->set[0] |= ct1->set[0] & TUPLE_SET(__DIR_ORIG);
}