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