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