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