blob: c35a6e6dcc11bc0fc6c617d38836d68161894d4d [file] [log] [blame]
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +00001#ifndef _XTABLES_H
2#define _XTABLES_H
3
Jan Engelhardtdacafa52009-01-27 20:56:23 +01004/*
5 * Changing any structs/functions may incur a needed change
6 * in libxtables_vcurrent/vage too.
7 */
8
Jan Engelhardtef18e812008-08-04 12:47:48 +02009#include <sys/socket.h> /* PF_* */
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000010#include <sys/types.h>
Stephen Hemminger71886fb2009-02-25 08:25:17 +010011#include <limits.h>
Jan Engelhardtef18e812008-08-04 12:47:48 +020012#include <stdbool.h>
Jan Engelhardtaa37acc2011-02-07 04:00:50 +010013#include <stddef.h>
14#include <stdint.h>
Jan Engelhardt03d99482008-11-18 12:27:54 +010015#include <netinet/in.h>
Jan Engelhardtef18e812008-08-04 12:47:48 +020016#include <net/if.h>
Jan Engelhardt5e9eaed2007-12-17 13:12:01 +000017#include <linux/types.h>
Jan Engelhardt03d99482008-11-18 12:27:54 +010018#include <linux/netfilter.h>
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000019#include <linux/netfilter/x_tables.h>
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000020
Yasuyuki KOZAKAI5cd1ff52007-07-24 05:55:12 +000021#ifndef IPPROTO_SCTP
22#define IPPROTO_SCTP 132
23#endif
24#ifndef IPPROTO_DCCP
25#define IPPROTO_DCCP 33
26#endif
Jan Engelhardt1de7edf2009-01-30 05:38:11 +010027#ifndef IPPROTO_MH
28# define IPPROTO_MH 135
29#endif
Yasuyuki KOZAKAI5cd1ff52007-07-24 05:55:12 +000030#ifndef IPPROTO_UDPLITE
31#define IPPROTO_UDPLITE 136
32#endif
33
Jan Engelhardtdf60a302012-08-31 03:59:07 +020034#include <xtables-version.h>
Jan Engelhardt493c7122008-04-15 11:15:16 +020035
Jan Engelhardtef18e812008-08-04 12:47:48 +020036struct in_addr;
37
Jan Engelhardtaa37acc2011-02-07 04:00:50 +010038/*
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/**
Jan Engelhardtd7282412011-05-04 16:41:13 +020048 * 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 *
Jan Engelhardtaa37acc2011-02-07 04:00:50 +010054 * %XTTYPE_NONE: option takes no argument
Jan Engelhardta93142d2011-02-16 01:22:25 +010055 * %XTTYPE_UINT*: standard integer
Jan Engelhardt04bb9882011-02-27 23:41:10 +010056 * %XTTYPE_UINT*RC: colon-separated range of standard integers
Jan Engelhardtf012b3c2011-05-02 18:09:59 +020057 * %XTTYPE_DOUBLE: double-precision floating point number
Jan Engelhardt4a0a1762011-02-15 22:09:21 +010058 * %XTTYPE_STRING: arbitrary string
Jan Engelhardt61cc52b2011-04-29 01:25:14 +020059 * %XTTYPE_TOSMASK: 8-bit TOS value with optional mask
Jan Engelhardtd25e2172011-03-06 14:57:44 +010060 * %XTTYPE_MARKMASK32: 32-bit mark with optional mask
Jan Engelhardt41a4cea2011-02-15 22:10:48 +010061 * %XTTYPE_SYSLOGLEVEL: syslog level by name or number
Jan Engelhardtd7282412011-05-04 16:41:13 +020062 * %XTTYPE_HOST: one host or address (ptr: union nf_inet_addr)
Jan Engelhardt66266ab2011-05-05 14:19:25 +020063 * %XTTYPE_HOSTMASK: one host or address, with an optional prefix length
64 * (ptr: union nf_inet_addr; only host portion is stored)
Jan Engelhardt170cf492011-05-07 12:56:39 +020065 * %XTTYPE_PROTOCOL: protocol number/name from /etc/protocols (ptr: uint8_t)
Jan Engelhardtc02c92d2011-05-18 22:48:51 +020066 * %XTTYPE_PORT: 16-bit port name or number (supports %XTOPT_NBO)
67 * %XTTYPE_PORTRC: colon-separated port range (names acceptable),
68 * (supports %XTOPT_NBO)
Jan Engelhardtfa9b7592011-05-04 17:25:54 +020069 * %XTTYPE_PLEN: prefix length
Jan Engelhardtd7282412011-05-04 16:41:13 +020070 * %XTTYPE_PLENMASK: prefix length (ptr: union nf_inet_addr)
Jan Engelhardtcb225e22011-05-08 13:31:19 +020071 * %XTTYPE_ETHERMAC: Ethernet MAC address in hex form
Jan Engelhardtaa37acc2011-02-07 04:00:50 +010072 */
73enum xt_option_type {
74 XTTYPE_NONE,
Jan Engelhardtdfe99f12011-02-27 19:03:28 +010075 XTTYPE_UINT8,
Jan Engelhardt0eff54b2011-03-06 17:42:51 +010076 XTTYPE_UINT16,
Jan Engelhardta93142d2011-02-16 01:22:25 +010077 XTTYPE_UINT32,
Jan Engelhardt8b5bdea2011-03-06 16:56:53 +010078 XTTYPE_UINT64,
Jan Engelhardt8bf513a2011-03-06 17:09:19 +010079 XTTYPE_UINT8RC,
Jan Engelhardt564eaf42011-03-06 16:59:23 +010080 XTTYPE_UINT16RC,
Jan Engelhardt04bb9882011-02-27 23:41:10 +010081 XTTYPE_UINT32RC,
Jan Engelhardtbc438c42011-03-06 17:13:54 +010082 XTTYPE_UINT64RC,
Jan Engelhardtf012b3c2011-05-02 18:09:59 +020083 XTTYPE_DOUBLE,
Jan Engelhardt4a0a1762011-02-15 22:09:21 +010084 XTTYPE_STRING,
Jan Engelhardt61cc52b2011-04-29 01:25:14 +020085 XTTYPE_TOSMASK,
Jan Engelhardtd25e2172011-03-06 14:57:44 +010086 XTTYPE_MARKMASK32,
Jan Engelhardt41a4cea2011-02-15 22:10:48 +010087 XTTYPE_SYSLOGLEVEL,
Jan Engelhardtd7282412011-05-04 16:41:13 +020088 XTTYPE_HOST,
Jan Engelhardt66266ab2011-05-05 14:19:25 +020089 XTTYPE_HOSTMASK,
Jan Engelhardt170cf492011-05-07 12:56:39 +020090 XTTYPE_PROTOCOL,
Jan Engelhardtb8592fa2011-02-14 15:12:50 +010091 XTTYPE_PORT,
Jan Engelhardtf30231a2011-04-17 13:33:50 +020092 XTTYPE_PORTRC,
Jan Engelhardtfa9b7592011-05-04 17:25:54 +020093 XTTYPE_PLEN,
Jan Engelhardte8b42fe2011-05-02 02:13:16 +020094 XTTYPE_PLENMASK,
Jan Engelhardtcb225e22011-05-08 13:31:19 +020095 XTTYPE_ETHERMAC,
Jan Engelhardtaa37acc2011-02-07 04:00:50 +010096};
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
Jan Engelhardtc02c92d2011-05-18 22:48:51 +0200103 * %XTOPT_NBO: store value in network-byte order
104 * (only certain XTTYPEs recognize this)
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100105 */
106enum xt_option_flags {
107 XTOPT_INVERT = 1 << 0,
108 XTOPT_MAND = 1 << 1,
109 XTOPT_MULTI = 1 << 2,
110 XTOPT_PUT = 1 << 3,
Jan Engelhardtc02c92d2011-05-18 22:48:51 +0200111 XTOPT_NBO = 1 << 4,
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100112};
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
Jan Engelhardtd78254d2011-02-27 17:38:34 +0100123 * @min: lowest allowed value (for singular integral types)
124 * @max: highest allowed value (for singular integral types)
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100125 */
126struct 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;
Jan Engelhardtd78254d2011-02-27 17:38:34 +0100132 unsigned int min, max;
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100133};
134
135/**
136 * @arg: input from command line
137 * @ext_name: name of extension currently being processed
138 * @entry: current option being processed
Jan Engelhardt2dba6762011-06-18 21:34:25 +0200139 * @data: per-extension kernel data block
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100140 * @xflags: options of the extension that have been used
141 * @invert: whether option was used with !
Jan Engelhardt04bb9882011-02-27 23:41:10 +0100142 * @nvals: number of results in uXX_multi
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100143 * @val: parsed result
Jan Engelhardt2dba6762011-06-18 21:34:25 +0200144 * @udata: per-extension private scratch area
145 * (cf. xtables_{match,target}->udata_size)
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100146 */
147struct 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;
Jan Engelhardt04bb9882011-02-27 23:41:10 +0100153 uint8_t nvals;
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100154 union {
Jan Engelhardt170cf492011-05-07 12:56:39 +0200155 uint8_t u8, u8_range[2], syslog_level, protocol;
Jan Engelhardtf30231a2011-04-17 13:33:50 +0200156 uint16_t u16, u16_range[2], port, port_range[2];
Jan Engelhardt04bb9882011-02-27 23:41:10 +0100157 uint32_t u32, u32_range[2];
Jan Engelhardtbc438c42011-03-06 17:13:54 +0100158 uint64_t u64, u64_range[2];
Jan Engelhardtf012b3c2011-05-02 18:09:59 +0200159 double dbl;
Jan Engelhardtd7282412011-05-04 16:41:13 +0200160 struct {
161 union nf_inet_addr haddr, hmask;
162 uint8_t hlen;
163 };
Jan Engelhardtd25e2172011-03-06 14:57:44 +0100164 struct {
Jan Engelhardt61cc52b2011-04-29 01:25:14 +0200165 uint8_t tos_value, tos_mask;
166 };
167 struct {
Jan Engelhardtd25e2172011-03-06 14:57:44 +0100168 uint32_t mark, mask;
169 };
Jan Engelhardtcb225e22011-05-08 13:31:19 +0200170 uint8_t ethermac[6];
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100171 } val;
Jan Engelhardt87a34d72011-05-07 00:15:49 +0200172 /* Wished for a world where the ones below were gone: */
Jan Engelhardt33d18082011-03-06 18:11:58 +0100173 union {
174 struct xt_entry_match **match;
175 struct xt_entry_target **target;
176 };
Jan Engelhardt87a34d72011-05-07 00:15:49 +0200177 void *xt_entry;
Jan Engelhardt2dba6762011-06-18 21:34:25 +0200178 void *udata;
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100179};
180
Jan Engelhardt3af739b2011-02-10 16:57:37 +0100181/**
182 * @ext_name: name of extension currently being processed
Jan Engelhardt2dba6762011-06-18 21:34:25 +0200183 * @data: per-extension (kernel) data block
184 * @udata: per-extension private scratch area
185 * (cf. xtables_{match,target}->udata_size)
Jan Engelhardt3af739b2011-02-10 16:57:37 +0100186 * @xflags: options of the extension that have been used
187 */
188struct xt_fcheck_call {
189 const char *ext_name;
Jan Engelhardt2dba6762011-06-18 21:34:25 +0200190 void *data, *udata;
Jan Engelhardt3af739b2011-02-10 16:57:37 +0100191 unsigned int xflags;
192};
193
Jan Engelhardt2e0ec4f2011-03-06 16:24:43 +0100194/**
195 * A "linear"/linked-list based name<->id map, for files similar to
196 * /etc/iproute2/.
197 */
198struct xtables_lmap {
199 char *name;
200 int id;
201 struct xtables_lmap *next;
202};
203
Jozsef Kadlecsikefcdba42013-01-28 21:15:27 +0100204enum xtables_ext_flags {
205 XTABLES_EXT_ALIAS = 1 << 0,
206};
207
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000208/* Include file for additions: new matches and targets. */
209struct xtables_match
210{
Jan Engelhardtc4edfa62009-03-30 00:44:46 +0200211 /*
212 * ABI/API version this module requires. Must be first member,
213 * as the rest of this struct may be subject to ABI changes.
214 */
215 const char *version;
216
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000217 struct xtables_match *next;
218
Jan Engelhardtef18e812008-08-04 12:47:48 +0200219 const char *name;
Jan Engelhardtc436dad2012-09-27 23:48:25 +0200220 const char *real_name;
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000221
222 /* Revision of match (0 by default). */
223 u_int8_t revision;
224
Jozsef Kadlecsikefcdba42013-01-28 21:15:27 +0100225 /* Extension flags */
226 u_int8_t ext_flags;
227
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000228 u_int16_t family;
229
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000230 /* Size of match data. */
231 size_t size;
232
233 /* Size of match data relevent for userspace comparison purposes */
234 size_t userspacesize;
235
236 /* Function which prints out usage message. */
237 void (*help)(void);
238
239 /* Initialize the match. */
Peter Rileyea146a92007-09-02 13:09:07 +0000240 void (*init)(struct xt_entry_match *m);
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000241
242 /* Function which parses command options; returns true if it
243 ate an option */
244 /* entry is struct ipt_entry for example */
245 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
246 const void *entry,
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000247 struct xt_entry_match **match);
248
249 /* Final check; exit if not ok. */
250 void (*final_check)(unsigned int flags);
251
252 /* Prints out the match iff non-NULL: put space at end */
253 /* ip is struct ipt_ip * for example */
254 void (*print)(const void *ip,
255 const struct xt_entry_match *match, int numeric);
256
257 /* Saves the match info in parsable form to stdout. */
258 /* ip is struct ipt_ip * for example */
259 void (*save)(const void *ip, const struct xt_entry_match *match);
260
Jozsef Kadlecsikefcdba42013-01-28 21:15:27 +0100261 /* Print match name or alias */
262 const char *(*alias)(const struct xt_entry_match *match);
263
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000264 /* Pointer to list of extra command-line options */
265 const struct option *extra_opts;
266
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100267 /* New parser */
268 void (*x6_parse)(struct xt_option_call *);
Jan Engelhardt3af739b2011-02-10 16:57:37 +0100269 void (*x6_fcheck)(struct xt_fcheck_call *);
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100270 const struct xt_option_entry *x6_options;
271
Jan Engelhardt2dba6762011-06-18 21:34:25 +0200272 /* Size of per-extension instance extra "global" scratch space */
273 size_t udata_size;
274
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000275 /* Ignore these men behind the curtain: */
Jan Engelhardt2dba6762011-06-18 21:34:25 +0200276 void *udata;
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000277 unsigned int option_offset;
278 struct xt_entry_match *m;
279 unsigned int mflags;
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000280 unsigned int loaded; /* simulate loading so options are merged properly */
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000281};
282
283struct xtables_target
284{
Jan Engelhardtc4edfa62009-03-30 00:44:46 +0200285 /*
286 * ABI/API version this module requires. Must be first member,
287 * as the rest of this struct may be subject to ABI changes.
288 */
289 const char *version;
290
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000291 struct xtables_target *next;
292
Jan Engelhardtc4edfa62009-03-30 00:44:46 +0200293
Jan Engelhardtef18e812008-08-04 12:47:48 +0200294 const char *name;
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000295
Jan Engelhardtcd2f9bd2012-09-04 05:24:47 +0200296 /* Real target behind this, if any. */
297 const char *real_name;
298
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000299 /* Revision of target (0 by default). */
300 u_int8_t revision;
301
Jozsef Kadlecsikefcdba42013-01-28 21:15:27 +0100302 /* Extension flags */
303 u_int8_t ext_flags;
304
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000305 u_int16_t family;
306
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000307
308 /* Size of target data. */
309 size_t size;
310
311 /* Size of target data relevent for userspace comparison purposes */
312 size_t userspacesize;
313
314 /* Function which prints out usage message. */
315 void (*help)(void);
316
317 /* Initialize the target. */
Peter Rileyea146a92007-09-02 13:09:07 +0000318 void (*init)(struct xt_entry_target *t);
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000319
320 /* Function which parses command options; returns true if it
321 ate an option */
322 /* entry is struct ipt_entry for example */
323 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
324 const void *entry,
325 struct xt_entry_target **targetinfo);
326
327 /* Final check; exit if not ok. */
328 void (*final_check)(unsigned int flags);
329
330 /* Prints out the target iff non-NULL: put space at end */
331 void (*print)(const void *ip,
332 const struct xt_entry_target *target, int numeric);
333
334 /* Saves the targinfo in parsable form to stdout. */
335 void (*save)(const void *ip,
336 const struct xt_entry_target *target);
337
Jozsef Kadlecsikefcdba42013-01-28 21:15:27 +0100338 /* Print target name or alias */
339 const char *(*alias)(const struct xt_entry_target *target);
340
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000341 /* Pointer to list of extra command-line options */
Jan Engelhardt33653322007-07-30 13:20:43 +0000342 const struct option *extra_opts;
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000343
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100344 /* New parser */
345 void (*x6_parse)(struct xt_option_call *);
Jan Engelhardt3af739b2011-02-10 16:57:37 +0100346 void (*x6_fcheck)(struct xt_fcheck_call *);
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100347 const struct xt_option_entry *x6_options;
348
Jan Engelhardt2dba6762011-06-18 21:34:25 +0200349 size_t udata_size;
350
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000351 /* Ignore these men behind the curtain: */
Jan Engelhardt2dba6762011-06-18 21:34:25 +0200352 void *udata;
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000353 unsigned int option_offset;
354 struct xt_entry_target *t;
355 unsigned int tflags;
356 unsigned int used;
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000357 unsigned int loaded; /* simulate loading so options are merged properly */
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000358};
359
Jan Engelhardt2338efd2009-01-27 15:23:01 +0100360struct xtables_rule_match {
361 struct xtables_rule_match *next;
362 struct xtables_match *match;
363 /* Multiple matches of the same type: the ones before
364 the current one are completed from parsing point of view */
365 bool completed;
366};
367
Jan Engelhardt1de7edf2009-01-30 05:38:11 +0100368/**
369 * struct xtables_pprot -
370 *
371 * A few hardcoded protocols for 'all' and in case the user has no
372 * /etc/protocols.
373 */
374struct xtables_pprot {
375 const char *name;
376 u_int8_t num;
377};
378
Jan Engelhardt2338efd2009-01-27 15:23:01 +0100379enum xtables_tryload {
380 XTF_DONT_LOAD,
381 XTF_DURING_LOAD,
382 XTF_TRY_LOAD,
383 XTF_LOAD_MUST_SUCCEED,
384};
385
Jan Engelhardta41545c2009-01-27 21:27:19 +0100386enum xtables_exittype {
387 OTHER_PROBLEM = 1,
388 PARAMETER_PROBLEM,
389 VERSION_PROBLEM,
390 RESOURCE_PROBLEM,
391 XTF_ONLY_ONCE,
392 XTF_NO_INVERT,
393 XTF_BAD_VALUE,
394 XTF_ONE_ACTION,
395};
396
Jamal Hadi Salim40a83432009-02-11 13:02:21 +0100397struct xtables_globals
398{
399 unsigned int option_offset;
Jan Engelhardt41f03ba2009-02-11 16:13:47 +0100400 const char *program_name, *program_version;
Jamal Hadi Salim139b3fe2009-02-12 11:43:01 -0500401 struct option *orig_opts;
Jamal Hadi Salim40a83432009-02-11 13:02:21 +0100402 struct option *opts;
Jamal Hadi Salim8b7baeb2009-02-11 13:05:43 +0100403 void (*exit_err)(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3)));
Jamal Hadi Salim40a83432009-02-11 13:02:21 +0100404};
405
Jan Engelhardt104fb312011-05-07 04:01:25 +0200406#define XT_GETOPT_TABLEEND {.name = NULL, .has_arg = false}
Jan Engelhardt32b8e612010-07-23 21:16:14 +0200407
Jan Engelhardt771871e2009-05-22 11:46:55 +0200408#ifdef __cplusplus
409extern "C" {
410#endif
411
Jan Engelhardtc021c3c2009-01-27 15:10:05 +0100412extern const char *xtables_modprobe_program;
Jan Engelhardt2338efd2009-01-27 15:23:01 +0100413extern struct xtables_match *xtables_matches;
414extern struct xtables_target *xtables_targets;
Jan Engelhardtc021c3c2009-01-27 15:10:05 +0100415
Jan Engelhardt39bf9c82009-01-27 15:59:06 +0100416extern void xtables_init(void);
Jan Engelhardt77f48c22009-02-07 19:59:53 +0100417extern void xtables_set_nfproto(uint8_t);
Jan Engelhardt630ef482009-01-27 14:58:41 +0100418extern void *xtables_calloc(size_t, size_t);
419extern void *xtables_malloc(size_t);
Michael Granzow332e4ac2009-04-09 18:24:36 +0100420extern void *xtables_realloc(void *, size_t);
Jan Engelhardt630ef482009-01-27 14:58:41 +0100421
Jan Engelhardtc021c3c2009-01-27 15:10:05 +0100422extern int xtables_insmod(const char *, const char *, bool);
423extern int xtables_load_ko(const char *, bool);
Jamal Hadi Salim8b7baeb2009-02-11 13:05:43 +0100424extern int xtables_set_params(struct xtables_globals *xtp);
Jamal Hadi Salim139b3fe2009-02-12 11:43:01 -0500425extern void xtables_free_opts(int reset_offset);
Jan Engelhardt710a1322010-11-15 14:39:35 +0100426extern struct option *xtables_merge_options(struct option *origopts,
427 struct option *oldopts, const struct option *newopts,
428 unsigned int *option_offset);
Jan Engelhardtc021c3c2009-01-27 15:10:05 +0100429
Jamal Hadi Salim7e4db2f2009-02-13 09:14:17 -0500430extern int xtables_init_all(struct xtables_globals *xtp, uint8_t nfproto);
Jan Engelhardt2338efd2009-01-27 15:23:01 +0100431extern struct xtables_match *xtables_find_match(const char *name,
432 enum xtables_tryload, struct xtables_rule_match **match);
433extern struct xtables_target *xtables_find_target(const char *name,
434 enum xtables_tryload);
435
Pablo Neira Ayusod1e79222013-01-04 20:27:11 +0100436extern void xtables_rule_matches_free(struct xtables_rule_match **matches);
437
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000438/* Your shared library should call one of these. */
439extern void xtables_register_match(struct xtables_match *me);
Jan Engelhardt9a8fc4f2009-06-25 17:13:46 +0200440extern void xtables_register_matches(struct xtables_match *, unsigned int);
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000441extern void xtables_register_target(struct xtables_target *me);
Jan Engelhardt9a8fc4f2009-06-25 17:13:46 +0200442extern void xtables_register_targets(struct xtables_target *, unsigned int);
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000443
Jan Engelhardt0b7a1402011-05-24 02:30:23 +0200444extern bool xtables_strtoul(const char *, char **, uintmax_t *,
445 uintmax_t, uintmax_t);
Jan Engelhardt5f2922c2009-01-27 18:43:01 +0100446extern bool xtables_strtoui(const char *, char **, unsigned int *,
Jan Engelhardtcd9e7aa2008-01-20 13:18:54 +0000447 unsigned int, unsigned int);
Jan Engelhardtaae6be92009-01-30 04:24:47 +0100448extern int xtables_service_to_port(const char *name, const char *proto);
449extern u_int16_t xtables_parse_port(const char *port, const char *proto);
Yasuyuki KOZAKAI04f8c542007-07-24 05:53:48 +0000450extern void
Jan Engelhardtaae6be92009-01-30 04:24:47 +0100451xtables_parse_interface(const char *arg, char *vianame, unsigned char *mask);
Yasuyuki KOZAKAI04f8c542007-07-24 05:53:48 +0000452
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000453/* this is a special 64bit data type that is 8-byte aligned */
Patrick McHardyc329d6a2007-09-05 14:19:23 +0000454#define aligned_u64 u_int64_t __attribute__((aligned(8)))
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000455
Jamal Hadi Salim8b7baeb2009-02-11 13:05:43 +0100456extern struct xtables_globals *xt_params;
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100457#define xtables_error (xt_params->exit_err)
Jamal Hadi Salim70581922009-02-13 08:36:44 -0500458
Jan Engelhardta41545c2009-01-27 21:27:19 +0100459extern void xtables_param_act(unsigned int, const char *, ...);
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000460
Jan Engelhardte44ea7f2009-01-30 03:55:09 +0100461extern const char *xtables_ipaddr_to_numeric(const struct in_addr *);
462extern const char *xtables_ipaddr_to_anyname(const struct in_addr *);
463extern const char *xtables_ipmask_to_numeric(const struct in_addr *);
Jan Engelhardt1e01b0b2009-01-30 04:20:32 +0100464extern struct in_addr *xtables_numeric_to_ipaddr(const char *);
465extern struct in_addr *xtables_numeric_to_ipmask(const char *);
Pablo Neira Ayusoa96166c2012-07-14 15:39:20 +0200466extern int xtables_ipmask_to_cidr(const struct in_addr *);
Jan Engelhardta0baae82009-01-30 04:32:50 +0100467extern void xtables_ipparse_any(const char *, struct in_addr **,
Jan Engelhardtbd943842008-01-20 13:38:08 +0000468 struct in_addr *, unsigned int *);
Michael Granzow332e4ac2009-04-09 18:24:36 +0100469extern void xtables_ipparse_multiple(const char *, struct in_addr **,
470 struct in_addr **, unsigned int *);
Jan Engelhardt08b16162008-01-20 13:36:08 +0000471
Jan Engelhardt1e01b0b2009-01-30 04:20:32 +0100472extern struct in6_addr *xtables_numeric_to_ip6addr(const char *);
Jan Engelhardte44ea7f2009-01-30 03:55:09 +0100473extern const char *xtables_ip6addr_to_numeric(const struct in6_addr *);
474extern const char *xtables_ip6addr_to_anyname(const struct in6_addr *);
475extern const char *xtables_ip6mask_to_numeric(const struct in6_addr *);
Pablo Neira Ayusoa96166c2012-07-14 15:39:20 +0200476extern int xtables_ip6mask_to_cidr(const struct in6_addr *);
Jan Engelhardta0baae82009-01-30 04:32:50 +0100477extern void xtables_ip6parse_any(const char *, struct in6_addr **,
Jan Engelhardtbd943842008-01-20 13:38:08 +0000478 struct in6_addr *, unsigned int *);
Michael Granzow332e4ac2009-04-09 18:24:36 +0100479extern void xtables_ip6parse_multiple(const char *, struct in6_addr **,
480 struct in6_addr **, unsigned int *);
Jan Engelhardt08b16162008-01-20 13:36:08 +0000481
Max Kellermanna5d09942008-01-29 13:44:34 +0000482/**
483 * Print the specified value to standard output, quoting dangerous
484 * characters if required.
485 */
Jan Engelhardta0baae82009-01-30 04:32:50 +0100486extern void xtables_save_string(const char *value);
Max Kellermanna5d09942008-01-29 13:44:34 +0000487
Pablo Neira Ayuso2f655ed2012-10-29 10:49:42 +0100488#define FMT_NUMERIC 0x0001
489#define FMT_NOCOUNTS 0x0002
490#define FMT_KILOMEGAGIGA 0x0004
491#define FMT_OPTIONS 0x0008
492#define FMT_NOTABLE 0x0010
493#define FMT_NOTARGET 0x0020
494#define FMT_VIA 0x0040
495#define FMT_NONEWLINE 0x0080
496#define FMT_LINENUMBERS 0x0100
497
498#define FMT_PRINT_RULE (FMT_NOCOUNTS | FMT_OPTIONS | FMT_VIA \
499 | FMT_NUMERIC | FMT_NOTABLE)
500#define FMT(tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab))
501
502extern void xtables_print_num(uint64_t number, unsigned int format);
503
Jan Engelhardtb79ec692009-07-23 17:41:21 +0200504#if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000505# ifdef _INIT
506# undef _init
507# define _init _INIT
508# endif
Maciej Żenczykowski9a9694f2011-04-06 13:35:11 -0700509 extern void init_extensions(void);
Maciej Zenczykowski5e8f9472011-04-04 15:32:39 +0200510 extern void init_extensions4(void);
Maciej Zenczykowski49d8c5d2011-04-04 15:33:25 +0200511 extern void init_extensions6(void);
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000512#else
513# define _init __attribute__((constructor)) _INIT
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000514#endif
515
Jan Engelhardt1de7edf2009-01-30 05:38:11 +0100516extern const struct xtables_pprot xtables_chain_protos[];
517extern u_int16_t xtables_parse_protocol(const char *s);
Jan Engelhardt33690a12008-02-11 00:54:00 +0100518
Jan Engelhardtf56b8a82011-09-03 14:27:55 +0200519/* kernel revision handling */
520extern int kernel_version;
521extern void get_kernel_version(void);
522#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
523#define LINUX_VERSION_MAJOR(x) (((x)>>16) & 0xFF)
524#define LINUX_VERSION_MINOR(x) (((x)>> 8) & 0xFF)
525#define LINUX_VERSION_PATCH(x) ( (x) & 0xFF)
526
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100527/* xtoptions.c */
528extern void xtables_option_metavalidate(const char *,
529 const struct xt_option_entry *);
530extern struct option *xtables_options_xfrm(struct option *, struct option *,
531 const struct xt_option_entry *,
532 unsigned int *);
533extern void xtables_option_parse(struct xt_option_call *);
534extern void xtables_option_tpcall(unsigned int, char **, bool,
535 struct xtables_target *, void *);
536extern void xtables_option_mpcall(unsigned int, char **, bool,
537 struct xtables_match *, void *);
Jan Engelhardt3af739b2011-02-10 16:57:37 +0100538extern void xtables_option_tfcall(struct xtables_target *);
539extern void xtables_option_mfcall(struct xtables_match *);
Jan Engelhardtaa37acc2011-02-07 04:00:50 +0100540extern void xtables_options_fcheck(const char *, unsigned int,
541 const struct xt_option_entry *);
542
Jan Engelhardt2e0ec4f2011-03-06 16:24:43 +0100543extern struct xtables_lmap *xtables_lmap_init(const char *);
544extern void xtables_lmap_free(struct xtables_lmap *);
545extern int xtables_lmap_name2id(const struct xtables_lmap *, const char *);
546extern const char *xtables_lmap_id2name(const struct xtables_lmap *, int);
547
Jan Engelhardt33690a12008-02-11 00:54:00 +0100548#ifdef XTABLES_INTERNAL
Jan Engelhardtc02e8082009-02-10 10:40:15 +0100549
550/* Shipped modules rely on this... */
551
Jan Engelhardt1de7edf2009-01-30 05:38:11 +0100552# ifndef ARRAY_SIZE
553# define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
554# endif
Jan Engelhardtc02e8082009-02-10 10:40:15 +0100555
556extern void _init(void);
557
Jan Engelhardt33690a12008-02-11 00:54:00 +0100558#endif
559
Jan Engelhardt771871e2009-05-22 11:46:55 +0200560#ifdef __cplusplus
561} /* extern "C" */
562#endif
563
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +0000564#endif /* _XTABLES_H */