Debian Codegraph @

include/internal/internal.h

raw
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
18 #include <libnfnetlink/libnfnetlink.h>
19 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
20 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
21 #include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
22 #include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
23
24 #include "internal/object.h"
25 #include "internal/prototypes.h"
26 #include "internal/types.h"
27 #include "internal/extern.h"
28 #include "internal/bitops.h"
29 #include "internal/proto.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 ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
44
45 #define BUFFER_SIZE(ret, size, len, offset) \
46 if (ret < 0) \
47 return -1; \
48 size += ret; \
49 if (ret > len) \
50 ret = len; \
51 offset += ret; \
52 len -= ret;
53
54 #define TS_ORIG \
55 ({ \
56 ((1 << ATTR_ORIG_IPV4_SRC) | (1 << ATTR_ORIG_IPV4_DST) | \
57 (1 << ATTR_ORIG_IPV6_SRC) | (1 << ATTR_ORIG_IPV6_DST) | \
58 (1 << ATTR_ORIG_PORT_SRC) | (1 << ATTR_ORIG_PORT_DST) | \
59 (1 << ATTR_ORIG_L3PROTO) | (1 << ATTR_ORIG_L4PROTO) | \
60 (1 << ATTR_ICMP_TYPE) | (1 << ATTR_ICMP_CODE) | \
61 (1 << ATTR_ICMP_ID)); \
62 })
63
64 #define TS_REPL \
65 ({ \
66 ((1 << ATTR_REPL_IPV4_SRC) | (1 << ATTR_REPL_IPV4_DST) | \
67 (1 << ATTR_REPL_IPV6_SRC) | (1 << ATTR_REPL_IPV6_DST) | \
68 (1 << ATTR_REPL_PORT_SRC) | (1 << ATTR_REPL_PORT_DST) | \
69 (1 << ATTR_REPL_L3PROTO) | (1 << ATTR_REPL_L4PROTO) | \
70 (1 << ATTR_ICMP_TYPE) | (1 << ATTR_ICMP_CODE) | \
71 (1 << ATTR_ICMP_ID)); \
72 })
73
74 #define TUPLE_SET(dir) (dir == __DIR_ORIG ? TS_ORIG : TS_REPL)
75
76 #define likely(x) __builtin_expect((x),1)
77 #define unlikely(x) __builtin_expect((x),0)
78
79 #ifndef NSEC_PER_SEC
80 #define NSEC_PER_SEC 1000000000L
81 #endif
82
83 /* extracted from include/linux/netfilter/nf_conntrack_tcp.h .*/
84 struct nf_ct_tcp_flags {
85 uint8_t flags;
86 uint8_t mask;
87 };
88
89 #define NFCT_BITMASK_AND 0
90 #define NFCT_BITMASK_OR 1
91
92 #define __noreturn __attribute__((__noreturn__))
93
94 void __noreturn __abi_breakage(const char *file, int line, const char *reason);
95
96 #define abi_breakage() \
97 __abi_breakage(__FILE__, __LINE__, strerror(errno));
98
99 #endif