Yasuyuki KOZAKAI | 5208806 | 2007-07-24 05:44:11 +0000 | [diff] [blame] | 1 | #ifndef _XTABLES_H |
| 2 | #define _XTABLES_H |
| 3 | |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 4 | /* |
| 5 | * Changing any structs/functions may incur a needed change |
| 6 | * in libxtables_vcurrent/vage too. |
| 7 | */ |
| 8 | |
Jan Engelhardt | ef18e81 | 2008-08-04 12:47:48 +0200 | [diff] [blame] | 9 | #include <sys/socket.h> /* PF_* */ |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 10 | #include <sys/types.h> |
Jan Engelhardt | ef18e81 | 2008-08-04 12:47:48 +0200 | [diff] [blame] | 11 | #include <stdbool.h> |
Jan Engelhardt | 03d9948 | 2008-11-18 12:27:54 +0100 | [diff] [blame] | 12 | #include <netinet/in.h> |
Jan Engelhardt | ef18e81 | 2008-08-04 12:47:48 +0200 | [diff] [blame] | 13 | #include <net/if.h> |
Jan Engelhardt | 5e9eaed | 2007-12-17 13:12:01 +0000 | [diff] [blame] | 14 | #include <linux/types.h> |
Jan Engelhardt | 03d9948 | 2008-11-18 12:27:54 +0100 | [diff] [blame] | 15 | #include <linux/netfilter.h> |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 16 | #include <linux/netfilter/x_tables.h> |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 17 | |
Yasuyuki KOZAKAI | 5cd1ff5 | 2007-07-24 05:55:12 +0000 | [diff] [blame] | 18 | #ifndef IPPROTO_SCTP |
| 19 | #define IPPROTO_SCTP 132 |
| 20 | #endif |
| 21 | #ifndef IPPROTO_DCCP |
| 22 | #define IPPROTO_DCCP 33 |
| 23 | #endif |
Jan Engelhardt | 1de7edf | 2009-01-30 05:38:11 +0100 | [diff] [blame] | 24 | #ifndef IPPROTO_MH |
| 25 | # define IPPROTO_MH 135 |
| 26 | #endif |
Yasuyuki KOZAKAI | 5cd1ff5 | 2007-07-24 05:55:12 +0000 | [diff] [blame] | 27 | #ifndef IPPROTO_UDPLITE |
| 28 | #define IPPROTO_UDPLITE 136 |
| 29 | #endif |
| 30 | |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 31 | #define XTABLES_VERSION "libxtables.so.@libxtables_vmajor@" |
| 32 | #define XTABLES_VERSION_CODE @libxtables_vmajor@ |
Jan Engelhardt | 493c712 | 2008-04-15 11:15:16 +0200 | [diff] [blame] | 33 | |
Jan Engelhardt | ef18e81 | 2008-08-04 12:47:48 +0200 | [diff] [blame] | 34 | struct in_addr; |
| 35 | |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 36 | /* Include file for additions: new matches and targets. */ |
| 37 | struct xtables_match |
| 38 | { |
| 39 | struct xtables_match *next; |
| 40 | |
Jan Engelhardt | ef18e81 | 2008-08-04 12:47:48 +0200 | [diff] [blame] | 41 | const char *name; |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 42 | |
| 43 | /* Revision of match (0 by default). */ |
| 44 | u_int8_t revision; |
| 45 | |
| 46 | u_int16_t family; |
| 47 | |
| 48 | const char *version; |
| 49 | |
| 50 | /* Size of match data. */ |
| 51 | size_t size; |
| 52 | |
| 53 | /* Size of match data relevent for userspace comparison purposes */ |
| 54 | size_t userspacesize; |
| 55 | |
| 56 | /* Function which prints out usage message. */ |
| 57 | void (*help)(void); |
| 58 | |
| 59 | /* Initialize the match. */ |
Peter Riley | ea146a9 | 2007-09-02 13:09:07 +0000 | [diff] [blame] | 60 | void (*init)(struct xt_entry_match *m); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 61 | |
| 62 | /* Function which parses command options; returns true if it |
| 63 | ate an option */ |
| 64 | /* entry is struct ipt_entry for example */ |
| 65 | int (*parse)(int c, char **argv, int invert, unsigned int *flags, |
| 66 | const void *entry, |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 67 | struct xt_entry_match **match); |
| 68 | |
| 69 | /* Final check; exit if not ok. */ |
| 70 | void (*final_check)(unsigned int flags); |
| 71 | |
| 72 | /* Prints out the match iff non-NULL: put space at end */ |
| 73 | /* ip is struct ipt_ip * for example */ |
| 74 | void (*print)(const void *ip, |
| 75 | const struct xt_entry_match *match, int numeric); |
| 76 | |
| 77 | /* Saves the match info in parsable form to stdout. */ |
| 78 | /* ip is struct ipt_ip * for example */ |
| 79 | void (*save)(const void *ip, const struct xt_entry_match *match); |
| 80 | |
| 81 | /* Pointer to list of extra command-line options */ |
| 82 | const struct option *extra_opts; |
| 83 | |
| 84 | /* Ignore these men behind the curtain: */ |
| 85 | unsigned int option_offset; |
| 86 | struct xt_entry_match *m; |
| 87 | unsigned int mflags; |
| 88 | #ifdef NO_SHARED_LIBS |
| 89 | unsigned int loaded; /* simulate loading so options are merged properly */ |
| 90 | #endif |
| 91 | }; |
| 92 | |
| 93 | struct xtables_target |
| 94 | { |
| 95 | struct xtables_target *next; |
| 96 | |
Jan Engelhardt | ef18e81 | 2008-08-04 12:47:48 +0200 | [diff] [blame] | 97 | const char *name; |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 98 | |
| 99 | /* Revision of target (0 by default). */ |
| 100 | u_int8_t revision; |
| 101 | |
| 102 | u_int16_t family; |
| 103 | |
| 104 | const char *version; |
| 105 | |
| 106 | /* Size of target data. */ |
| 107 | size_t size; |
| 108 | |
| 109 | /* Size of target data relevent for userspace comparison purposes */ |
| 110 | size_t userspacesize; |
| 111 | |
| 112 | /* Function which prints out usage message. */ |
| 113 | void (*help)(void); |
| 114 | |
| 115 | /* Initialize the target. */ |
Peter Riley | ea146a9 | 2007-09-02 13:09:07 +0000 | [diff] [blame] | 116 | void (*init)(struct xt_entry_target *t); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 117 | |
| 118 | /* Function which parses command options; returns true if it |
| 119 | ate an option */ |
| 120 | /* entry is struct ipt_entry for example */ |
| 121 | int (*parse)(int c, char **argv, int invert, unsigned int *flags, |
| 122 | const void *entry, |
| 123 | struct xt_entry_target **targetinfo); |
| 124 | |
| 125 | /* Final check; exit if not ok. */ |
| 126 | void (*final_check)(unsigned int flags); |
| 127 | |
| 128 | /* Prints out the target iff non-NULL: put space at end */ |
| 129 | void (*print)(const void *ip, |
| 130 | const struct xt_entry_target *target, int numeric); |
| 131 | |
| 132 | /* Saves the targinfo in parsable form to stdout. */ |
| 133 | void (*save)(const void *ip, |
| 134 | const struct xt_entry_target *target); |
| 135 | |
| 136 | /* Pointer to list of extra command-line options */ |
Jan Engelhardt | 3365332 | 2007-07-30 13:20:43 +0000 | [diff] [blame] | 137 | const struct option *extra_opts; |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 138 | |
| 139 | /* Ignore these men behind the curtain: */ |
| 140 | unsigned int option_offset; |
| 141 | struct xt_entry_target *t; |
| 142 | unsigned int tflags; |
| 143 | unsigned int used; |
| 144 | #ifdef NO_SHARED_LIBS |
| 145 | unsigned int loaded; /* simulate loading so options are merged properly */ |
| 146 | #endif |
| 147 | }; |
| 148 | |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 149 | struct xtables_rule_match { |
| 150 | struct xtables_rule_match *next; |
| 151 | struct xtables_match *match; |
| 152 | /* Multiple matches of the same type: the ones before |
| 153 | the current one are completed from parsing point of view */ |
| 154 | bool completed; |
| 155 | }; |
| 156 | |
Jan Engelhardt | 1de7edf | 2009-01-30 05:38:11 +0100 | [diff] [blame] | 157 | /** |
| 158 | * struct xtables_pprot - |
| 159 | * |
| 160 | * A few hardcoded protocols for 'all' and in case the user has no |
| 161 | * /etc/protocols. |
| 162 | */ |
| 163 | struct xtables_pprot { |
| 164 | const char *name; |
| 165 | u_int8_t num; |
| 166 | }; |
| 167 | |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 168 | enum xtables_tryload { |
| 169 | XTF_DONT_LOAD, |
| 170 | XTF_DURING_LOAD, |
| 171 | XTF_TRY_LOAD, |
| 172 | XTF_LOAD_MUST_SUCCEED, |
| 173 | }; |
| 174 | |
Jan Engelhardt | a41545c | 2009-01-27 21:27:19 +0100 | [diff] [blame] | 175 | enum xtables_exittype { |
| 176 | OTHER_PROBLEM = 1, |
| 177 | PARAMETER_PROBLEM, |
| 178 | VERSION_PROBLEM, |
| 179 | RESOURCE_PROBLEM, |
| 180 | XTF_ONLY_ONCE, |
| 181 | XTF_NO_INVERT, |
| 182 | XTF_BAD_VALUE, |
| 183 | XTF_ONE_ACTION, |
| 184 | }; |
| 185 | |
Jamal Hadi Salim | 40a8343 | 2009-02-11 13:02:21 +0100 | [diff] [blame] | 186 | struct xtables_globals |
| 187 | { |
| 188 | unsigned int option_offset; |
Jan Engelhardt | 41f03ba | 2009-02-11 16:13:47 +0100 | [diff] [blame] | 189 | const char *program_name, *program_version; |
Jamal Hadi Salim | 139b3fe | 2009-02-12 11:43:01 -0500 | [diff] [blame] | 190 | struct option *orig_opts; |
Jamal Hadi Salim | 40a8343 | 2009-02-11 13:02:21 +0100 | [diff] [blame] | 191 | struct option *opts; |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 192 | void (*exit_err)(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3))); |
Jamal Hadi Salim | 40a8343 | 2009-02-11 13:02:21 +0100 | [diff] [blame] | 193 | }; |
| 194 | |
Jan Engelhardt | c021c3c | 2009-01-27 15:10:05 +0100 | [diff] [blame] | 195 | extern const char *xtables_modprobe_program; |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 196 | extern struct xtables_match *xtables_matches; |
| 197 | extern struct xtables_target *xtables_targets; |
Jan Engelhardt | c021c3c | 2009-01-27 15:10:05 +0100 | [diff] [blame] | 198 | |
Jan Engelhardt | 39bf9c8 | 2009-01-27 15:59:06 +0100 | [diff] [blame] | 199 | extern void xtables_init(void); |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 200 | extern void xtables_set_nfproto(uint8_t); |
Jan Engelhardt | 630ef48 | 2009-01-27 14:58:41 +0100 | [diff] [blame] | 201 | extern void *xtables_calloc(size_t, size_t); |
| 202 | extern void *xtables_malloc(size_t); |
| 203 | |
Jan Engelhardt | c021c3c | 2009-01-27 15:10:05 +0100 | [diff] [blame] | 204 | extern int xtables_insmod(const char *, const char *, bool); |
| 205 | extern int xtables_load_ko(const char *, bool); |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 206 | extern int xtables_set_params(struct xtables_globals *xtp); |
Jamal Hadi Salim | 8533221 | 2009-02-12 09:33:59 -0500 | [diff] [blame] | 207 | extern void xtables_set_revision(char *name, u_int8_t revision); |
Jamal Hadi Salim | 139b3fe | 2009-02-12 11:43:01 -0500 | [diff] [blame] | 208 | extern void xtables_free_opts(int reset_offset); |
Jamal Hadi Salim | 7058192 | 2009-02-13 08:36:44 -0500 | [diff] [blame] | 209 | extern struct option *xtables_merge_options(struct option *oldopts, |
| 210 | const struct option *newopts, unsigned int *option_offset); |
Jan Engelhardt | c021c3c | 2009-01-27 15:10:05 +0100 | [diff] [blame] | 211 | |
Jamal Hadi Salim | 7e4db2f | 2009-02-13 09:14:17 -0500 | [diff] [blame] | 212 | extern int xtables_init_all(struct xtables_globals *xtp, uint8_t nfproto); |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 213 | extern struct xtables_match *xtables_find_match(const char *name, |
| 214 | enum xtables_tryload, struct xtables_rule_match **match); |
| 215 | extern struct xtables_target *xtables_find_target(const char *name, |
| 216 | enum xtables_tryload); |
| 217 | |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 218 | /* Your shared library should call one of these. */ |
| 219 | extern void xtables_register_match(struct xtables_match *me); |
| 220 | extern void xtables_register_target(struct xtables_target *me); |
| 221 | |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 222 | extern bool xtables_strtoul(const char *, char **, unsigned long *, |
Jan Engelhardt | cd9e7aa | 2008-01-20 13:18:54 +0000 | [diff] [blame] | 223 | unsigned long, unsigned long); |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 224 | extern bool xtables_strtoui(const char *, char **, unsigned int *, |
Jan Engelhardt | cd9e7aa | 2008-01-20 13:18:54 +0000 | [diff] [blame] | 225 | unsigned int, unsigned int); |
Jan Engelhardt | aae6be9 | 2009-01-30 04:24:47 +0100 | [diff] [blame] | 226 | extern int xtables_service_to_port(const char *name, const char *proto); |
| 227 | extern u_int16_t xtables_parse_port(const char *port, const char *proto); |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 228 | extern void |
Jan Engelhardt | aae6be9 | 2009-01-30 04:24:47 +0100 | [diff] [blame] | 229 | xtables_parse_interface(const char *arg, char *vianame, unsigned char *mask); |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 230 | |
Yasuyuki KOZAKAI | a3732db | 2007-07-24 06:39:40 +0000 | [diff] [blame] | 231 | /* this is a special 64bit data type that is 8-byte aligned */ |
Patrick McHardy | c329d6a | 2007-09-05 14:19:23 +0000 | [diff] [blame] | 232 | #define aligned_u64 u_int64_t __attribute__((aligned(8))) |
Yasuyuki KOZAKAI | a3732db | 2007-07-24 06:39:40 +0000 | [diff] [blame] | 233 | |
Jan Engelhardt | 0f16c72 | 2009-01-30 04:55:38 +0100 | [diff] [blame] | 234 | int xtables_check_inverse(const char option[], int *invert, |
| 235 | int *my_optind, int argc); |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 236 | extern struct xtables_globals *xt_params; |
Jan Engelhardt | 1829ed4 | 2009-02-21 03:29:44 +0100 | [diff] [blame] | 237 | #define xtables_error (xt_params->exit_err) |
Jamal Hadi Salim | 7058192 | 2009-02-13 08:36:44 -0500 | [diff] [blame] | 238 | |
Jan Engelhardt | a41545c | 2009-01-27 21:27:19 +0100 | [diff] [blame] | 239 | extern void xtables_param_act(unsigned int, const char *, ...); |
Yasuyuki KOZAKAI | a3732db | 2007-07-24 06:39:40 +0000 | [diff] [blame] | 240 | |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 241 | extern const char *xtables_ipaddr_to_numeric(const struct in_addr *); |
| 242 | extern const char *xtables_ipaddr_to_anyname(const struct in_addr *); |
| 243 | extern const char *xtables_ipmask_to_numeric(const struct in_addr *); |
Jan Engelhardt | 1e01b0b | 2009-01-30 04:20:32 +0100 | [diff] [blame] | 244 | extern struct in_addr *xtables_numeric_to_ipaddr(const char *); |
| 245 | extern struct in_addr *xtables_numeric_to_ipmask(const char *); |
Jan Engelhardt | a0baae8 | 2009-01-30 04:32:50 +0100 | [diff] [blame] | 246 | extern void xtables_ipparse_any(const char *, struct in_addr **, |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 247 | struct in_addr *, unsigned int *); |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 248 | |
Jan Engelhardt | 1e01b0b | 2009-01-30 04:20:32 +0100 | [diff] [blame] | 249 | extern struct in6_addr *xtables_numeric_to_ip6addr(const char *); |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 250 | extern const char *xtables_ip6addr_to_numeric(const struct in6_addr *); |
| 251 | extern const char *xtables_ip6addr_to_anyname(const struct in6_addr *); |
| 252 | extern const char *xtables_ip6mask_to_numeric(const struct in6_addr *); |
Jan Engelhardt | a0baae8 | 2009-01-30 04:32:50 +0100 | [diff] [blame] | 253 | extern void xtables_ip6parse_any(const char *, struct in6_addr **, |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 254 | struct in6_addr *, unsigned int *); |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 255 | |
Max Kellermann | a5d0994 | 2008-01-29 13:44:34 +0000 | [diff] [blame] | 256 | /** |
| 257 | * Print the specified value to standard output, quoting dangerous |
| 258 | * characters if required. |
| 259 | */ |
Jan Engelhardt | a0baae8 | 2009-01-30 04:32:50 +0100 | [diff] [blame] | 260 | extern void xtables_save_string(const char *value); |
Max Kellermann | a5d0994 | 2008-01-29 13:44:34 +0000 | [diff] [blame] | 261 | |
Yasuyuki KOZAKAI | a3732db | 2007-07-24 06:39:40 +0000 | [diff] [blame] | 262 | #ifdef NO_SHARED_LIBS |
Jan Engelhardt | f82070f | 2008-01-20 13:14:00 +0000 | [diff] [blame] | 263 | # ifdef _INIT |
| 264 | # undef _init |
| 265 | # define _init _INIT |
| 266 | # endif |
| 267 | extern void init_extensions(void); |
| 268 | #else |
| 269 | # define _init __attribute__((constructor)) _INIT |
Yasuyuki KOZAKAI | a3732db | 2007-07-24 06:39:40 +0000 | [diff] [blame] | 270 | #endif |
| 271 | |
Jan Engelhardt | 1de7edf | 2009-01-30 05:38:11 +0100 | [diff] [blame] | 272 | extern const struct xtables_pprot xtables_chain_protos[]; |
| 273 | extern u_int16_t xtables_parse_protocol(const char *s); |
Jan Engelhardt | 33690a1 | 2008-02-11 00:54:00 +0100 | [diff] [blame] | 274 | |
| 275 | #ifdef XTABLES_INTERNAL |
Jan Engelhardt | c02e808 | 2009-02-10 10:40:15 +0100 | [diff] [blame] | 276 | |
| 277 | /* Shipped modules rely on this... */ |
| 278 | |
Jan Engelhardt | 1de7edf | 2009-01-30 05:38:11 +0100 | [diff] [blame] | 279 | # ifndef ARRAY_SIZE |
| 280 | # define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) |
| 281 | # endif |
Jan Engelhardt | c02e808 | 2009-02-10 10:40:15 +0100 | [diff] [blame] | 282 | |
| 283 | extern void _init(void); |
| 284 | |
Jan Engelhardt | 33690a1 | 2008-02-11 00:54:00 +0100 | [diff] [blame] | 285 | #endif |
| 286 | |
Yasuyuki KOZAKAI | 5208806 | 2007-07-24 05:44:11 +0000 | [diff] [blame] | 287 | #endif /* _XTABLES_H */ |