5 * Changing any structs/functions may incur a needed change
6 * in libxtables_vcurrent/vage too.
9 #include <sys/socket.h> /* PF_* */
10 #include <sys/types.h>
13 #include <netinet/in.h>
15 #include <linux/types.h>
16 #include <linux/netfilter.h>
17 #include <linux/netfilter/x_tables.h>
20 #define IPPROTO_SCTP 132
23 #define IPPROTO_DCCP 33
26 # define IPPROTO_MH 135
28 #ifndef IPPROTO_UDPLITE
29 #define IPPROTO_UDPLITE 136
32 #define XTABLES_VERSION "libxtables.so.@libxtables_vmajor@"
33 #define XTABLES_VERSION_CODE @libxtables_vmajor@
37 /* Include file for additions: new matches and targets. */
41 * ABI/API version this module requires. Must be first member,
42 * as the rest of this struct may be subject to ABI changes.
46 struct xtables_match *next;
50 /* Revision of match (0 by default). */
55 /* Size of match data. */
58 /* Size of match data relevent for userspace comparison purposes */
61 /* Function which prints out usage message. */
64 /* Initialize the match. */
65 void (*init)(struct xt_entry_match *m);
67 /* Function which parses command options; returns true if it
69 /* entry is struct ipt_entry for example */
70 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
72 struct xt_entry_match **match);
74 /* Final check; exit if not ok. */
75 void (*final_check)(unsigned int flags);
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);
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);
86 /* Pointer to list of extra command-line options */
87 const struct option *extra_opts;
89 /* Ignore these men behind the curtain: */
90 unsigned int option_offset;
91 struct xt_entry_match *m;
93 unsigned int loaded; /* simulate loading so options are merged properly */
99 * ABI/API version this module requires. Must be first member,
100 * as the rest of this struct may be subject to ABI changes.
104 struct xtables_target *next;
109 /* Revision of target (0 by default). */
115 /* Size of target data. */
118 /* Size of target data relevent for userspace comparison purposes */
119 size_t userspacesize;
121 /* Function which prints out usage message. */
124 /* Initialize the target. */
125 void (*init)(struct xt_entry_target *t);
127 /* Function which parses command options; returns true if it
129 /* entry is struct ipt_entry for example */
130 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
132 struct xt_entry_target **targetinfo);
134 /* Final check; exit if not ok. */
135 void (*final_check)(unsigned int flags);
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);
141 /* Saves the targinfo in parsable form to stdout. */
142 void (*save)(const void *ip,
143 const struct xt_entry_target *target);
145 /* Pointer to list of extra command-line options */
146 const struct option *extra_opts;
148 /* Ignore these men behind the curtain: */
149 unsigned int option_offset;
150 struct xt_entry_target *t;
153 unsigned int loaded; /* simulate loading so options are merged properly */
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 */
165 * struct xtables_pprot -
167 * A few hardcoded protocols for 'all' and in case the user has no
170 struct xtables_pprot {
175 enum xtables_tryload {
179 XTF_LOAD_MUST_SUCCEED,
182 enum xtables_exittype {
193 struct xtables_globals
195 unsigned int option_offset;
196 const char *program_name, *program_version;
197 struct option *orig_opts;
199 void (*exit_err)(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3)));
206 extern const char *xtables_modprobe_program;
207 extern struct xtables_match *xtables_matches;
208 extern struct xtables_target *xtables_targets;
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);
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);
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);
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);
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);
242 xtables_parse_interface(const char *arg, char *vianame, unsigned char *mask);
244 /* this is a special 64bit data type that is 8-byte aligned */
245 #define aligned_u64 u_int64_t __attribute__((aligned(8)))
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)
252 extern void xtables_param_act(unsigned int, const char *, ...);
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 *);
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 *);
274 * Print the specified value to standard output, quoting dangerous
275 * characters if required.
277 extern void xtables_save_string(const char *value);
279 #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
284 extern void init_extensions(void);
286 # define _init __attribute__((constructor)) _INIT
289 extern const struct xtables_pprot xtables_chain_protos[];
290 extern u_int16_t xtables_parse_protocol(const char *s);
292 #ifdef XTABLES_INTERNAL
294 /* Shipped modules rely on this... */
297 # define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
300 extern void _init(void);
308 #endif /* _XTABLES_H */