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 |
| 26 | #include <linux/netfilter_bridge/ebtables.h> |
| 27 | #include <linux/br_db.h> |
| 28 | |
| 29 | struct ebt_u_entries |
| 30 | { |
| 31 | __u8 policy; |
| 32 | __u32 nentries; |
| 33 | struct ebt_u_entry *entries; |
| 34 | }; |
| 35 | |
| 36 | |
| 37 | struct ebt_u_replace |
| 38 | { |
| 39 | char name[EBT_TABLE_MAXNAMELEN]; |
| 40 | unsigned int valid_hooks; |
| 41 | // nr of rules in the table |
| 42 | unsigned int nentries; |
| 43 | struct ebt_u_entries *hook_entry[NF_BR_NUMHOOKS]; |
| 44 | // how many counters in front of it? |
| 45 | unsigned int counter_entry[NF_BR_NUMHOOKS]; |
| 46 | // nr of counters userspace expects back |
| 47 | unsigned int num_counters; |
| 48 | // where the kernel will put the old counters |
| 49 | struct ebt_counter *counters; |
| 50 | // can be used e.g. to know if a standard option |
| 51 | // has been specified twice |
| 52 | unsigned int flags; |
| 53 | // we stick the specified command (e.g. -A) in here |
| 54 | char command; |
| 55 | // here we stick the hook to do our thing on (can be -1 if unspecified) |
| 56 | int selected_hook; |
| 57 | }; |
| 58 | |
| 59 | struct ebt_u_table |
| 60 | { |
| 61 | char name[EBT_TABLE_MAXNAMELEN]; |
| 62 | int (*check)(struct ebt_u_replace *repl); |
| 63 | void (*help)(char **); |
| 64 | struct ebt_u_table *next; |
| 65 | }; |
| 66 | |
| 67 | struct ebt_u_match_list |
| 68 | { |
| 69 | struct ebt_u_match_list *next; |
| 70 | struct ebt_entry_match *m; |
| 71 | }; |
| 72 | |
| 73 | struct ebt_u_watcher_list |
| 74 | { |
| 75 | struct ebt_u_watcher_list *next; |
| 76 | struct ebt_entry_watcher *w; |
| 77 | }; |
| 78 | |
| 79 | struct ebt_u_entry |
| 80 | { |
| 81 | __u32 bitmask; |
| 82 | __u32 invflags; |
| 83 | __u16 ethproto; |
| 84 | __u8 in[IFNAMSIZ]; |
| 85 | __u8 logical_in[IFNAMSIZ]; |
| 86 | __u8 out[IFNAMSIZ]; |
| 87 | __u8 logical_out[IFNAMSIZ]; |
| 88 | __u8 sourcemac[ETH_ALEN]; |
| 89 | __u8 sourcemsk[ETH_ALEN]; |
| 90 | __u8 destmac[ETH_ALEN]; |
| 91 | __u8 destmsk[ETH_ALEN]; |
| 92 | struct ebt_u_match_list *m_list; |
| 93 | struct ebt_u_watcher_list *w_list; |
| 94 | struct ebt_entry_target *t; |
| 95 | struct ebt_u_entry *next; |
| 96 | }; |
| 97 | |
| 98 | struct ebt_u_match |
| 99 | { |
| 100 | char name[EBT_FUNCTION_MAXNAMELEN]; |
| 101 | // size of the real match data + sizeof struct ebt_match |
| 102 | unsigned int size; |
| 103 | void (*help)(void); |
| 104 | void (*init)(struct ebt_entry_match *m); |
| 105 | int (*parse)(int c, char **argv, int argc, |
| 106 | const struct ebt_u_entry *entry, unsigned int *flags, |
| 107 | struct ebt_entry_match **match); |
| 108 | void (*final_check)(const struct ebt_u_entry *entry, |
| 109 | const struct ebt_entry_match *match, |
| 110 | const char *name, unsigned int hook); |
| 111 | void (*print)(const struct ebt_u_entry *entry, |
| 112 | const struct ebt_entry_match *match); |
| 113 | int (*compare)(const struct ebt_entry_match *m1, |
| 114 | const struct ebt_entry_match *m2); |
| 115 | const struct option *extra_ops; |
| 116 | // can be used e.g. to check for multiple occurance of the same option |
| 117 | unsigned int flags; |
| 118 | unsigned int option_offset; |
| 119 | struct ebt_entry_match *m; |
| 120 | // if used == 1 we no longer have to add it to |
| 121 | // the match chain of the new entry |
| 122 | unsigned int used; |
| 123 | struct ebt_u_match *next; |
| 124 | }; |
| 125 | |
| 126 | struct ebt_u_watcher |
| 127 | { |
| 128 | char name[EBT_FUNCTION_MAXNAMELEN]; |
| 129 | unsigned int size; |
| 130 | void (*help)(void); |
| 131 | void (*init)(struct ebt_entry_watcher *w); |
| 132 | int (*parse)(int c, char **argv, int argc, |
| 133 | const struct ebt_u_entry *entry, unsigned int *flags, |
| 134 | struct ebt_entry_watcher **watcher); |
| 135 | void (*final_check)(const struct ebt_u_entry *entry, |
| 136 | const struct ebt_entry_watcher *watch, const char *name, |
| 137 | unsigned int hook); |
| 138 | void (*print)(const struct ebt_u_entry *entry, |
| 139 | const struct ebt_entry_watcher *watcher); |
| 140 | int (*compare)(const struct ebt_entry_watcher *w1, |
| 141 | const struct ebt_entry_watcher *w2); |
| 142 | const struct option *extra_ops; |
| 143 | unsigned int flags; |
| 144 | unsigned int option_offset; |
| 145 | struct ebt_entry_watcher *w; |
| 146 | unsigned int used; |
| 147 | struct ebt_u_watcher *next; |
| 148 | }; |
| 149 | |
| 150 | struct ebt_u_target |
| 151 | { |
| 152 | char name[EBT_FUNCTION_MAXNAMELEN]; |
| 153 | unsigned int size; |
| 154 | void (*help)(void); |
| 155 | void (*init)(struct ebt_entry_target *t); |
| 156 | int (*parse)(int c, char **argv, int argc, |
| 157 | const struct ebt_u_entry *entry, unsigned int *flags, |
| 158 | struct ebt_entry_target **target); |
| 159 | void (*final_check)(const struct ebt_u_entry *entry, |
| 160 | const struct ebt_entry_target *target, const char *name, |
| 161 | unsigned int hook); |
| 162 | void (*print)(const struct ebt_u_entry *entry, |
| 163 | const struct ebt_entry_target *target); |
| 164 | int (*compare)(const struct ebt_entry_target *t1, |
| 165 | const struct ebt_entry_target *t2); |
| 166 | const struct option *extra_ops; |
| 167 | unsigned int option_offset; |
| 168 | unsigned int flags; |
| 169 | struct ebt_entry_target *t; |
| 170 | unsigned int used; |
| 171 | struct ebt_u_target *next; |
| 172 | }; |
| 173 | |
| 174 | void register_table(struct ebt_u_table *); |
| 175 | void register_match(struct ebt_u_match *); |
| 176 | void register_watcher(struct ebt_u_watcher *); |
| 177 | void register_target(struct ebt_u_target *t); |
| 178 | void get_table(struct ebt_u_replace *repl); |
| 179 | struct ebt_u_target *find_target(const char *name); |
| 180 | struct ebt_u_match *find_match(const char *name); |
| 181 | struct ebt_u_watcher *find_watcher(const char *name); |
| 182 | void deliver_counters(struct ebt_u_replace *repl, |
| 183 | unsigned short * counterchanges); |
| 184 | void deliver_table(struct ebt_u_replace *repl); |
| 185 | void get_dbinfo(struct brdb_dbinfo *nr); |
| 186 | void get_db(int len, struct brdb_dbentry *db); |
| 187 | void deliver_allowdb(__u16 *decision); |
Bart De Schuymer | e2ac8a8 | 2002-06-03 16:29:12 +0000 | [diff] [blame] | 188 | int name_to_protocol(char *name); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 189 | void check_option(unsigned int *flags, unsigned int mask); |
| 190 | int check_inverse(const char option[]); |
| 191 | #define print_bug(format, args...) \ |
| 192 | {printf("BUG: "format".\n", ##args); exit(-1);} |
| 193 | #define print_error(format, args...) {printf(format".\n", ##args); exit(-1);} |
| 194 | #define print_memory() {printf("Ebtables: " __FILE__ " " __FUNCTION__ \ |
| 195 | " %d :Out of memory.\n", __LINE__); exit(-1);} |
| 196 | |
| 197 | |
| 198 | |
| 199 | // used for keeping the rule counters right during rule adds or deletes |
| 200 | #define CNT_NORM 0 |
| 201 | #define CNT_DEL 1 |
| 202 | #define CNT_ADD 2 |
| 203 | #define CNT_END 3 |
| 204 | #define CNT_ZERO 4 |
| 205 | |
| 206 | #endif /* EBTABLES_U_H */ |