| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1 | #ifndef _IPTABLES_USER_H |
| 2 | #define _IPTABLES_USER_H |
| 3 | |
| Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 4 | #include "iptables_common.h" |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 5 | #include "libiptc/libiptc.h" |
| 6 | |
| Martin Josefsson | 357d59d | 2004-12-27 19:49:28 +0000 | [diff] [blame] | 7 | #ifndef IPT_LIB_DIR |
| 8 | #define IPT_LIB_DIR "/usr/local/lib/iptables" |
| 9 | #endif |
| 10 | |
| Harald Welte | db0422f | 2004-03-04 07:45:30 +0000 | [diff] [blame] | 11 | #ifndef IPPROTO_SCTP |
| 12 | #define IPPROTO_SCTP 132 |
| 13 | #endif |
| 14 | |
| Rusty Russell | 3aef54d | 2005-01-03 03:48:40 +0000 | [diff] [blame] | 15 | #ifndef IPT_SO_GET_REVISION_MATCH /* Old kernel source. */ |
| 16 | #define IPT_SO_GET_REVISION_MATCH (IPT_BASE_CTL + 2) |
| 17 | #define IPT_SO_GET_REVISION_TARGET (IPT_BASE_CTL + 3) |
| 18 | |
| 19 | struct ipt_get_revision |
| 20 | { |
| 21 | char name[IPT_FUNCTION_MAXNAMELEN-1]; |
| 22 | |
| 23 | u_int8_t revision; |
| 24 | }; |
| 25 | #endif /* IPT_SO_GET_REVISION_MATCH Old kernel source */ |
| 26 | |
| Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 27 | struct iptables_rule_match |
| 28 | { |
| 29 | struct iptables_rule_match *next; |
| 30 | |
| 31 | struct iptables_match *match; |
| Joszef Kadlecsik | a258ad7 | 2006-03-03 09:36:50 +0000 | [diff] [blame^] | 32 | |
| 33 | /* Multiple matches of the same type: the ones before |
| 34 | the current one are completed from parsing point of view */ |
| 35 | unsigned int completed; |
| Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 38 | /* Include file for additions: new matches and targets. */ |
| 39 | struct iptables_match |
| 40 | { |
| 41 | struct iptables_match *next; |
| 42 | |
| 43 | ipt_chainlabel name; |
| 44 | |
| Rusty Russell | 3aef54d | 2005-01-03 03:48:40 +0000 | [diff] [blame] | 45 | /* Revision of match (0 by default). */ |
| 46 | u_int8_t revision; |
| 47 | |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 48 | const char *version; |
| 49 | |
| 50 | /* Size of match data. */ |
| 51 | size_t size; |
| 52 | |
| Rusty Russell | edf14cf | 2000-04-19 11:26:44 +0000 | [diff] [blame] | 53 | /* Size of match data relevent for userspace comparison purposes */ |
| 54 | size_t userspacesize; |
| 55 | |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 56 | /* Function which prints out usage message. */ |
| 57 | void (*help)(void); |
| 58 | |
| 59 | /* Initialize the match. */ |
| 60 | void (*init)(struct ipt_entry_match *m, unsigned int *nfcache); |
| 61 | |
| 62 | /* Function which parses command options; returns true if it |
| 63 | ate an option */ |
| 64 | int (*parse)(int c, char **argv, int invert, unsigned int *flags, |
| 65 | const struct ipt_entry *entry, |
| 66 | unsigned int *nfcache, |
| 67 | struct ipt_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 | void (*print)(const struct ipt_ip *ip, |
| 74 | const struct ipt_entry_match *match, int numeric); |
| 75 | |
| Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 76 | /* Saves the match info in parsable form to stdout. */ |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 77 | void (*save)(const struct ipt_ip *ip, |
| 78 | const struct ipt_entry_match *match); |
| 79 | |
| 80 | /* Pointer to list of extra command-line options */ |
| Jan Echternach | b6db331 | 2000-08-27 07:39:08 +0000 | [diff] [blame] | 81 | const struct option *extra_opts; |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 82 | |
| 83 | /* Ignore these men behind the curtain: */ |
| 84 | unsigned int option_offset; |
| 85 | struct ipt_entry_match *m; |
| 86 | unsigned int mflags; |
| Harald Welte | 3efb6ea | 2001-08-06 18:50:21 +0000 | [diff] [blame] | 87 | #ifdef NO_SHARED_LIBS |
| 88 | unsigned int loaded; /* simulate loading so options are merged properly */ |
| 89 | #endif |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | struct iptables_target |
| 93 | { |
| 94 | struct iptables_target *next; |
| 95 | |
| 96 | ipt_chainlabel name; |
| 97 | |
| Rusty Russell | 3aef54d | 2005-01-03 03:48:40 +0000 | [diff] [blame] | 98 | /* Revision of target (0 by default). */ |
| 99 | u_int8_t revision; |
| 100 | |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 101 | const char *version; |
| 102 | |
| 103 | /* Size of target data. */ |
| 104 | size_t size; |
| 105 | |
| Rusty Russell | edf14cf | 2000-04-19 11:26:44 +0000 | [diff] [blame] | 106 | /* Size of target data relevent for userspace comparison purposes */ |
| 107 | size_t userspacesize; |
| 108 | |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 109 | /* Function which prints out usage message. */ |
| 110 | void (*help)(void); |
| 111 | |
| 112 | /* Initialize the target. */ |
| 113 | void (*init)(struct ipt_entry_target *t, unsigned int *nfcache); |
| 114 | |
| 115 | /* Function which parses command options; returns true if it |
| 116 | ate an option */ |
| 117 | int (*parse)(int c, char **argv, int invert, unsigned int *flags, |
| 118 | const struct ipt_entry *entry, |
| 119 | struct ipt_entry_target **target); |
| 120 | |
| 121 | /* Final check; exit if not ok. */ |
| 122 | void (*final_check)(unsigned int flags); |
| 123 | |
| 124 | /* Prints out the target iff non-NULL: put space at end */ |
| 125 | void (*print)(const struct ipt_ip *ip, |
| 126 | const struct ipt_entry_target *target, int numeric); |
| 127 | |
| 128 | /* Saves the targinfo in parsable form to stdout. */ |
| 129 | void (*save)(const struct ipt_ip *ip, |
| 130 | const struct ipt_entry_target *target); |
| 131 | |
| 132 | /* Pointer to list of extra command-line options */ |
| 133 | struct option *extra_opts; |
| 134 | |
| 135 | /* Ignore these men behind the curtain: */ |
| 136 | unsigned int option_offset; |
| 137 | struct ipt_entry_target *t; |
| 138 | unsigned int tflags; |
| Harald Welte | a114e9e | 2000-12-01 14:28:19 +0000 | [diff] [blame] | 139 | unsigned int used; |
| Harald Welte | 3efb6ea | 2001-08-06 18:50:21 +0000 | [diff] [blame] | 140 | #ifdef NO_SHARED_LIBS |
| 141 | unsigned int loaded; /* simulate loading so options are merged properly */ |
| 142 | #endif |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
| Illes Marci | 63e9063 | 2003-03-03 08:08:37 +0000 | [diff] [blame] | 145 | extern int line; |
| 146 | |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 147 | /* Your shared library should call one of these. */ |
| 148 | extern void register_match(struct iptables_match *me); |
| 149 | extern void register_target(struct iptables_target *me); |
| 150 | |
| Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 151 | extern struct in_addr *dotted_to_addr(const char *dotted); |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 152 | extern char *addr_to_dotted(const struct in_addr *addrp); |
| Marc Boucher | b93c798 | 2001-12-06 14:50:19 +0000 | [diff] [blame] | 153 | extern char *addr_to_anyname(const struct in_addr *addr); |
| 154 | extern char *mask_to_dotted(const struct in_addr *mask); |
| 155 | |
| 156 | extern void parse_hostnetworkmask(const char *name, struct in_addr **addrpp, |
| 157 | struct in_addr *maskp, unsigned int *naddrs); |
| 158 | extern u_int16_t parse_protocol(const char *s); |
| Yasuyuki KOZAKAI | 9867e81 | 2005-06-22 12:24:21 +0000 | [diff] [blame] | 159 | extern void parse_interface(const char *arg, char *vianame, unsigned char *mask); |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 160 | |
| 161 | extern int do_command(int argc, char *argv[], char **table, |
| 162 | iptc_handle_t *handle); |
| 163 | /* Keeping track of external matches and targets: linked lists. */ |
| 164 | extern struct iptables_match *iptables_matches; |
| 165 | extern struct iptables_target *iptables_targets; |
| 166 | |
| Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 167 | enum ipt_tryload { |
| 168 | DONT_LOAD, |
| Jones Desougi | f5b86e6 | 2005-12-22 03:33:50 +0000 | [diff] [blame] | 169 | DURING_LOAD, |
| Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 170 | TRY_LOAD, |
| 171 | LOAD_MUST_SUCCEED |
| 172 | }; |
| 173 | |
| 174 | extern struct iptables_target *find_target(const char *name, enum ipt_tryload); |
| Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 175 | extern struct iptables_match *find_match(const char *name, enum ipt_tryload, struct iptables_rule_match **match); |
| Harald Welte | a114e9e | 2000-12-01 14:28:19 +0000 | [diff] [blame] | 176 | |
| 177 | extern int delete_chain(const ipt_chainlabel chain, int verbose, |
| 178 | iptc_handle_t *handle); |
| 179 | extern int flush_entries(const ipt_chainlabel chain, int verbose, |
| 180 | iptc_handle_t *handle); |
| 181 | extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, iptc_handle_t *), |
| 182 | int verbose, int builtinstoo, iptc_handle_t *handle); |
| Phil Oester | 8cf6591 | 2005-09-19 15:00:33 +0000 | [diff] [blame] | 183 | |
| 184 | /* kernel revision handling */ |
| 185 | extern int kernel_version; |
| 186 | extern void get_kernel_version(void); |
| 187 | #define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z) |
| 188 | #define LINUX_VERSION_MAJOR(x) (((x)>>16) & 0xFF) |
| 189 | #define LINUX_VERSION_MINOR(x) (((x)>> 8) & 0xFF) |
| 190 | #define LINUX_VERSION_PATCH(x) ( (x) & 0xFF) |
| 191 | |
| Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 192 | #endif /*_IPTABLES_USER_H*/ |