Update Packaging Spec file
[external/iptables.git] / include / xtables.h.in
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 <netinet/in.h>
14 #include <net/if.h>
15 #include <linux/types.h>
16 #include <linux/netfilter.h>
17 #include <linux/netfilter/x_tables.h>
18
19 #ifndef IPPROTO_SCTP
20 #define IPPROTO_SCTP 132
21 #endif
22 #ifndef IPPROTO_DCCP
23 #define IPPROTO_DCCP 33
24 #endif
25 #ifndef IPPROTO_MH
26 #       define IPPROTO_MH 135
27 #endif
28 #ifndef IPPROTO_UDPLITE
29 #define IPPROTO_UDPLITE 136
30 #endif
31
32 #define XTABLES_VERSION "libxtables.so.@libxtables_vmajor@"
33 #define XTABLES_VERSION_CODE @libxtables_vmajor@
34
35 struct in_addr;
36
37 /* Include file for additions: new matches and targets. */
38 struct xtables_match
39 {
40         /*
41          * ABI/API version this module requires. Must be first member,
42          * as the rest of this struct may be subject to ABI changes.
43          */
44         const char *version;
45
46         struct xtables_match *next;
47
48         const char *name;
49
50         /* Revision of match (0 by default). */
51         u_int8_t revision;
52
53         u_int16_t family;
54
55         /* Size of match data. */
56         size_t size;
57
58         /* Size of match data relevent for userspace comparison purposes */
59         size_t userspacesize;
60
61         /* Function which prints out usage message. */
62         void (*help)(void);
63
64         /* Initialize the match. */
65         void (*init)(struct xt_entry_match *m);
66
67         /* Function which parses command options; returns true if it
68            ate an option */
69         /* entry is struct ipt_entry for example */
70         int (*parse)(int c, char **argv, int invert, unsigned int *flags,
71                      const void *entry,
72                      struct xt_entry_match **match);
73
74         /* Final check; exit if not ok. */
75         void (*final_check)(unsigned int flags);
76
77         /* Prints out the match iff non-NULL: put space at end */
78         /* ip is struct ipt_ip * for example */
79         void (*print)(const void *ip,
80                       const struct xt_entry_match *match, int numeric);
81
82         /* Saves the match info in parsable form to stdout. */
83         /* ip is struct ipt_ip * for example */
84         void (*save)(const void *ip, const struct xt_entry_match *match);
85
86         /* Pointer to list of extra command-line options */
87         const struct option *extra_opts;
88
89         /* Ignore these men behind the curtain: */
90         unsigned int option_offset;
91         struct xt_entry_match *m;
92         unsigned int mflags;
93         unsigned int loaded; /* simulate loading so options are merged properly */
94 };
95
96 struct xtables_target
97 {
98         /*
99          * ABI/API version this module requires. Must be first member,
100          * as the rest of this struct may be subject to ABI changes.
101          */
102         const char *version;
103
104         struct xtables_target *next;
105
106
107         const char *name;
108
109         /* Revision of target (0 by default). */
110         u_int8_t revision;
111
112         u_int16_t family;
113
114
115         /* Size of target data. */
116         size_t size;
117
118         /* Size of target data relevent for userspace comparison purposes */
119         size_t userspacesize;
120
121         /* Function which prints out usage message. */
122         void (*help)(void);
123
124         /* Initialize the target. */
125         void (*init)(struct xt_entry_target *t);
126
127         /* Function which parses command options; returns true if it
128            ate an option */
129         /* entry is struct ipt_entry for example */
130         int (*parse)(int c, char **argv, int invert, unsigned int *flags,
131                      const void *entry,
132                      struct xt_entry_target **targetinfo);
133
134         /* Final check; exit if not ok. */
135         void (*final_check)(unsigned int flags);
136
137         /* Prints out the target iff non-NULL: put space at end */
138         void (*print)(const void *ip,
139                       const struct xt_entry_target *target, int numeric);
140
141         /* Saves the targinfo in parsable form to stdout. */
142         void (*save)(const void *ip,
143                      const struct xt_entry_target *target);
144
145         /* Pointer to list of extra command-line options */
146         const struct option *extra_opts;
147
148         /* Ignore these men behind the curtain: */
149         unsigned int option_offset;
150         struct xt_entry_target *t;
151         unsigned int tflags;
152         unsigned int used;
153         unsigned int loaded; /* simulate loading so options are merged properly */
154 };
155
156 struct xtables_rule_match {
157         struct xtables_rule_match *next;
158         struct xtables_match *match;
159         /* Multiple matches of the same type: the ones before
160            the current one are completed from parsing point of view */
161         bool completed;
162 };
163
164 /**
165  * struct xtables_pprot -
166  *
167  * A few hardcoded protocols for 'all' and in case the user has no
168  * /etc/protocols.
169  */
170 struct xtables_pprot {
171         const char *name;
172         u_int8_t num;
173 };
174
175 enum xtables_tryload {
176         XTF_DONT_LOAD,
177         XTF_DURING_LOAD,
178         XTF_TRY_LOAD,
179         XTF_LOAD_MUST_SUCCEED,
180 };
181
182 enum xtables_exittype {
183         OTHER_PROBLEM = 1,
184         PARAMETER_PROBLEM,
185         VERSION_PROBLEM,
186         RESOURCE_PROBLEM,
187         XTF_ONLY_ONCE,
188         XTF_NO_INVERT,
189         XTF_BAD_VALUE,
190         XTF_ONE_ACTION,
191 };
192
193 struct xtables_globals
194 {
195         unsigned int option_offset;
196         const char *program_name, *program_version;
197         struct option *orig_opts;
198         struct option *opts;
199         void (*exit_err)(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3)));
200 };
201
202 #ifdef __cplusplus
203 extern "C" {
204 #endif
205
206 extern const char *xtables_modprobe_program;
207 extern struct xtables_match *xtables_matches;
208 extern struct xtables_target *xtables_targets;
209
210 extern void xtables_init(void);
211 extern void xtables_set_nfproto(uint8_t);
212 extern void *xtables_calloc(size_t, size_t);
213 extern void *xtables_malloc(size_t);
214 extern void *xtables_realloc(void *, size_t);
215
216 extern int xtables_insmod(const char *, const char *, bool);
217 extern int xtables_load_ko(const char *, bool);
218 extern int xtables_set_params(struct xtables_globals *xtp);
219 extern void xtables_free_opts(int reset_offset);
220 extern struct option *xtables_merge_options(struct option *oldopts,
221         const struct option *newopts, unsigned int *option_offset);
222
223 extern int xtables_init_all(struct xtables_globals *xtp, uint8_t nfproto);
224 extern struct xtables_match *xtables_find_match(const char *name,
225         enum xtables_tryload, struct xtables_rule_match **match);
226 extern struct xtables_target *xtables_find_target(const char *name,
227         enum xtables_tryload);
228
229 /* Your shared library should call one of these. */
230 extern void xtables_register_match(struct xtables_match *me);
231 extern void xtables_register_matches(struct xtables_match *, unsigned int);
232 extern void xtables_register_target(struct xtables_target *me);
233 extern void xtables_register_targets(struct xtables_target *, unsigned int);
234
235 extern bool xtables_strtoul(const char *, char **, unsigned long *,
236         unsigned long, unsigned long);
237 extern bool xtables_strtoui(const char *, char **, unsigned int *,
238         unsigned int, unsigned int);
239 extern int xtables_service_to_port(const char *name, const char *proto);
240 extern u_int16_t xtables_parse_port(const char *port, const char *proto);
241 extern void
242 xtables_parse_interface(const char *arg, char *vianame, unsigned char *mask);
243
244 /* this is a special 64bit data type that is 8-byte aligned */
245 #define aligned_u64 u_int64_t __attribute__((aligned(8)))
246
247 int xtables_check_inverse(const char option[], int *invert,
248         int *my_optind, int argc, char **argv);
249 extern struct xtables_globals *xt_params;
250 #define xtables_error (xt_params->exit_err)
251
252 extern void xtables_param_act(unsigned int, const char *, ...);
253
254 extern const char *xtables_ipaddr_to_numeric(const struct in_addr *);
255 extern const char *xtables_ipaddr_to_anyname(const struct in_addr *);
256 extern const char *xtables_ipmask_to_numeric(const struct in_addr *);
257 extern struct in_addr *xtables_numeric_to_ipaddr(const char *);
258 extern struct in_addr *xtables_numeric_to_ipmask(const char *);
259 extern void xtables_ipparse_any(const char *, struct in_addr **,
260         struct in_addr *, unsigned int *);
261 extern void xtables_ipparse_multiple(const char *, struct in_addr **,
262         struct in_addr **, unsigned int *);
263
264 extern struct in6_addr *xtables_numeric_to_ip6addr(const char *);
265 extern const char *xtables_ip6addr_to_numeric(const struct in6_addr *);
266 extern const char *xtables_ip6addr_to_anyname(const struct in6_addr *);
267 extern const char *xtables_ip6mask_to_numeric(const struct in6_addr *);
268 extern void xtables_ip6parse_any(const char *, struct in6_addr **,
269         struct in6_addr *, unsigned int *);
270 extern void xtables_ip6parse_multiple(const char *, struct in6_addr **,
271         struct in6_addr **, unsigned int *);
272
273 /**
274  * Print the specified value to standard output, quoting dangerous
275  * characters if required.
276  */
277 extern void xtables_save_string(const char *value);
278
279 #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
280 #       ifdef _INIT
281 #               undef _init
282 #               define _init _INIT
283 #       endif
284         extern void init_extensions(void);
285 #else
286 #       define _init __attribute__((constructor)) _INIT
287 #endif
288
289 extern const struct xtables_pprot xtables_chain_protos[];
290 extern u_int16_t xtables_parse_protocol(const char *s);
291
292 #ifdef XTABLES_INTERNAL
293
294 /* Shipped modules rely on this... */
295
296 #       ifndef ARRAY_SIZE
297 #               define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
298 #       endif
299
300 extern void _init(void);
301
302 #endif
303
304 #ifdef __cplusplus
305 } /* extern "C" */
306 #endif
307
308 #endif /* _XTABLES_H */