Debian Codegraph @

include/internal/object.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 _NFCT_OBJECT_H_
7 #define _NFCT_OBJECT_H_
8
9 #include <internal/bitops.h>
10 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
11
12 /*
13 * nfct callback handler object
14 */
15
16 struct nfct_handle {
17 struct nfnl_handle *nfnlh;
18 struct nfnl_subsys_handle *nfnlssh_ct;
19 struct nfnl_subsys_handle *nfnlssh_exp;
20
21 /* callback handler for the new API */
22 struct nfnl_callback nfnl_cb_ct;
23 struct nfnl_callback nfnl_cb_exp;
24
25 int (*cb)(enum nf_conntrack_msg_type type,
26 struct nf_conntrack *ct,
27 void *data);
28
29 /* This is the second version of the callback that includes
30 * the Netlink header. This is the result of an early design
31 * error, hiding Netlink details is evil. You end needing some
32 * internal information at some point like the Netlink PortID. */
33 int (*cb2)(const struct nlmsghdr *nlh,
34 enum nf_conntrack_msg_type type,
35 struct nf_conntrack *ct,
36 void *data);
37
38 int (*expect_cb)(enum nf_conntrack_msg_type type,
39 struct nf_expect *exp,
40 void *data);
41
42 /* second version of the expect callback: it includes netlink header */
43 int (*expect_cb2)(const struct nlmsghdr *nlh,
44 enum nf_conntrack_msg_type type,
45 struct nf_expect *exp,
46 void *data);
47 };
48
49 /* container used to pass data to nfnl callbacks */
50 struct __data_container {
51 struct nfct_handle *h;
52 enum nf_conntrack_msg_type type;
53 void *data;
54 };
55
56 /*
57 * conntrack object
58 */
59
60 union __nfct_l4_src {
61 /* Add other protocols here. */
62 uint16_t all;
63 struct {
64 uint16_t port;
65 } tcp;
66 struct {
67 uint16_t port;
68 } udp;
69 struct {
70 uint16_t id;
71 } icmp;
72 struct {
73 uint16_t port;
74 } sctp;
75 struct {
76 uint16_t port;
77 } dccp;
78 };
79
80 union __nfct_l4_dst {
81 /* Add other protocols here. */
82 uint16_t all;
83 struct {
84 uint16_t port;
85 } tcp;
86 struct {
87 uint16_t port;
88 } udp;
89 struct {
90 uint8_t type, code;
91 } icmp;
92 struct {
93 uint16_t port;
94 } sctp;
95 struct {
96 uint16_t port;
97 } dccp;
98 };
99
100 union __nfct_address {
101 uint32_t v4;
102 struct in6_addr v6;
103 };
104
105 struct __nfct_tuple {
106 union __nfct_address src;
107 union __nfct_address dst;
108
109 uint8_t l3protonum;
110 uint8_t protonum;
111 uint16_t zone;
112
113 union __nfct_l4_src l4src;
114 union __nfct_l4_dst l4dst;
115 };
116
117 #define __DIR_ORIG 0
118 #define __DIR_REPL 1
119 #define __DIR_MAX __DIR_REPL+1
120 #define __DIR_MASTER 2
121
122 union __nfct_protoinfo {
123 struct {
124 uint8_t state;
125 struct {
126 uint8_t value;
127 uint8_t mask;
128 } flags[__DIR_MAX];
129 uint8_t wscale[__DIR_MAX];
130 } tcp;
131 struct {
132 uint8_t state;
133 uint32_t vtag[__DIR_MAX];
134 } sctp;
135 struct {
136 uint8_t state;
137 uint8_t role;
138 uint64_t handshake_seq;
139 } dccp;
140 };
141
142 struct __nfct_counters {
143 uint64_t packets;
144 uint64_t bytes;
145 };
146
147 struct __nfct_nat {
148 union __nfct_address min_ip, max_ip;
149 union __nfct_l4_src l4min, l4max;
150 };
151
152 struct nfct_tuple_head {
153 struct __nfct_tuple orig;
154
155 #define __NFCT_BITSET 3
156 uint32_t set[__NFCT_BITSET];
157 };
158
159 struct nf_conntrack {
160 struct nfct_tuple_head head;
161 struct __nfct_tuple repl;
162 struct __nfct_tuple master;
163
164 uint32_t timeout;
165 uint32_t mark;
166 uint32_t secmark;
167 uint32_t status;
168 uint32_t use;
169 uint32_t id;
170 uint16_t zone;
171
172 char helper_name[NFCT_HELPER_NAME_MAX];
173 /* According to Eric Paris <[email protected]> this field can be up to 4096
174 * bytes long. For that reason, we allocate this dynamically. */
175 char *secctx;
176
177 union __nfct_protoinfo protoinfo;
178 struct __nfct_counters counters[__DIR_MAX];
179 struct __nfct_nat snat;
180 struct __nfct_nat dnat;
181
182 struct {
183 uint32_t correction_pos;
184 uint32_t offset_before;
185 uint32_t offset_after;
186 } natseq[__DIR_MAX];
187
188 struct {
189 uint64_t start;
190 uint64_t stop;
191 } timestamp;
192
193 struct {
194 uint32_t isn;
195 uint32_t its;
196 uint32_t tsoff;
197 } synproxy;
198
199 void *helper_info;
200 size_t helper_info_len;
201
202 struct nfct_bitmask *connlabels;
203 struct nfct_bitmask *connlabels_mask;
204 uint64_t timestamp_event;
205 };
206
207 /*
208 * conntrack filter object
209 */
210
211 struct nfct_filter {
212 /*
213 * As many other objects in this library, the attributes are
214 * private. This gives us the chance to modify the layout and
215 * object size.
216 *
217 * Another observation, although this object might seem too
218 * memory consuming, it is only needed to build the filter. Thus,
219 * once it is attached, you can release this object.
220 */
221
222 /*
223 * filter logic: use positive or negative logic
224 */
225 enum nfct_filter_logic logic[NFCT_FILTER_MAX];
226
227 /*
228 * This the layer 4 protocol map for filtering. Not more than 255
229 * protocols. Although IPPROTO_MAX is currently 263, there are many
230 * fewer protocols defined in netinet/in.h, so no one should reach this
231 * limit.
232 */
233 #define __FILTER_L4PROTO_MAX 255
234 uint32_t l4proto_map[DIV_ROUND_UP(IPPROTO_MAX, 32)];
235 uint32_t l4proto_len;
236
237 struct {
238 /*
239 * No limitations in the protocol filtering. We use a map of
240 * 16 bits per protocol. As for now, DCCP has 10 states, TCP has
241 * 10 states, SCTP has 8 state. Therefore, 16 bits is enough.
242 */
243 #define __FILTER_PROTO_MAX 16
244 uint16_t map;
245 uint16_t len;
246 } l4proto_state[IPPROTO_MAX];
247
248 #define __FILTER_ADDR_SRC 0
249 #define __FILTER_ADDR_DST 1
250
251 /*
252 * FIXME: For IPv4 filtering, up to 127 IPs by now.
253 * This limitation is related to the existing autogenerated BSF code
254 * (two BSF lines per comparison) and the fact that the maximum
255 * jump offset is 0xff which is 255.
256 */
257 uint32_t l3proto_elems[2];
258 struct {
259 #define __FILTER_ADDR_MAX 127
260 uint32_t addr;
261 uint32_t mask;
262 } l3proto[2][__FILTER_ADDR_MAX];
263
264 /*
265 * FIXME: For IPv6 filtering, up to 20 IPs/masks (12 BSF lines
266 * per comparison). I think that it is not worthy to try to support
267 * more than that for performance reasons. It seems that oprofile
268 * shows bad numbers for very large BSF code.
269 */
270 uint32_t l3proto_elems_ipv6[2];
271 struct {
272 #define __FILTER_IPV6_MAX 20
273 uint32_t addr[4];
274 uint32_t mask[4];
275 } l3proto_ipv6[2][__FILTER_IPV6_MAX];
276
277 uint32_t mark_elems;
278 struct {
279 #define __FILTER_MARK_MAX 127
280 uint32_t val;
281 uint32_t mask;
282 } mark[__FILTER_MARK_MAX];
283
284 uint32_t zone_elems;
285 #define __FILTER_ZONE_MAX 127
286 uint16_t zone[__FILTER_ZONE_MAX];
287
288 uint32_t set[1];
289 };
290
291 /*
292 * conntrack filter dump object
293 */
294
295 struct nfct_filter_dump {
296 struct nf_conntrack ct;
297 struct nfct_filter_dump_mark mark;
298 struct nfct_filter_dump_mark status;
299 uint8_t l3num;
300 uint32_t set;
301 uint16_t zone;
302 };
303
304 /*
305 * expectation object
306 */
307
308 #define __NFCT_EXPECTFN_MAX 24 /* maximum symbol length. */
309
310 struct nf_expect {
311 struct nfct_tuple_head master;
312 struct nfct_tuple_head expected;
313 struct nfct_tuple_head mask;
314 struct nfct_tuple_head nat;
315
316 uint32_t timeout;
317 uint32_t id;
318 uint16_t zone;
319 uint32_t flags;
320 uint32_t class;
321 char helper_name[NFCT_HELPER_NAME_MAX];
322 uint32_t nat_dir;
323 char expectfn[__NFCT_EXPECTFN_MAX];
324
325 uint32_t set[1];
326 };
327
328 /*
329 * bitmask object
330 */
331 struct nfct_bitmask {
332 unsigned int words;
333 uint32_t bits[];
334 };
335
336 struct nfct_labelmap;
337
338 #endif