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