1 #ifndef _XTABLES_H
2 #define _XTABLES_H
3
4 /*
5 * Changing any structs/functions may incur a needed change
6 * in libxtables_vcurrent/vage too.
7 */
8
9 #include <sys/socket.h> /* PF_* */
10 #include <sys/types.h>
11 #include <limits.h>
12 #include <stdbool.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <netinet/ether.h>
16 #include <netinet/in.h>
17 #include <net/if.h>
18 #include <linux/types.h>
19 #include <linux/netfilter.h>
20 #include <linux/netfilter/x_tables.h>
21
22 #ifndef IPPROTO_SCTP
23 #define IPPROTO_SCTP 132
24 #endif
25 #ifndef IPPROTO_DCCP
26 #define IPPROTO_DCCP 33
27 #endif
28 #ifndef IPPROTO_MH
29 # define IPPROTO_MH 135
30 #endif
31 #ifndef IPPROTO_UDPLITE
32 #define IPPROTO_UDPLITE 136
33 #endif
34
35 #include <xtables-version.h>
36
37 struct in_addr;
38
39 /*
40 * .size is here so that there is a somewhat reasonable check
41 * against the chosen .type.
42 */
43 #define XTOPT_POINTER(stype, member) \
44 .ptroff = offsetof(stype, member), \
45 .size = sizeof(((stype *)NULL)->member)
46 #define XTOPT_TABLEEND {.name = NULL}
47
48 /**
49 * Select the format the input has to conform to, as well as the target type
50 * (area pointed to with XTOPT_POINTER). Note that the storing is not always
51 * uniform. @cb->val will be populated with as much as there is space, i.e.
52 * exactly 2 items for ranges, but the target area can receive more values
53 * (e.g. in case of ranges), or less values (e.g. %XTTYPE_HOSTMASK).
54 *
55 * %XTTYPE_NONE: option takes no argument
56 * %XTTYPE_UINT*: standard integer
57 * %XTTYPE_UINT*RC: colon-separated range of standard integers
58 * %XTTYPE_DOUBLE: double-precision floating point number
59 * %XTTYPE_STRING: arbitrary string
60 * %XTTYPE_TOSMASK: 8-bit TOS value with optional mask
61 * %XTTYPE_MARKMASK32: 32-bit mark with optional mask
62 * %XTTYPE_SYSLOGLEVEL: syslog level by name or number
63 * %XTTYPE_HOST: one host or address (ptr: union nf_inet_addr)
64 * %XTTYPE_HOSTMASK: one host or address, with an optional prefix length
65 * %XTTYPE_PROTOCOL: protocol number/name from /etc/protocols (ptr: uint8_t)
66 * %XTTYPE_PORT: 16-bit port name or number (supports %XTOPT_NBO)
67 * %XTTYPE_PORTRC: colon-separated port range (names acceptable),
68 * (supports %XTOPT_NBO)
69 * %XTTYPE_PLEN: prefix length
70 * %XTTYPE_PLENMASK: prefix length (ptr: union nf_inet_addr)
71 * %XTTYPE_ETHERMAC: Ethernet MAC address in hex form
72 * %XTTYPE_ETHERMACMASK: Ethernet MAC address in hex form with optional mask
73 */
74 enum xt_option_type {
75 XTTYPE_NONE,
76 XTTYPE_UINT8,
77 XTTYPE_UINT16,
78 XTTYPE_UINT32,
79 XTTYPE_UINT64,
80 XTTYPE_UINT8RC,
81 XTTYPE_UINT16RC,
82 XTTYPE_UINT32RC,
83 XTTYPE_UINT64RC,
84 XTTYPE_DOUBLE,
85 XTTYPE_STRING,
86 XTTYPE_TOSMASK,
87 XTTYPE_MARKMASK32,
88 XTTYPE_SYSLOGLEVEL,
89 XTTYPE_HOST,
90 XTTYPE_HOSTMASK,
91 XTTYPE_PROTOCOL,
92 XTTYPE_PORT,
93 XTTYPE_PORTRC,
94 XTTYPE_PLEN,
95 XTTYPE_PLENMASK,
96 XTTYPE_ETHERMAC,
97 XTTYPE_ETHERMACMASK,
98 };
99
100 /**
101 * %XTOPT_INVERT: option is invertible (usable with !)
102 * %XTOPT_MAND: option is mandatory
103 * %XTOPT_MULTI: option may be specified multiple times
104 * %XTOPT_PUT: store value into memory at @ptroff
105 * %XTOPT_NBO: store value in network-byte order
106 * (only certain XTTYPEs recognize this)
107 */
108 enum xt_option_flags {
109 XTOPT_INVERT = 1 << 0,
110 XTOPT_MAND = 1 << 1,
111 XTOPT_MULTI = 1 << 2,
112 XTOPT_PUT = 1 << 3,
113 XTOPT_NBO = 1 << 4,
114 };
115
116 /**
117 * @name: name of option
118 * @type: type of input and validation method, see %XTTYPE_*
119 * @id: unique number (within extension) for option, 0-31
120 * @excl: bitmask of flags that cannot be used with this option
121 * @also: bitmask of flags that must be used with this option
122 * @flags: bitmask of option flags, see %XTOPT_*
123 * @ptroff: offset into private structure for member
124 * @size: size of the item pointed to by @ptroff; this is a safeguard
125 * @min: lowest allowed value (for singular integral types)
126 * @max: highest allowed value (for singular integral types)
127 * @base: assumed base of parsed value for integer types (default 0)
128 */
129 struct xt_option_entry {
130 const char *name;
131 enum xt_option_type type;
132 unsigned int id, excl, also, flags;
133 unsigned int ptroff;
134 size_t size;
135 unsigned int min, max, base;
136 };
137
138 /**
139 * @arg: input from command line
140 * @ext_name: name of extension currently being processed
141 * @entry: current option being processed
142 * @data: per-extension kernel data block
143 * @xflags: options of the extension that have been used
144 * @invert: whether option was used with !
145 * @nvals: number of results in uXX_multi
146 * @val: parsed result
147 * @udata: per-extension private scratch area
148 * (cf. xtables_{match,target}->udata_size)
149 */
150 struct xt_option_call {
151 const char *arg, *ext_name;
152 const struct xt_option_entry *entry;
153 void *data;
154 unsigned int xflags;
155 bool invert;
156 uint8_t nvals;
157 union {
158 uint8_t u8, u8_range[2], syslog_level, protocol;
159 uint16_t u16, u16_range[2], port, port_range[2];
160 uint32_t u32, u32_range[2];
161 uint64_t u64, u64_range[2];
162 double dbl;
163 struct {
164 union nf_inet_addr haddr, hmask;
165 uint8_t hlen;
166 };
167 struct {
168 uint8_t tos_value, tos_mask;
169 };
170 struct {
171 uint32_t mark, mask;
172 };
173 struct {
174 uint8_t ethermac[ETH_ALEN], ethermacmask[ETH_ALEN];
175 };
176 } val;
177 /* Wished for a world where the ones below were gone: */
178 union {
179 struct xt_entry_match **match;
180 struct xt_entry_target **target;
181 };
182 void *xt_entry;
183 void *udata;
184 };
185
186 /**
187 * @ext_name: name of extension currently being processed
188 * @data: per-extension (kernel) data block
189 * @udata: per-extension private scratch area
190 * (cf. xtables_{match,target}->udata_size)
191 * @xflags: options of the extension that have been used
192 */
193 struct xt_fcheck_call {
194 const char *ext_name;
195 void *data, *udata;
196 unsigned int xflags;
197 };
198
199 /**
200 * A "linear"/linked-list based name<->id map, for files similar to
201 * /etc/iproute2/.
202 */
203 struct xtables_lmap {
204 char *name;
205 int id;
206 struct xtables_lmap *next;
207 };
208
209 enum xtables_ext_flags {
210 XTABLES_EXT_ALIAS = 1 << 0,
211 XTABLES_EXT_WATCHER = 1 << 1,
212 };
213
214 struct xt_xlate;
215
216 struct xt_xlate_mt_params {
217 const void *ip;
218 const struct xt_entry_match *match;
219 int numeric;
220 bool escape_quotes; /* not used anymore, retained for ABI */
221 };
222
223 struct xt_xlate_tg_params {
224 const void *ip;
225 const struct xt_entry_target *target;
226 int numeric;
227 bool escape_quotes; /* not used anymore, retained for ABI */
228 };
229
230 /* Include file for additions: new matches and targets. */
231 struct xtables_match {
232 /*
233 * ABI/API version this module requires. Must be first member,
234 * as the rest of this struct may be subject to ABI changes.
235 */
236 const char *version;
237
238 struct xtables_match *next;
239
240 const char *name;
241 const char *real_name;
242
243 /* Revision of match (0 by default). */
244 uint8_t revision;
245
246 /* Extension flags */
247 uint8_t ext_flags;
248
249 uint16_t family;
250
251 /* Size of match data. */
252 size_t size;
253
254 /* Size of match data relevant for userspace comparison purposes */
255 size_t userspacesize;
256
257 /* Function which prints out usage message. */
258 void (*help)(void);
259
260 /* Initialize the match. */
261 void (*init)(struct xt_entry_match *m);
262
263 /* Function which parses command options; returns true if it
264 ate an option */
265 /* entry is struct ipt_entry for example */
266 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
267 const void *entry,
268 struct xt_entry_match **match);
269
270 /* Final check; exit if not ok. */
271 void (*final_check)(unsigned int flags);
272
273 /* Prints out the match iff non-NULL: put space at end */
274 /* ip is struct ipt_ip * for example */
275 void (*print)(const void *ip,
276 const struct xt_entry_match *match, int numeric);
277
278 /* Saves the match info in parsable form to stdout. */
279 /* ip is struct ipt_ip * for example */
280 void (*save)(const void *ip, const struct xt_entry_match *match);
281
282 /* Print match name or alias */
283 const char *(*alias)(const struct xt_entry_match *match);
284
285 /* Pointer to list of extra command-line options */
286 const struct option *extra_opts;
287
288 /* New parser */
289 void (*x6_parse)(struct xt_option_call *);
290 void (*x6_fcheck)(struct xt_fcheck_call *);
291 const struct xt_option_entry *x6_options;
292
293 /* Translate iptables to nft */
294 int (*xlate)(struct xt_xlate *xl,
295 const struct xt_xlate_mt_params *params);
296
297 /* Size of per-extension instance extra "global" scratch space */
298 size_t udata_size;
299
300 /* Ignore these men behind the curtain: */
301 void *udata;
302 unsigned int option_offset;
303 struct xt_entry_match *m;
304 unsigned int mflags;
305 unsigned int loaded; /* simulate loading so options are merged properly */
306 };
307
308 struct xtables_target {
309 /*
310 * ABI/API version this module requires. Must be first member,
311 * as the rest of this struct may be subject to ABI changes.
312 */
313 const char *version;
314
315 struct xtables_target *next;
316
317
318 const char *name;
319
320 /* Real target behind this, if any. */
321 const char *real_name;
322
323 /* Revision of target (0 by default). */
324 uint8_t revision;
325
326 /* Extension flags */
327 uint8_t ext_flags;
328
329 uint16_t family;
330
331
332 /* Size of target data. */
333 size_t size;
334
335 /* Size of target data relevant for userspace comparison purposes */
336 size_t userspacesize;
337
338 /* Function which prints out usage message. */
339 void (*help)(void);
340
341 /* Initialize the target. */
342 void (*init)(struct xt_entry_target *t);
343
344 /* Function which parses command options; returns true if it
345 ate an option */
346 /* entry is struct ipt_entry for example */
347 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
348 const void *entry,
349 struct xt_entry_target **targetinfo);
350
351 /* Final check; exit if not ok. */
352 void (*final_check)(unsigned int flags);
353
354 /* Prints out the target iff non-NULL: put space at end */
355 void (*print)(const void *ip,
356 const struct xt_entry_target *target, int numeric);
357
358 /* Saves the targinfo in parsable form to stdout. */
359 void (*save)(const void *ip,
360 const struct xt_entry_target *target);
361
362 /* Print target name or alias */
363 const char *(*alias)(const struct xt_entry_target *target);
364
365 /* Pointer to list of extra command-line options */
366 const struct option *extra_opts;
367
368 /* New parser */
369 void (*x6_parse)(struct xt_option_call *);
370 void (*x6_fcheck)(struct xt_fcheck_call *);
371 const struct xt_option_entry *x6_options;
372
373 /* Translate iptables to nft */
374 int (*xlate)(struct xt_xlate *xl,
375 const struct xt_xlate_tg_params *params);
376
377 size_t udata_size;
378
379 /* Ignore these men behind the curtain: */
380 void *udata;
381 unsigned int option_offset;
382 struct xt_entry_target *t;
383 unsigned int tflags;
384 unsigned int used;
385 unsigned int loaded; /* simulate loading so options are merged properly */
386 };
387
388 struct xtables_rule_match {
389 struct xtables_rule_match *next;
390 struct xtables_match *match;
391 /* Multiple matches of the same type: the ones before
392 the current one are completed from parsing point of view */
393 bool completed;
394 };
395
396 /**
397 * struct xtables_pprot -
398 *
399 * A few hardcoded protocols for 'all' and in case the user has no
400 * /etc/protocols.
401 */
402 struct xtables_pprot {
403 const char *name;
404 uint8_t num;
405 };
406
407 enum xtables_tryload {
408 XTF_DONT_LOAD,
409 XTF_DURING_LOAD,
410 XTF_TRY_LOAD,
411 XTF_LOAD_MUST_SUCCEED,
412 };
413
414 enum xtables_exittype {
415 OTHER_PROBLEM = 1,
416 PARAMETER_PROBLEM,
417 VERSION_PROBLEM,
418 RESOURCE_PROBLEM,
419 XTF_ONLY_ONCE,
420 XTF_NO_INVERT,
421 XTF_BAD_VALUE,
422 XTF_ONE_ACTION,
423 };
424
425 struct xtables_globals
426 {
427 unsigned int option_offset;
428 const char *program_name, *program_version;
429 struct option *orig_opts;
430 struct option *opts;
431 void (*exit_err)(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3)));
432 int (*compat_rev)(const char *name, uint8_t rev, int opt);
433 };
434
435 #define XT_GETOPT_TABLEEND {.name = NULL, .has_arg = false}
436
437 /*
438 * enum op-
439 *
440 * For writing clean nftables translations code
441 */
442 enum xt_op {
443 XT_OP_EQ,
444 XT_OP_NEQ,
445 XT_OP_MAX,
446 };
447
448 #ifdef __cplusplus
449 extern "C" {
450 #endif
451
452 extern const char *xtables_modprobe_program;
453 extern struct xtables_match *xtables_matches;
454 extern struct xtables_target *xtables_targets;
455
456 extern void xtables_init(void);
457 extern void xtables_fini(void);
458 extern void xtables_set_nfproto(uint8_t);
459 extern void *xtables_calloc(size_t, size_t);
460 extern void *xtables_malloc(size_t);
461 extern void *xtables_realloc(void *, size_t);
462 char *xtables_strdup(const char *);
463
464 extern int xtables_insmod(const char *, const char *, bool);
465 extern int xtables_load_ko(const char *, bool);
466 extern int xtables_set_params(struct xtables_globals *xtp);
467 extern void xtables_free_opts(int reset_offset);
468 extern struct option *xtables_merge_options(struct option *origopts,
469 struct option *oldopts, const struct option *newopts,
470 unsigned int *option_offset);
471
472 extern int xtables_init_all(struct xtables_globals *xtp, uint8_t nfproto);
473 extern struct xtables_match *xtables_find_match(const char *name,
474 enum xtables_tryload, struct xtables_rule_match **match);
475 extern struct xtables_match *xtables_find_match_revision(const char *name,
476 enum xtables_tryload tryload, struct xtables_match *match,
477 int revision);
478 extern struct xtables_target *xtables_find_target(const char *name,
479 enum xtables_tryload);
480 struct xtables_target *xtables_find_target_revision(const char *name,
481 enum xtables_tryload tryload, struct xtables_target *target,
482 int revision);
483 extern int xtables_compatible_revision(const char *name, uint8_t revision,
484 int opt);
485
486 extern void xtables_rule_matches_free(struct xtables_rule_match **matches);
487
488 /* Your shared library should call one of these. */
489 extern void xtables_register_match(struct xtables_match *me);
490 extern void xtables_register_matches(struct xtables_match *, unsigned int);
491 extern void xtables_register_target(struct xtables_target *me);
492 extern void xtables_register_targets(struct xtables_target *, unsigned int);
493
494 extern bool xtables_strtoul(const char *, char **, uintmax_t *,
495 uintmax_t, uintmax_t);
496 extern bool xtables_strtoui(const char *, char **, unsigned int *,
497 unsigned int, unsigned int);
498 extern int xtables_service_to_port(const char *name, const char *proto);
499 extern uint16_t xtables_parse_port(const char *port, const char *proto);
500 extern void
501 xtables_parse_interface(const char *arg, char *vianame, unsigned char *mask);
502
503 /* this is a special 64bit data type that is 8-byte aligned */
504 #define aligned_u64 uint64_t __attribute__((aligned(8)))
505
506 extern struct xtables_globals *xt_params;
507 #define xtables_error (xt_params->exit_err)
508
509 extern void xtables_param_act(unsigned int, const char *, ...);
510
511 extern const char *xtables_ipaddr_to_numeric(const struct in_addr *);
512 extern const char *xtables_ipaddr_to_anyname(const struct in_addr *);
513 extern const char *xtables_ipmask_to_numeric(const struct in_addr *);
514 extern struct in_addr *xtables_numeric_to_ipaddr(const char *);
515 extern struct in_addr *xtables_numeric_to_ipmask(const char *);
516 extern int xtables_ipmask_to_cidr(const struct in_addr *);
517 extern void xtables_ipparse_any(const char *, struct in_addr **,
518 struct in_addr *, unsigned int *);
519 extern void xtables_ipparse_multiple(const char *, struct in_addr **,
520 struct in_addr **, unsigned int *);
521
522 extern struct in6_addr *xtables_numeric_to_ip6addr(const char *);
523 extern const char *xtables_ip6addr_to_numeric(const struct in6_addr *);
524 extern const char *xtables_ip6addr_to_anyname(const struct in6_addr *);
525 extern const char *xtables_ip6mask_to_numeric(const struct in6_addr *);
526 extern int xtables_ip6mask_to_cidr(const struct in6_addr *);
527 extern void xtables_ip6parse_any(const char *, struct in6_addr **,
528 struct in6_addr *, unsigned int *);
529 extern void xtables_ip6parse_multiple(const char *, struct in6_addr **,
530 struct in6_addr **, unsigned int *);
531
532 /* Absolute file name for network data base files. */
533 #define XT_PATH_ETHERTYPES "/etc/ethertypes"
534
535 struct xt_ethertypeent {
536 char *e_name; /* Official ethernet type name. */
537 char **e_aliases; /* Alias list. */
538 int e_ethertype; /* Ethernet type number. */
539 };
540
541 extern struct xt_ethertypeent *xtables_getethertypebyname(const char *name);
542 extern struct xt_ethertypeent *xtables_getethertypebynumber(int ethertype);
543
544 /**
545 * Print the specified value to standard output, quoting dangerous
546 * characters if required.
547 */
548 extern void xtables_save_string(const char *value);
549
550 #define FMT_NUMERIC 0x0001
551 #define FMT_NOCOUNTS 0x0002
552 #define FMT_KILOMEGAGIGA 0x0004
553 #define FMT_OPTIONS 0x0008
554 #define FMT_NOTABLE 0x0010
555 #define FMT_NOTARGET 0x0020
556 #define FMT_VIA 0x0040
557 #define FMT_NONEWLINE 0x0080
558 #define FMT_LINENUMBERS 0x0100
559 #define FMT_EBT_SAVE 0x0200
560 #define FMT_C_COUNTS 0x0400
561
562 #define FMT_PRINT_RULE (FMT_NOCOUNTS | FMT_OPTIONS | FMT_VIA \
563 | FMT_NUMERIC | FMT_NOTABLE)
564 #define FMT(tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab))
565
566 extern void xtables_print_num(uint64_t number, unsigned int format);
567 extern int xtables_parse_mac_and_mask(const char *from, void *to, void *mask);
568 extern int xtables_print_well_known_mac_and_mask(const void *mac,
569 const void *mask);
570 extern void xtables_print_mac(const unsigned char *macaddress);
571 extern void xtables_print_mac_and_mask(const unsigned char *mac,
572 const unsigned char *mask);
573
574 extern void xtables_parse_val_mask(struct xt_option_call *cb,
575 unsigned int *val, unsigned int *mask,
576 const struct xtables_lmap *lmap);
577
xtables_parse_mark_mask(struct xt_option_call * cb,unsigned int * mark,unsigned int * mask)578 static inline void xtables_parse_mark_mask(struct xt_option_call *cb,
579 unsigned int *mark,
580 unsigned int *mask)
581 {
582 xtables_parse_val_mask(cb, mark, mask, NULL);
583 }
584
585 extern void xtables_print_val_mask(unsigned int val, unsigned int mask,
586 const struct xtables_lmap *lmap);
587
xtables_print_mark_mask(unsigned int mark,unsigned int mask)588 static inline void xtables_print_mark_mask(unsigned int mark,
589 unsigned int mask)
590 {
591 xtables_print_val_mask(mark, mask, NULL);
592 }
593
594 extern const struct xtables_pprot xtables_chain_protos[];
595 extern uint16_t xtables_parse_protocol(const char *s);
596
597 /* kernel revision handling */
598 extern int kernel_version;
599 extern void get_kernel_version(void);
600 #define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
601 #define LINUX_VERSION_MAJOR(x) (((x)>>16) & 0xFF)
602 #define LINUX_VERSION_MINOR(x) (((x)>> 8) & 0xFF)
603 #define LINUX_VERSION_PATCH(x) ( (x) & 0xFF)
604
605 /* xtoptions.c */
606 extern void xtables_option_metavalidate(const char *,
607 const struct xt_option_entry *);
608 extern struct option *xtables_options_xfrm(struct option *, struct option *,
609 const struct xt_option_entry *,
610 unsigned int *);
611 extern void xtables_option_parse(struct xt_option_call *);
612 extern void xtables_option_tpcall(unsigned int, char **, bool,
613 struct xtables_target *, void *);
614 extern void xtables_option_mpcall(unsigned int, char **, bool,
615 struct xtables_match *, void *);
616 extern void xtables_option_tfcall(struct xtables_target *);
617 extern void xtables_option_mfcall(struct xtables_match *);
618 extern void xtables_options_fcheck(const char *, unsigned int,
619 const struct xt_option_entry *);
620
621 extern struct xtables_lmap *xtables_lmap_init(const char *);
622 extern void xtables_lmap_free(struct xtables_lmap *);
623 extern int xtables_lmap_name2id(const struct xtables_lmap *, const char *);
624 extern const char *xtables_lmap_id2name(const struct xtables_lmap *, int);
625
626 /* xlate infrastructure */
627 struct xt_xlate *xt_xlate_alloc(int size);
628 void xt_xlate_free(struct xt_xlate *xl);
629 void xt_xlate_add(struct xt_xlate *xl, const char *fmt, ...) __attribute__((format(printf,2,3)));
630 void xt_xlate_add_nospc(struct xt_xlate *xl, const char *fmt, ...) __attribute__((format(printf,2,3)));
631 #define xt_xlate_rule_add xt_xlate_add
632 #define xt_xlate_rule_add_nospc xt_xlate_add_nospc
633 void xt_xlate_set_add(struct xt_xlate *xl, const char *fmt, ...) __attribute__((format(printf,2,3)));
634 void xt_xlate_set_add_nospc(struct xt_xlate *xl, const char *fmt, ...) __attribute__((format(printf,2,3)));
635 void xt_xlate_add_comment(struct xt_xlate *xl, const char *comment);
636 const char *xt_xlate_get_comment(struct xt_xlate *xl);
637 void xl_xlate_set_family(struct xt_xlate *xl, uint8_t family);
638 uint8_t xt_xlate_get_family(struct xt_xlate *xl);
639 const char *xt_xlate_get(struct xt_xlate *xl);
640 #define xt_xlate_rule_get xt_xlate_get
641 const char *xt_xlate_set_get(struct xt_xlate *xl);
642
643 /* informed target lookups */
644 void xtables_announce_chain(const char *name);
645
646 #ifdef XTABLES_INTERNAL
647
648 /* Shipped modules rely on this... */
649
650 # ifndef ARRAY_SIZE
651 # define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
652 # endif
653
654 #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
655 # ifdef _INIT
656 # undef _init
657 # define _init _INIT
658 # endif
659 extern void init_extensions(void);
660 extern void init_extensions4(void);
661 extern void init_extensions6(void);
662 extern void init_extensionsa(void);
663 extern void init_extensionsb(void);
664 #else
665 # define _init __attribute__((constructor)) _INIT
666 # define EMPTY_FUNC_DEF(x) static inline void x(void) {}
667 EMPTY_FUNC_DEF(init_extensions)
668 EMPTY_FUNC_DEF(init_extensions4)
669 EMPTY_FUNC_DEF(init_extensions6)
670 EMPTY_FUNC_DEF(init_extensionsa)
671 EMPTY_FUNC_DEF(init_extensionsb)
672 # undef EMPTY_FUNC_DEF
673 #endif
674
675 extern void _init(void);
676
677 /**
678 * xtables_afinfo - protocol family dependent information
679 * @kmod: kernel module basename (e.g. "ip_tables")
680 * @proc_exists: file which exists in procfs when module already loaded
681 * @libprefix: prefix of .so library name (e.g. "libipt_")
682 * @family: nfproto family
683 * @ipproto: used by setsockopt (e.g. IPPROTO_IP)
684 * @so_rev_match: optname to check revision support of match
685 * @so_rev_target: optname to check revision support of target
686 */
687 struct xtables_afinfo {
688 const char *kmod;
689 const char *proc_exists;
690 const char *libprefix;
691 uint8_t family;
692 uint8_t ipproto;
693 int so_rev_match;
694 int so_rev_target;
695 };
696
697 extern const struct xtables_afinfo *afinfo;
698
699 /* base offset of merged extensions' consecutive options */
700 #define XT_OPTION_OFFSET_SCALE 256
701
702 #endif /* XTABLES_INTERNAL */
703
704 #ifdef __cplusplus
705 } /* extern "C" */
706 #endif
707
708 #endif /* _XTABLES_H */
709