1 /*
2  * WARNING: Do *NOT* ever include this file, only for internal use!
3  * 	    Use the set/get API in order to set/get the conntrack attributes
4  */
5 
6 #ifndef __LIBNETFILTER_CONNTRACK_INTERNAL__
7 #define __LIBNETFILTER_CONNTRACK_INTERNAL__
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <stdarg.h>
12 #include <string.h>
13 #include <sys/types.h>
14 #include <arpa/inet.h>
15 #include <time.h>
16 #include <errno.h>
17 #include <netinet/in.h>
18 
19 #include <libnfnetlink/libnfnetlink.h>
20 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
21 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
22 #include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
23 #include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
24 
25 #include "internal/object.h"
26 #include "internal/prototypes.h"
27 #include "internal/types.h"
28 #include "internal/extern.h"
29 #include "internal/bitops.h"
30 
31 #ifndef IPPROTO_SCTP
32 #define IPPROTO_SCTP 132
33 #endif
34 
35 #ifndef IPPROTO_UDPLITE
36 #define IPPROTO_UDPLITE 136
37 #endif
38 
39 #ifndef IPPROTO_DCCP
40 #define IPPROTO_DCCP 33
41 #endif
42 
43 #define BUFFER_SIZE(ret, size, len, offset)		\
44 	size += ret;					\
45 	if (ret > len)					\
46 		ret = len;				\
47 	offset += ret;					\
48 	len -= ret;
49 
50 #define TS_ORIG								\
51 ({									\
52 	((1 << ATTR_ORIG_IPV4_SRC) | (1 << ATTR_ORIG_IPV4_DST) |	\
53 	 (1 << ATTR_ORIG_IPV6_SRC) | (1 << ATTR_ORIG_IPV6_DST) |	\
54 	 (1 << ATTR_ORIG_PORT_SRC) | (1 << ATTR_ORIG_PORT_DST) | 	\
55 	 (1 << ATTR_ORIG_L3PROTO)  | (1 << ATTR_ORIG_L4PROTO)  | 	\
56 	 (1 << ATTR_ICMP_TYPE)	   | (1 << ATTR_ICMP_CODE)     | 	\
57 	 (1 << ATTR_ICMP_ID));						\
58 })
59 
60 #define TS_REPL								\
61 ({									\
62 	((1 << ATTR_REPL_IPV4_SRC) | (1 << ATTR_REPL_IPV4_DST) | 	\
63 	 (1 << ATTR_REPL_IPV6_SRC) | (1 << ATTR_REPL_IPV6_DST) | 	\
64 	 (1 << ATTR_REPL_PORT_SRC) | (1 << ATTR_REPL_PORT_DST) | 	\
65 	 (1 << ATTR_REPL_L3PROTO)  | (1 << ATTR_REPL_L4PROTO)  |	\
66 	 (1 << ATTR_ICMP_TYPE)	   | (1 << ATTR_ICMP_CODE)     | 	\
67 	 (1 << ATTR_ICMP_ID));						\
68 })
69 
70 #define TUPLE_SET(dir) (dir == __DIR_ORIG ? TS_ORIG : TS_REPL)
71 
72 #define likely(x)       __builtin_expect((x),1)
73 #define unlikely(x)     __builtin_expect((x),0)
74 
75 #ifndef NSEC_PER_SEC
76 #define NSEC_PER_SEC    1000000000L
77 #endif
78 
79 /* extracted from include/linux/netfilter/nf_conntrack_tcp.h .*/
80 struct nf_ct_tcp_flags {
81 	uint8_t flags;
82 	uint8_t mask;
83 };
84 
85 #define NFCT_BITMASK_AND	0
86 #define NFCT_BITMASK_OR		1
87 
88 #endif
89