Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * $Id: ebtables.c,v 1.03 2002/01/19 |
| 3 | * |
| 4 | * Copyright (C) 2001-2002 Bart De Schuymer |
| 5 | * |
| 6 | * This code is stongly inspired on the iptables code which is |
| 7 | * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of the |
| 12 | * License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
| 23 | |
| 24 | #ifndef EBTABLES_U_H |
| 25 | #define EBTABLES_U_H |
Bart De Schuymer | 9cfd654 | 2002-08-13 16:08:08 +0000 | [diff] [blame] | 26 | #include <netinet/in.h> |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 27 | #include <linux/netfilter_bridge/ebtables.h> |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 28 | |
Bart De Schuymer | 639bbe9 | 2006-01-23 18:08:07 +0000 | [diff] [blame] | 29 | #ifndef IPPROTO_SCTP |
| 30 | #define IPPROTO_SCTP 132 |
| 31 | #endif |
| 32 | #ifndef IPPROTO_DCCP |
| 33 | #define IPPROTO_DCCP 33 |
| 34 | #endif |
| 35 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 36 | #define EXEC_STYLE_PRG 0 |
| 37 | #define EXEC_STYLE_DAEMON 1 |
| 38 | |
Bart De Schuymer | f81c270 | 2003-07-23 21:07:04 +0000 | [diff] [blame] | 39 | #ifndef EBT_MIN_ALIGN |
| 40 | #define EBT_MIN_ALIGN (__alignof__(struct ebt_entry_target)) |
| 41 | #endif |
| 42 | #define EBT_ALIGN(s) (((s) + (EBT_MIN_ALIGN-1)) & ~(EBT_MIN_ALIGN-1)) |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 43 | #define ERRORMSG_MAXLEN 128 |
Bart De Schuymer | f81c270 | 2003-07-23 21:07:04 +0000 | [diff] [blame] | 44 | |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 45 | struct ebt_u_entries |
| 46 | { |
Bart De Schuymer | 0976590 | 2002-06-23 08:15:51 +0000 | [diff] [blame] | 47 | int policy; |
Bart De Schuymer | 376ccfb | 2002-07-23 20:52:18 +0000 | [diff] [blame] | 48 | unsigned int nentries; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 49 | /* counter offset for this chain */ |
Bart De Schuymer | 0976590 | 2002-06-23 08:15:51 +0000 | [diff] [blame] | 50 | unsigned int counter_offset; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 51 | /* used for udc */ |
Bart De Schuymer | 0976590 | 2002-06-23 08:15:51 +0000 | [diff] [blame] | 52 | unsigned int hook_mask; |
Bart De Schuymer | 9bfcfd8 | 2005-08-27 16:52:19 +0000 | [diff] [blame] | 53 | char *kernel_start; |
Bart De Schuymer | 0976590 | 2002-06-23 08:15:51 +0000 | [diff] [blame] | 54 | char name[EBT_CHAIN_MAXNAMELEN]; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 55 | struct ebt_u_entry *entries; |
| 56 | }; |
| 57 | |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 58 | struct ebt_cntchanges |
| 59 | { |
| 60 | unsigned short type; |
Bart De Schuymer | 9d14e84 | 2005-05-24 20:49:27 +0000 | [diff] [blame] | 61 | unsigned short change; /* determines incremental/decremental/change */ |
Bart De Schuymer | 482fbaf | 2005-08-28 13:16:25 +0000 | [diff] [blame] | 62 | struct ebt_cntchanges *prev; |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 63 | struct ebt_cntchanges *next; |
| 64 | }; |
| 65 | |
Bart De Schuymer | 9bfcfd8 | 2005-08-27 16:52:19 +0000 | [diff] [blame] | 66 | #define EBT_ORI_MAX_CHAINS 10 |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 67 | struct ebt_u_replace |
| 68 | { |
| 69 | char name[EBT_TABLE_MAXNAMELEN]; |
| 70 | unsigned int valid_hooks; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 71 | /* nr of rules in the table */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 72 | unsigned int nentries; |
Bart De Schuymer | 9bfcfd8 | 2005-08-27 16:52:19 +0000 | [diff] [blame] | 73 | unsigned int num_chains; |
| 74 | unsigned int max_chains; |
| 75 | struct ebt_u_entries **chains; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 76 | /* nr of counters userspace expects back */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 77 | unsigned int num_counters; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 78 | /* where the kernel will put the old counters */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 79 | struct ebt_counter *counters; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 80 | /* |
| 81 | * can be used e.g. to know if a standard option |
| 82 | * has been specified twice |
| 83 | */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 84 | unsigned int flags; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 85 | /* we stick the specified command (e.g. -A) in here */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 86 | char command; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 87 | /* |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 88 | * here we stick the chain to do our thing on (can be -1 if unspecified) |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 89 | */ |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 90 | int selected_chain; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 91 | /* used for the atomic option */ |
Bart De Schuymer | 8330e89 | 2002-07-14 19:06:47 +0000 | [diff] [blame] | 92 | char *filename; |
Bart De Schuymer | 482fbaf | 2005-08-28 13:16:25 +0000 | [diff] [blame] | 93 | /* tells what happened to the old rules (counter changes) */ |
| 94 | struct ebt_cntchanges *cc; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | struct ebt_u_table |
| 98 | { |
| 99 | char name[EBT_TABLE_MAXNAMELEN]; |
Bart De Schuymer | f57f50f | 2002-08-29 16:52:36 +0000 | [diff] [blame] | 100 | void (*check)(struct ebt_u_replace *repl); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 101 | void (*help)(const char **); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 102 | struct ebt_u_table *next; |
| 103 | }; |
| 104 | |
| 105 | struct ebt_u_match_list |
| 106 | { |
| 107 | struct ebt_u_match_list *next; |
| 108 | struct ebt_entry_match *m; |
| 109 | }; |
| 110 | |
| 111 | struct ebt_u_watcher_list |
| 112 | { |
| 113 | struct ebt_u_watcher_list *next; |
| 114 | struct ebt_entry_watcher *w; |
| 115 | }; |
| 116 | |
| 117 | struct ebt_u_entry |
| 118 | { |
Bart De Schuymer | 376ccfb | 2002-07-23 20:52:18 +0000 | [diff] [blame] | 119 | unsigned int bitmask; |
| 120 | unsigned int invflags; |
Bart De Schuymer | 9cfd654 | 2002-08-13 16:08:08 +0000 | [diff] [blame] | 121 | uint16_t ethproto; |
Bart De Schuymer | 376ccfb | 2002-07-23 20:52:18 +0000 | [diff] [blame] | 122 | char in[IFNAMSIZ]; |
| 123 | char logical_in[IFNAMSIZ]; |
| 124 | char out[IFNAMSIZ]; |
| 125 | char logical_out[IFNAMSIZ]; |
Bart De Schuymer | e3cceb7 | 2002-07-26 12:47:33 +0000 | [diff] [blame] | 126 | unsigned char sourcemac[ETH_ALEN]; |
| 127 | unsigned char sourcemsk[ETH_ALEN]; |
| 128 | unsigned char destmac[ETH_ALEN]; |
| 129 | unsigned char destmsk[ETH_ALEN]; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 130 | struct ebt_u_match_list *m_list; |
| 131 | struct ebt_u_watcher_list *w_list; |
| 132 | struct ebt_entry_target *t; |
Bart De Schuymer | e94eaf7 | 2005-08-28 16:06:22 +0000 | [diff] [blame] | 133 | struct ebt_u_entry *prev; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 134 | struct ebt_u_entry *next; |
Bart De Schuymer | d2ced82 | 2005-01-23 19:19:00 +0000 | [diff] [blame] | 135 | struct ebt_counter cnt; |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 136 | struct ebt_counter cnt_surplus; /* for increasing/decreasing a counter and for option 'C' */ |
Bart De Schuymer | 482fbaf | 2005-08-28 13:16:25 +0000 | [diff] [blame] | 137 | struct ebt_cntchanges *cc; |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 138 | /* the standard target needs this to know the name of a udc when |
| 139 | * printing out rules. */ |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 140 | struct ebt_u_replace *replace; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | struct ebt_u_match |
| 144 | { |
| 145 | char name[EBT_FUNCTION_MAXNAMELEN]; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 146 | /* size of the real match data */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 147 | unsigned int size; |
| 148 | void (*help)(void); |
| 149 | void (*init)(struct ebt_entry_match *m); |
| 150 | int (*parse)(int c, char **argv, int argc, |
| 151 | const struct ebt_u_entry *entry, unsigned int *flags, |
| 152 | struct ebt_entry_match **match); |
| 153 | void (*final_check)(const struct ebt_u_entry *entry, |
| 154 | const struct ebt_entry_match *match, |
Bart De Schuymer | 76712df | 2002-08-25 21:54:06 +0000 | [diff] [blame] | 155 | const char *name, unsigned int hookmask, unsigned int time); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 156 | void (*print)(const struct ebt_u_entry *entry, |
| 157 | const struct ebt_entry_match *match); |
| 158 | int (*compare)(const struct ebt_entry_match *m1, |
| 159 | const struct ebt_entry_match *m2); |
| 160 | const struct option *extra_ops; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 161 | /* |
| 162 | * can be used e.g. to check for multiple occurance of the same option |
| 163 | */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 164 | unsigned int flags; |
| 165 | unsigned int option_offset; |
| 166 | struct ebt_entry_match *m; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 167 | /* |
| 168 | * if used == 1 we no longer have to add it to |
| 169 | * the match chain of the new entry |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 170 | * be sure to put it back on 0 when finished |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 171 | */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 172 | unsigned int used; |
| 173 | struct ebt_u_match *next; |
| 174 | }; |
| 175 | |
| 176 | struct ebt_u_watcher |
| 177 | { |
| 178 | char name[EBT_FUNCTION_MAXNAMELEN]; |
| 179 | unsigned int size; |
| 180 | void (*help)(void); |
| 181 | void (*init)(struct ebt_entry_watcher *w); |
| 182 | int (*parse)(int c, char **argv, int argc, |
| 183 | const struct ebt_u_entry *entry, unsigned int *flags, |
| 184 | struct ebt_entry_watcher **watcher); |
| 185 | void (*final_check)(const struct ebt_u_entry *entry, |
| 186 | const struct ebt_entry_watcher *watch, const char *name, |
Bart De Schuymer | 76712df | 2002-08-25 21:54:06 +0000 | [diff] [blame] | 187 | unsigned int hookmask, unsigned int time); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 188 | void (*print)(const struct ebt_u_entry *entry, |
| 189 | const struct ebt_entry_watcher *watcher); |
| 190 | int (*compare)(const struct ebt_entry_watcher *w1, |
| 191 | const struct ebt_entry_watcher *w2); |
| 192 | const struct option *extra_ops; |
| 193 | unsigned int flags; |
| 194 | unsigned int option_offset; |
| 195 | struct ebt_entry_watcher *w; |
| 196 | unsigned int used; |
| 197 | struct ebt_u_watcher *next; |
| 198 | }; |
| 199 | |
| 200 | struct ebt_u_target |
| 201 | { |
| 202 | char name[EBT_FUNCTION_MAXNAMELEN]; |
| 203 | unsigned int size; |
| 204 | void (*help)(void); |
| 205 | void (*init)(struct ebt_entry_target *t); |
| 206 | int (*parse)(int c, char **argv, int argc, |
| 207 | const struct ebt_u_entry *entry, unsigned int *flags, |
| 208 | struct ebt_entry_target **target); |
| 209 | void (*final_check)(const struct ebt_u_entry *entry, |
| 210 | const struct ebt_entry_target *target, const char *name, |
Bart De Schuymer | 76712df | 2002-08-25 21:54:06 +0000 | [diff] [blame] | 211 | unsigned int hookmask, unsigned int time); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 212 | void (*print)(const struct ebt_u_entry *entry, |
| 213 | const struct ebt_entry_target *target); |
| 214 | int (*compare)(const struct ebt_entry_target *t1, |
| 215 | const struct ebt_entry_target *t2); |
| 216 | const struct option *extra_ops; |
| 217 | unsigned int option_offset; |
| 218 | unsigned int flags; |
| 219 | struct ebt_entry_target *t; |
| 220 | unsigned int used; |
| 221 | struct ebt_u_target *next; |
| 222 | }; |
| 223 | |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 224 | /* libebtc.c */ |
| 225 | |
| 226 | extern struct ebt_u_table *ebt_tables; |
| 227 | extern struct ebt_u_match *ebt_matches; |
| 228 | extern struct ebt_u_watcher *ebt_watchers; |
| 229 | extern struct ebt_u_target *ebt_targets; |
| 230 | |
| 231 | void ebt_register_table(struct ebt_u_table *); |
| 232 | void ebt_register_match(struct ebt_u_match *); |
| 233 | void ebt_register_watcher(struct ebt_u_watcher *); |
| 234 | void ebt_register_target(struct ebt_u_target *t); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 235 | int ebt_get_kernel_table(struct ebt_u_replace *replace, int init); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 236 | struct ebt_u_target *ebt_find_target(const char *name); |
| 237 | struct ebt_u_match *ebt_find_match(const char *name); |
| 238 | struct ebt_u_watcher *ebt_find_watcher(const char *name); |
| 239 | struct ebt_u_table *ebt_find_table(const char *name); |
Bart De Schuymer | 0cb0179 | 2003-05-04 16:52:04 +0000 | [diff] [blame] | 240 | int ebtables_insmod(const char *modname); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 241 | void ebt_list_extensions(); |
| 242 | void ebt_initialize_entry(struct ebt_u_entry *e); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 243 | void ebt_cleanup_replace(struct ebt_u_replace *replace); |
| 244 | void ebt_reinit_extensions(); |
Bart De Schuymer | 9bfcfd8 | 2005-08-27 16:52:19 +0000 | [diff] [blame] | 245 | void ebt_double_chains(struct ebt_u_replace *replace); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 246 | void ebt_free_u_entry(struct ebt_u_entry *e); |
| 247 | struct ebt_u_entries *ebt_name_to_chain(const struct ebt_u_replace *replace, |
| 248 | const char* arg); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 249 | struct ebt_u_entries *ebt_name_to_chain(const struct ebt_u_replace *replace, |
| 250 | const char* arg); |
| 251 | int ebt_get_chainnr(const struct ebt_u_replace *replace, const char* arg); |
| 252 | /**/ |
| 253 | void ebt_change_policy(struct ebt_u_replace *replace, int policy); |
| 254 | void ebt_flush_chains(struct ebt_u_replace *replace); |
| 255 | int ebt_check_rule_exists(struct ebt_u_replace *replace, |
| 256 | struct ebt_u_entry *new_entry); |
| 257 | void ebt_add_rule(struct ebt_u_replace *replace, struct ebt_u_entry *new_entry, |
| 258 | int rule_nr); |
| 259 | void ebt_delete_rule(struct ebt_u_replace *replace, |
| 260 | struct ebt_u_entry *new_entry, int begin, int end); |
| 261 | void ebt_zero_counters(struct ebt_u_replace *replace); |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 262 | void ebt_change_counters(struct ebt_u_replace *replace, |
| 263 | struct ebt_u_entry *new_entry, int begin, int end, |
Bart De Schuymer | 9d14e84 | 2005-05-24 20:49:27 +0000 | [diff] [blame] | 264 | struct ebt_counter *cnt, int mask); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 265 | void ebt_new_chain(struct ebt_u_replace *replace, const char *name, int policy); |
| 266 | void ebt_delete_chain(struct ebt_u_replace *replace); |
| 267 | void ebt_rename_chain(struct ebt_u_replace *replace, const char *name); |
| 268 | /**/ |
| 269 | void ebt_do_final_checks(struct ebt_u_replace *replace, struct ebt_u_entry *e, |
| 270 | struct ebt_u_entries *entries); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 271 | int ebt_check_for_references(struct ebt_u_replace *replace, int print_err); |
| 272 | int ebt_check_for_references2(struct ebt_u_replace *replace, int chain_nr, |
| 273 | int print_err); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 274 | void ebt_check_for_loops(struct ebt_u_replace *replace); |
| 275 | void ebt_add_match(struct ebt_u_entry *new_entry, struct ebt_u_match *m); |
| 276 | void ebt_add_watcher(struct ebt_u_entry *new_entry, struct ebt_u_watcher *w); |
| 277 | void ebt_iterate_matches(void (*f)(struct ebt_u_match *)); |
| 278 | void ebt_iterate_watchers(void (*f)(struct ebt_u_watcher *)); |
| 279 | void ebt_iterate_targets(void (*f)(struct ebt_u_target *)); |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 280 | void __ebt_print_bug(char *file, int line, char *format, ...); |
| 281 | void __ebt_print_error(char *format, ...); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 282 | |
| 283 | /* communication.c */ |
| 284 | |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 285 | int ebt_get_table(struct ebt_u_replace *repl, int init); |
Bart De Schuymer | 83a1b0f | 2005-09-28 19:36:17 +0000 | [diff] [blame] | 286 | void ebt_deliver_counters(struct ebt_u_replace *repl); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 287 | void ebt_deliver_table(struct ebt_u_replace *repl); |
| 288 | |
| 289 | /* useful_functions.c */ |
| 290 | |
| 291 | extern int ebt_invert; |
| 292 | void ebt_check_option(unsigned int *flags, unsigned int mask); |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 293 | #define ebt_check_inverse(arg) _ebt_check_inverse(arg, argc, argv) |
| 294 | int _ebt_check_inverse(const char option[], int argc, char **argv); |
Bart De Schuymer | 510c9ce | 2006-01-23 18:50:54 +0000 | [diff] [blame] | 295 | void ebt_print_mac(const unsigned char *mac); |
| 296 | void ebt_print_mac_and_mask(const unsigned char *mac, const unsigned char *mask); |
| 297 | int ebt_get_mac_and_mask(const char *from, unsigned char *to, unsigned char *mask); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 298 | void ebt_parse_ip_address(char *address, uint32_t *addr, uint32_t *msk); |
| 299 | char *ebt_mask_to_dotted(uint32_t mask); |
| 300 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 301 | int do_command(int argc, char *argv[], int exec_style, |
| 302 | struct ebt_u_replace *replace_); |
| 303 | |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 304 | struct ethertypeent *parseethertypebynumber(int type); |
| 305 | |
Bart De Schuymer | 482fbaf | 2005-08-28 13:16:25 +0000 | [diff] [blame] | 306 | #define ebt_to_chain(repl) \ |
| 307 | ({struct ebt_u_entries *_ch = NULL; \ |
Bart De Schuymer | cdc2cd0 | 2005-10-01 20:12:50 +0000 | [diff] [blame] | 308 | if (repl->selected_chain != -1) \ |
Bart De Schuymer | 482fbaf | 2005-08-28 13:16:25 +0000 | [diff] [blame] | 309 | _ch = repl->chains[repl->selected_chain]; \ |
| 310 | _ch;}) |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 311 | #define ebt_print_bug(format, args...) \ |
| 312 | __ebt_print_bug(__FILE__, __LINE__, format, ##args) |
| 313 | #define ebt_print_error(format,args...) __ebt_print_error(format, ##args); |
Bart De Schuymer | cdc2cd0 | 2005-10-01 20:12:50 +0000 | [diff] [blame] | 314 | #define ebt_print_error2(format, args...) do {__ebt_print_error(format, ##args); \ |
| 315 | return -1;} while (0) |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 316 | #define ebt_check_option2(flags,mask) \ |
| 317 | ({ebt_check_option(flags,mask); \ |
| 318 | if (ebt_errormsg[0] != '\0') \ |
| 319 | return -1;}) |
| 320 | #define ebt_check_inverse2(option) \ |
| 321 | ({int __ret = ebt_check_inverse(option); \ |
| 322 | if (ebt_errormsg[0] != '\0') \ |
| 323 | return -1; \ |
| 324 | if (!optarg) { \ |
| 325 | __ebt_print_error("Option without (mandatory) argument"); \ |
| 326 | return -1; \ |
| 327 | } \ |
| 328 | __ret;}) |
Bart De Schuymer | 02619f4 | 2005-10-02 12:10:07 +0000 | [diff] [blame] | 329 | #define ebt_print_memory() do {printf("Ebtables: " __FILE__ \ |
| 330 | " %s %d :Out of memory.\n", __FUNCTION__, __LINE__); exit(-1);} while (0) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 331 | |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 332 | /* used for keeping the rule counters right during rule adds or deletes */ |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 333 | #define CNT_NORM 0 |
| 334 | #define CNT_DEL 1 |
| 335 | #define CNT_ADD 2 |
Bart De Schuymer | 482fbaf | 2005-08-28 13:16:25 +0000 | [diff] [blame] | 336 | #define CNT_CHANGE 3 |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 337 | |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 338 | extern const char *ebt_hooknames[NF_BR_NUMHOOKS]; |
| 339 | extern const char *ebt_standard_targets[NUM_STANDARD_TARGETS]; |
| 340 | extern char ebt_errormsg[ERRORMSG_MAXLEN]; |
| 341 | extern char *ebt_modprobe; |
| 342 | extern int ebt_silent; |
| 343 | extern int ebt_printstyle_mac; |
| 344 | |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 345 | /* |
| 346 | * Transforms a target string into the right integer, |
| 347 | * returns 0 on success. |
| 348 | */ |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 349 | #define FILL_TARGET(_str, _pos) ({ \ |
| 350 | int _i, _ret = 0; \ |
| 351 | for (_i = 0; _i < NUM_STANDARD_TARGETS; _i++) \ |
| 352 | if (!strcmp(_str, ebt_standard_targets[_i])) {\ |
| 353 | _pos = -_i - 1; \ |
| 354 | break; \ |
| 355 | } \ |
| 356 | if (_i == NUM_STANDARD_TARGETS) \ |
| 357 | _ret = 1; \ |
| 358 | _ret; \ |
Bart De Schuymer | 9cfd654 | 2002-08-13 16:08:08 +0000 | [diff] [blame] | 359 | }) |
| 360 | |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 361 | /* Transforms the target value to an index into standard_targets[] */ |
Bart De Schuymer | 9cfd654 | 2002-08-13 16:08:08 +0000 | [diff] [blame] | 362 | #define TARGET_INDEX(_value) (-_value - 1) |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 363 | /* Returns a target string corresponding to the value */ |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 364 | #define TARGET_NAME(_value) (ebt_standard_targets[TARGET_INDEX(_value)]) |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 365 | /* True if the hook mask denotes that the rule is in a base chain */ |
Bart De Schuymer | 76712df | 2002-08-25 21:54:06 +0000 | [diff] [blame] | 366 | #define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS)) |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 367 | /* Clear the bit in the hook_mask that tells if the rule is on a base chain */ |
Bart De Schuymer | 76712df | 2002-08-25 21:54:06 +0000 | [diff] [blame] | 368 | #define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS)) |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 369 | #define PRINT_VERSION printf(PROGNAME" v"PROGVERSION" ("PROGDATE")\n") |
| 370 | #ifndef PROC_SYS_MODPROBE |
| 371 | #define PROC_SYS_MODPROBE "/proc/sys/kernel/modprobe" |
| 372 | #endif |
| 373 | #define ATOMIC_ENV_VARIABLE "EBTABLES_ATOMIC_FILE" |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 374 | #endif /* EBTABLES_U_H */ |