Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1 | /* |
Bart De Schuymer | c56a31a | 2002-07-25 08:16:08 +0000 | [diff] [blame] | 2 | * ebtables.c, v2.0 July 2002 |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 3 | * |
| 4 | * Author: Bart De Schuymer |
| 5 | * |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 6 | * This code was stongly inspired on the iptables code which is |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 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 | #include <getopt.h> |
| 25 | #include <string.h> |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 28 | #include "include/ebtables_u.h" |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 29 | #include "include/ethernetdb.h" |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 30 | |
Bart De Schuymer | 229079b | 2005-06-18 14:42:21 +0000 | [diff] [blame] | 31 | /* Checks whether a command has already been specified */ |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 32 | #define OPT_COMMANDS (replace->flags & OPT_COMMAND || replace->flags & OPT_ZERO) |
| 33 | |
| 34 | #define OPT_COMMAND 0x01 |
| 35 | #define OPT_TABLE 0x02 |
| 36 | #define OPT_IN 0x04 |
| 37 | #define OPT_OUT 0x08 |
| 38 | #define OPT_JUMP 0x10 |
| 39 | #define OPT_PROTOCOL 0x20 |
| 40 | #define OPT_SOURCE 0x40 |
| 41 | #define OPT_DEST 0x80 |
| 42 | #define OPT_ZERO 0x100 |
| 43 | #define OPT_LOGICALIN 0x200 |
| 44 | #define OPT_LOGICALOUT 0x400 |
| 45 | #define OPT_KERNELDATA 0x800 /* This value is also defined in ebtablesd.c */ |
| 46 | #define OPT_COUNT 0x1000 /* This value is also defined in libebtc.c */ |
| 47 | #define OPT_CNT_INCR 0x2000 /* This value is also defined in libebtc.c */ |
| 48 | #define OPT_CNT_DECR 0x4000 /* This value is also defined in libebtc.c */ |
| 49 | |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 50 | /* Default command line options. Do not mess around with the already |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 51 | * assigned numbers unless you know what you are doing */ |
Bart De Schuymer | 6242374 | 2002-07-14 19:06:20 +0000 | [diff] [blame] | 52 | static struct option ebt_original_options[] = |
| 53 | { |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 54 | { "append" , required_argument, 0, 'A' }, |
| 55 | { "insert" , required_argument, 0, 'I' }, |
| 56 | { "delete" , required_argument, 0, 'D' }, |
| 57 | { "list" , optional_argument, 0, 'L' }, |
| 58 | { "Lc" , no_argument , 0, 4 }, |
| 59 | { "Ln" , no_argument , 0, 5 }, |
| 60 | { "Lx" , no_argument , 0, 6 }, |
| 61 | { "Lmac2" , no_argument , 0, 12 }, |
| 62 | { "zero" , optional_argument, 0, 'Z' }, |
| 63 | { "flush" , optional_argument, 0, 'F' }, |
| 64 | { "policy" , required_argument, 0, 'P' }, |
| 65 | { "in-interface" , required_argument, 0, 'i' }, |
| 66 | { "in-if" , required_argument, 0, 'i' }, |
| 67 | { "logical-in" , required_argument, 0, 2 }, |
| 68 | { "logical-out" , required_argument, 0, 3 }, |
| 69 | { "out-interface" , required_argument, 0, 'o' }, |
| 70 | { "out-if" , required_argument, 0, 'o' }, |
| 71 | { "version" , no_argument , 0, 'V' }, |
| 72 | { "help" , no_argument , 0, 'h' }, |
| 73 | { "jump" , required_argument, 0, 'j' }, |
| 74 | { "set-counters" , required_argument, 0, 'c' }, |
| 75 | { "change-counters", required_argument, 0, 'C' }, |
| 76 | { "proto" , required_argument, 0, 'p' }, |
| 77 | { "protocol" , required_argument, 0, 'p' }, |
| 78 | { "db" , required_argument, 0, 'b' }, |
| 79 | { "source" , required_argument, 0, 's' }, |
| 80 | { "src" , required_argument, 0, 's' }, |
| 81 | { "destination" , required_argument, 0, 'd' }, |
| 82 | { "dst" , required_argument, 0, 'd' }, |
| 83 | { "table" , required_argument, 0, 't' }, |
| 84 | { "modprobe" , required_argument, 0, 'M' }, |
| 85 | { "new-chain" , required_argument, 0, 'N' }, |
| 86 | { "rename-chain" , required_argument, 0, 'E' }, |
| 87 | { "delete-chain" , optional_argument, 0, 'X' }, |
| 88 | { "atomic-init" , no_argument , 0, 7 }, |
| 89 | { "atomic-commit" , no_argument , 0, 8 }, |
| 90 | { "atomic-file" , required_argument, 0, 9 }, |
| 91 | { "atomic-save" , no_argument , 0, 10 }, |
| 92 | { "init-table" , no_argument , 0, 11 }, |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 93 | { 0 } |
| 94 | }; |
| 95 | |
| 96 | static struct option *ebt_options = ebt_original_options; |
| 97 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 98 | /* Holds all the data */ |
| 99 | static struct ebt_u_replace *replace; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 100 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 101 | /* The chosen table */ |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 102 | static struct ebt_u_table *table; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 103 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 104 | /* The pointers in here are special: |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 105 | * The struct ebt_target pointer is actually a struct ebt_u_target pointer. |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 106 | * I do not feel like using a union. |
Bart De Schuymer | 229079b | 2005-06-18 14:42:21 +0000 | [diff] [blame] | 107 | * We need a struct ebt_u_target pointer because we know the address of the data |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 108 | * they point to won't change. We want to allow that the struct ebt_u_target.t |
| 109 | * member can change. |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 110 | * The same holds for the struct ebt_match and struct ebt_watcher pointers */ |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 111 | static struct ebt_u_entry *new_entry; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 112 | |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 113 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 114 | static int global_option_offset; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 115 | #define OPTION_OFFSET 256 |
Bart De Schuymer | 229079b | 2005-06-18 14:42:21 +0000 | [diff] [blame] | 116 | static struct option *merge_options(struct option *oldopts, |
| 117 | const struct option *newopts, unsigned int *options_offset) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 118 | { |
| 119 | unsigned int num_old, num_new, i; |
| 120 | struct option *merge; |
| 121 | |
| 122 | if (!newopts || !oldopts || !options_offset) |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 123 | ebt_print_bug("merge wrong"); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 124 | for (num_old = 0; oldopts[num_old].name; num_old++); |
| 125 | for (num_new = 0; newopts[num_new].name; num_new++); |
| 126 | |
| 127 | global_option_offset += OPTION_OFFSET; |
| 128 | *options_offset = global_option_offset; |
| 129 | |
| 130 | merge = malloc(sizeof(struct option) * (num_new + num_old + 1)); |
| 131 | if (!merge) |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 132 | ebt_print_memory(); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 133 | memcpy(merge, oldopts, num_old * sizeof(struct option)); |
| 134 | for (i = 0; i < num_new; i++) { |
| 135 | merge[num_old + i] = newopts[i]; |
| 136 | merge[num_old + i].val += *options_offset; |
| 137 | } |
| 138 | memset(merge + num_old + num_new, 0, sizeof(struct option)); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 139 | /* Only free dynamically allocated stuff */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 140 | if (oldopts != ebt_original_options) |
| 141 | free(oldopts); |
| 142 | |
| 143 | return merge; |
| 144 | } |
| 145 | |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 146 | static void merge_match(struct ebt_u_match *m) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 147 | { |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 148 | ebt_options = merge_options |
| 149 | (ebt_options, m->extra_ops, &(m->option_offset)); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 152 | static void merge_watcher(struct ebt_u_watcher *w) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 153 | { |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 154 | ebt_options = merge_options |
| 155 | (ebt_options, w->extra_ops, &(w->option_offset)); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 158 | static void merge_target(struct ebt_u_target *t) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 159 | { |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 160 | ebt_options = merge_options |
| 161 | (ebt_options, t->extra_ops, &(t->option_offset)); |
Bart De Schuymer | 9a0fbf2 | 2003-01-11 16:16:54 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 164 | /* Be backwards compatible, so don't use '+' in kernel */ |
Bart De Schuymer | 37d520d | 2004-10-24 07:36:15 +0000 | [diff] [blame] | 165 | #define IF_WILDCARD 1 |
| 166 | static void print_iface(const char *iface) |
| 167 | { |
| 168 | char *c; |
| 169 | |
| 170 | if ((c = strchr(iface, IF_WILDCARD))) |
| 171 | *c = '+'; |
| 172 | printf("%s ", iface); |
| 173 | if (c) |
| 174 | *c = IF_WILDCARD; |
| 175 | } |
| 176 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 177 | /* We use replace->flags, so we can't use the following values: |
| 178 | * 0x01 == OPT_COMMAND, 0x02 == OPT_TABLE, 0x100 == OPT_ZERO */ |
Bart De Schuymer | 22d03a2 | 2003-05-03 20:28:22 +0000 | [diff] [blame] | 179 | #define LIST_N 0x04 |
| 180 | #define LIST_C 0x08 |
| 181 | #define LIST_X 0x10 |
| 182 | #define LIST_MAC2 0x20 |
| 183 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 184 | /* Helper function for list_rules() */ |
Bart De Schuymer | 482fbaf | 2005-08-28 13:16:25 +0000 | [diff] [blame] | 185 | static void list_em(struct ebt_u_entries *entries) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 186 | { |
| 187 | int i, j, space = 0, digits; |
| 188 | struct ebt_u_entry *hlp; |
| 189 | struct ebt_u_match_list *m_l; |
| 190 | struct ebt_u_watcher_list *w_l; |
| 191 | struct ebt_u_match *m; |
| 192 | struct ebt_u_watcher *w; |
| 193 | struct ebt_u_target *t; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 194 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 195 | if (replace->flags & LIST_MAC2) |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 196 | ebt_printstyle_mac = 2; |
Bart De Schuymer | 229079b | 2005-06-18 14:42:21 +0000 | [diff] [blame] | 197 | else |
| 198 | ebt_printstyle_mac = 0; |
Bart De Schuymer | e94eaf7 | 2005-08-28 16:06:22 +0000 | [diff] [blame] | 199 | hlp = entries->entries->next; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 200 | if (replace->flags & LIST_X && entries->policy != EBT_ACCEPT) { |
| 201 | printf("ebtables -t %s -P %s %s\n", replace->name, |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 202 | entries->name, ebt_standard_targets[-entries->policy - 1]); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 203 | } else if (!(replace->flags & LIST_X)) { |
Bart De Schuymer | c87c964 | 2002-08-01 15:34:16 +0000 | [diff] [blame] | 204 | printf("\nBridge chain: %s, entries: %d, policy: %s\n", |
| 205 | entries->name, entries->nentries, |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 206 | ebt_standard_targets[-entries->policy - 1]); |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 207 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 208 | |
Bart De Schuymer | 229079b | 2005-06-18 14:42:21 +0000 | [diff] [blame] | 209 | if (replace->flags & LIST_N) { |
| 210 | i = entries->nentries; |
| 211 | while (i > 9) { |
| 212 | space++; |
| 213 | i /= 10; |
| 214 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 217 | for (i = 0; i < entries->nentries; i++) { |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 218 | if (replace->flags & LIST_N) { |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 219 | digits = 0; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 220 | /* A little work to get nice rule numbers. */ |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 221 | j = i + 1; |
| 222 | while (j > 9) { |
| 223 | digits++; |
| 224 | j /= 10; |
| 225 | } |
| 226 | for (j = 0; j < space - digits; j++) |
| 227 | printf(" "); |
| 228 | printf("%d. ", i + 1); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 229 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 230 | if (replace->flags & LIST_X) |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 231 | printf("ebtables -t %s -A %s ", |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 232 | replace->name, entries->name); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 233 | |
Bart De Schuymer | caa9a46 | 2004-12-05 15:59:17 +0000 | [diff] [blame] | 234 | /* The standard target's print() uses this to find out |
| 235 | * the name of a udc */ |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 236 | hlp->replace = replace; |
Bart De Schuymer | caa9a46 | 2004-12-05 15:59:17 +0000 | [diff] [blame] | 237 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 238 | /* Don't print anything about the protocol if no protocol was |
| 239 | * specified, obviously this means any protocol will do. */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 240 | if (!(hlp->bitmask & EBT_NOPROTO)) { |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 241 | printf("-p "); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 242 | if (hlp->invflags & EBT_IPROTO) |
| 243 | printf("! "); |
| 244 | if (hlp->bitmask & EBT_802_3) |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 245 | printf("Length "); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 246 | else { |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 247 | struct ethertypeent *ent; |
| 248 | |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 249 | ent = getethertypebynumber(ntohs(hlp->ethproto)); |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 250 | if (!ent) |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 251 | printf("0x%x ", ntohs(hlp->ethproto)); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 252 | else |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 253 | printf("%s ", ent->e_name); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | if (hlp->bitmask & EBT_SOURCEMAC) { |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 257 | printf("-s "); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 258 | if (hlp->invflags & EBT_ISOURCE) |
| 259 | printf("! "); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 260 | ebt_print_mac_and_mask(hlp->sourcemac, hlp->sourcemsk); |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 261 | printf(" "); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 262 | } |
| 263 | if (hlp->bitmask & EBT_DESTMAC) { |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 264 | printf("-d "); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 265 | if (hlp->invflags & EBT_IDEST) |
| 266 | printf("! "); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 267 | ebt_print_mac_and_mask(hlp->destmac, hlp->destmsk); |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 268 | printf(" "); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 269 | } |
| 270 | if (hlp->in[0] != '\0') { |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 271 | printf("-i "); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 272 | if (hlp->invflags & EBT_IIN) |
| 273 | printf("! "); |
Bart De Schuymer | 37d520d | 2004-10-24 07:36:15 +0000 | [diff] [blame] | 274 | print_iface(hlp->in); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 275 | } |
| 276 | if (hlp->logical_in[0] != '\0') { |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 277 | printf("--logical-in "); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 278 | if (hlp->invflags & EBT_ILOGICALIN) |
| 279 | printf("! "); |
Bart De Schuymer | 37d520d | 2004-10-24 07:36:15 +0000 | [diff] [blame] | 280 | print_iface(hlp->logical_in); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 281 | } |
| 282 | if (hlp->logical_out[0] != '\0') { |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 283 | printf("--logical-out "); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 284 | if (hlp->invflags & EBT_ILOGICALOUT) |
| 285 | printf("! "); |
Bart De Schuymer | 37d520d | 2004-10-24 07:36:15 +0000 | [diff] [blame] | 286 | print_iface(hlp->logical_out); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 287 | } |
| 288 | if (hlp->out[0] != '\0') { |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 289 | printf("-o "); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 290 | if (hlp->invflags & EBT_IOUT) |
| 291 | printf("! "); |
Bart De Schuymer | 37d520d | 2004-10-24 07:36:15 +0000 | [diff] [blame] | 292 | print_iface(hlp->out); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | m_l = hlp->m_list; |
| 296 | while (m_l) { |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 297 | m = ebt_find_match(m_l->m->u.name); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 298 | if (!m) |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 299 | ebt_print_bug("Match not found"); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 300 | m->print(hlp, m_l->m); |
| 301 | m_l = m_l->next; |
| 302 | } |
| 303 | w_l = hlp->w_list; |
| 304 | while (w_l) { |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 305 | w = ebt_find_watcher(w_l->w->u.name); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 306 | if (!w) |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 307 | ebt_print_bug("Watcher not found"); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 308 | w->print(hlp, w_l->w); |
| 309 | w_l = w_l->next; |
| 310 | } |
| 311 | |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 312 | printf("-j "); |
| 313 | if (strcmp(hlp->t->u.name, EBT_STANDARD_TARGET)) |
| 314 | printf("%s ", hlp->t->u.name); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 315 | t = ebt_find_target(hlp->t->u.name); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 316 | if (!t) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 317 | ebt_print_bug("Target '%s' not found", hlp->t->u.name); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 318 | t->print(hlp, hlp->t); |
Bart De Schuymer | b5917d8 | 2005-01-25 21:15:59 +0000 | [diff] [blame] | 319 | if (replace->flags & LIST_C) { |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 320 | uint64_t pcnt = hlp->cnt.pcnt; |
| 321 | uint64_t bcnt = hlp->cnt.bcnt; |
| 322 | |
Bart De Schuymer | b5917d8 | 2005-01-25 21:15:59 +0000 | [diff] [blame] | 323 | if (replace->flags & LIST_X) |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 324 | printf("-c %llu %llu", pcnt, bcnt); |
Bart De Schuymer | b5917d8 | 2005-01-25 21:15:59 +0000 | [diff] [blame] | 325 | else |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 326 | printf(", pcnt = %llu -- bcnt = %llu", pcnt, bcnt); |
Bart De Schuymer | b5917d8 | 2005-01-25 21:15:59 +0000 | [diff] [blame] | 327 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 328 | printf("\n"); |
| 329 | hlp = hlp->next; |
| 330 | } |
| 331 | } |
| 332 | |
Bart De Schuymer | 6242374 | 2002-07-14 19:06:20 +0000 | [diff] [blame] | 333 | static void print_help() |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 334 | { |
| 335 | struct ebt_u_match_list *m_l; |
| 336 | struct ebt_u_watcher_list *w_l; |
| 337 | |
Bart De Schuymer | 57a3f6a | 2003-04-01 16:59:33 +0000 | [diff] [blame] | 338 | PRINT_VERSION; |
| 339 | printf( |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 340 | "Usage:\n" |
| 341 | "ebtables -[ADI] chain rule-specification [options]\n" |
| 342 | "ebtables -P chain target\n" |
| 343 | "ebtables -[LFZ] [chain]\n" |
Bart De Schuymer | 5885b36 | 2002-12-03 20:51:36 +0000 | [diff] [blame] | 344 | "ebtables -[NX] [chain]\n" |
| 345 | "ebtables -E old-chain-name new-chain-name\n\n" |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 346 | "Commands:\n" |
Bart De Schuymer | 23f6dcf | 2002-08-17 09:14:07 +0000 | [diff] [blame] | 347 | "--append -A chain : append to chain\n" |
| 348 | "--delete -D chain : delete matching rule from chain\n" |
| 349 | "--delete -D chain rulenum : delete rule at position rulenum from chain\n" |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 350 | "--change-counters -C chain\n" |
| 351 | " [rulenum] pcnt bcnt : change counters of existing rule\n" |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 352 | "--insert -I chain rulenum : insert rule at position rulenum in chain\n" |
Bart De Schuymer | 23f6dcf | 2002-08-17 09:14:07 +0000 | [diff] [blame] | 353 | "--list -L [chain] : list the rules in a chain or in all chains\n" |
| 354 | "--flush -F [chain] : delete all rules in chain or in all chains\n" |
| 355 | "--init-table : replace the kernel table with the initial table\n" |
| 356 | "--zero -Z [chain] : put counters on zero in chain or in all chains\n" |
| 357 | "--policy -P chain target : change policy on chain to target\n" |
| 358 | "--new-chain -N chain : create a user defined chain\n" |
| 359 | "--rename-chain -E old new : rename a chain\n" |
Bart De Schuymer | 90f2c2e | 2003-07-13 18:48:02 +0000 | [diff] [blame] | 360 | "--delete-chain -X [chain] : delete a user defined chain\n" |
Bart De Schuymer | 5885b36 | 2002-12-03 20:51:36 +0000 | [diff] [blame] | 361 | "--atomic-commit : update the kernel w/t table contained in <FILE>\n" |
| 362 | "--atomic-init : put the initial kernel table into <FILE>\n" |
| 363 | "--atomic-save : put the current kernel table into <FILE>\n" |
Bart De Schuymer | 9781996 | 2002-12-11 21:23:07 +0000 | [diff] [blame] | 364 | "--atomic-file file : set <FILE> to file\n\n" |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 365 | "Options:\n" |
| 366 | "--proto -p [!] proto : protocol hexadecimal, by name or LENGTH\n" |
| 367 | "--src -s [!] address[/mask]: source mac address\n" |
| 368 | "--dst -d [!] address[/mask]: destination mac address\n" |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 369 | "--in-if -i [!] name[+] : network input interface name\n" |
| 370 | "--out-if -o [!] name[+] : network output interface name\n" |
| 371 | "--logical-in [!] name[+] : logical bridge input interface name\n" |
| 372 | "--logical-out [!] name[+] : logical bridge output interface name\n" |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 373 | "--set-counters -c chain\n" |
| 374 | " pcnt bcnt : set the counters of the to be added rule\n" |
Bart De Schuymer | 5cbc8e0 | 2002-07-14 21:15:28 +0000 | [diff] [blame] | 375 | "--modprobe -M program : try to insert modules using this program\n" |
Bart De Schuymer | 5885b36 | 2002-12-03 20:51:36 +0000 | [diff] [blame] | 376 | "--version -V : print package version\n\n" |
| 377 | "Environment variable:\n" |
| 378 | ATOMIC_ENV_VARIABLE " : if set <FILE> (see above) will equal its value" |
| 379 | "\n\n"); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 380 | m_l = new_entry->m_list; |
| 381 | while (m_l) { |
| 382 | ((struct ebt_u_match *)m_l->m)->help(); |
| 383 | printf("\n"); |
| 384 | m_l = m_l->next; |
| 385 | } |
| 386 | w_l = new_entry->w_list; |
| 387 | while (w_l) { |
| 388 | ((struct ebt_u_watcher *)w_l->w)->help(); |
| 389 | printf("\n"); |
| 390 | w_l = w_l->next; |
| 391 | } |
| 392 | ((struct ebt_u_target *)new_entry->t)->help(); |
| 393 | printf("\n"); |
| 394 | if (table->help) |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 395 | table->help(ebt_hooknames); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 398 | /* Execute command L */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 399 | static void list_rules() |
| 400 | { |
Bart De Schuymer | 229079b | 2005-06-18 14:42:21 +0000 | [diff] [blame] | 401 | int i; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 402 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 403 | if (!(replace->flags & LIST_X)) |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 404 | printf("Bridge table: %s\n", table->name); |
Bart De Schuymer | 9bfcfd8 | 2005-08-27 16:52:19 +0000 | [diff] [blame] | 405 | if (replace->selected_chain != -1) |
Bart De Schuymer | 482fbaf | 2005-08-28 13:16:25 +0000 | [diff] [blame] | 406 | list_em(ebt_to_chain(replace)); |
Bart De Schuymer | 9bfcfd8 | 2005-08-27 16:52:19 +0000 | [diff] [blame] | 407 | else { |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 408 | /* Create new chains and rename standard chains when necessary */ |
Bart De Schuymer | 9bfcfd8 | 2005-08-27 16:52:19 +0000 | [diff] [blame] | 409 | if (replace->flags & LIST_X && replace->num_chains > NF_BR_NUMHOOKS) { |
| 410 | for (i = NF_BR_NUMHOOKS; i < replace->num_chains; i++) |
| 411 | printf("ebtables -t %s -N %s\n", replace->name, replace->chains[i]->name); |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 412 | for (i = 0; i < NF_BR_NUMHOOKS; i++) |
Bart De Schuymer | 9bfcfd8 | 2005-08-27 16:52:19 +0000 | [diff] [blame] | 413 | if (replace->chains[i] && strcmp(replace->chains[i]->name, ebt_hooknames[i])) |
| 414 | printf("ebtables -t %s -E %s %s\n", replace->name, ebt_hooknames[i], replace->chains[i]->name); |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 415 | } |
Bart De Schuymer | 9bfcfd8 | 2005-08-27 16:52:19 +0000 | [diff] [blame] | 416 | for (i = 0; i < replace->num_chains; i++) |
| 417 | if (replace->chains[i]) |
Bart De Schuymer | 482fbaf | 2005-08-28 13:16:25 +0000 | [diff] [blame] | 418 | list_em(replace->chains[i]); |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 419 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 422 | static int parse_rule_range(const char *argv, int *rule_nr, int *rule_nr_end) |
Bart De Schuymer | cc44005 | 2002-11-06 21:10:33 +0000 | [diff] [blame] | 423 | { |
| 424 | char *colon = strchr(argv, ':'), *buffer; |
| 425 | |
| 426 | if (colon) { |
| 427 | *colon = '\0'; |
| 428 | if (*(colon + 1) == '\0') |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 429 | *rule_nr_end = -1; /* Until the last rule */ |
Bart De Schuymer | cc44005 | 2002-11-06 21:10:33 +0000 | [diff] [blame] | 430 | else { |
| 431 | *rule_nr_end = strtol(colon + 1, &buffer, 10); |
Bart De Schuymer | c3b97f5 | 2003-04-17 17:03:49 +0000 | [diff] [blame] | 432 | if (*buffer != '\0' || *rule_nr_end == 0) |
Bart De Schuymer | cc44005 | 2002-11-06 21:10:33 +0000 | [diff] [blame] | 433 | return -1; |
| 434 | } |
| 435 | } |
| 436 | if (colon == argv) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 437 | *rule_nr = 1; /* Beginning with the first rule */ |
Bart De Schuymer | cc44005 | 2002-11-06 21:10:33 +0000 | [diff] [blame] | 438 | else { |
| 439 | *rule_nr = strtol(argv, &buffer, 10); |
Bart De Schuymer | c3b97f5 | 2003-04-17 17:03:49 +0000 | [diff] [blame] | 440 | if (*buffer != '\0' || *rule_nr == 0) |
Bart De Schuymer | cc44005 | 2002-11-06 21:10:33 +0000 | [diff] [blame] | 441 | return -1; |
| 442 | } |
| 443 | if (!colon) |
| 444 | *rule_nr_end = *rule_nr; |
Bart De Schuymer | cc44005 | 2002-11-06 21:10:33 +0000 | [diff] [blame] | 445 | return 0; |
| 446 | } |
| 447 | |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 448 | /* Incrementing or decrementing rules in daemon mode is not supported as the |
Bart De Schuymer | 229079b | 2005-06-18 14:42:21 +0000 | [diff] [blame] | 449 | * involved code overload is not worth it (too annoying to take the increased |
| 450 | * counters in the kernel into account). */ |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 451 | static int parse_change_counters_rule(int argc, char **argv, int *rule_nr, int *rule_nr_end, int exec_style) |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 452 | { |
| 453 | char *buffer; |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 454 | int ret = 0; |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 455 | |
| 456 | if (optind + 1 >= argc || (argv[optind][0] == '-' && (argv[optind][1] < '0' || argv[optind][1] > '9')) || |
| 457 | (argv[optind + 1][0] == '-' && (argv[optind + 1][1] < '0' && argv[optind + 1][1] > '9'))) |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 458 | ebt_print_error2("The command -C needs at least 2 arguments"); |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 459 | if (optind + 2 < argc && (argv[optind + 2][0] != '-' || (argv[optind + 2][1] >= '0' && argv[optind + 2][1] <= '9'))) { |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 460 | if (optind + 3 != argc) |
| 461 | ebt_print_error2("No extra options allowed with -C start_nr[:end_nr] pcnt bcnt"); |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 462 | if (parse_rule_range(argv[optind], rule_nr, rule_nr_end)) |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 463 | ebt_print_error2("Something is wrong with the rule number specification '%s'", argv[optind]); |
| 464 | optind++; |
| 465 | } |
| 466 | |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 467 | if (argv[optind][0] == '+') { |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 468 | if (exec_style == EXEC_STYLE_DAEMON) |
| 469 | daemon_incr: |
| 470 | ebt_print_error2("Incrementing rule counters (%s) not allowed in daemon mode", argv[optind]); |
| 471 | ret += 1; |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 472 | new_entry->cnt_surplus.pcnt = strtoull(argv[optind] + 1, &buffer, 10); |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 473 | } else if (argv[optind][0] == '-') { |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 474 | if (exec_style == EXEC_STYLE_DAEMON) |
| 475 | daemon_decr: |
| 476 | ebt_print_error2("Decrementing rule counters (%s) not allowed in daemon mode", argv[optind]); |
| 477 | ret += 2; |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 478 | new_entry->cnt_surplus.pcnt = strtoull(argv[optind] + 1, &buffer, 10); |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 479 | } else |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 480 | new_entry->cnt_surplus.pcnt = strtoull(argv[optind], &buffer, 10); |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 481 | |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 482 | if (*buffer != '\0') |
| 483 | goto invalid; |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 484 | optind++; |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 485 | if (argv[optind][0] == '+') { |
| 486 | if (exec_style == EXEC_STYLE_DAEMON) |
| 487 | goto daemon_incr; |
| 488 | ret += 3; |
| 489 | new_entry->cnt_surplus.bcnt = strtoull(argv[optind] + 1, &buffer, 10); |
| 490 | } else if (argv[optind][0] == '-') { |
| 491 | if (exec_style == EXEC_STYLE_DAEMON) |
| 492 | goto daemon_decr; |
| 493 | ret += 6; |
| 494 | new_entry->cnt_surplus.bcnt = strtoull(argv[optind] + 1, &buffer, 10); |
| 495 | } else |
| 496 | new_entry->cnt_surplus.bcnt = strtoull(argv[optind], &buffer, 10); |
| 497 | |
| 498 | if (*buffer != '\0') |
| 499 | goto invalid; |
| 500 | optind++; |
| 501 | return ret; |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 502 | invalid: |
| 503 | ebt_print_error2("Packet counter '%s' invalid", argv[optind]); |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 506 | static int parse_iface(char *iface, char *option) |
Bart De Schuymer | 37d520d | 2004-10-24 07:36:15 +0000 | [diff] [blame] | 507 | { |
| 508 | char *c; |
| 509 | |
| 510 | if ((c = strchr(iface, '+'))) { |
| 511 | if (*(c + 1) != '\0') { |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 512 | ebt_print_error("Spurious characters after '+' wildcard for '%s'", option); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 513 | return -1; |
Bart De Schuymer | 37d520d | 2004-10-24 07:36:15 +0000 | [diff] [blame] | 514 | } else |
| 515 | *c = IF_WILDCARD; |
| 516 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 517 | return 0; |
Bart De Schuymer | 37d520d | 2004-10-24 07:36:15 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 520 | void ebt_early_init_once() |
| 521 | { |
| 522 | ebt_iterate_matches(merge_match); |
| 523 | ebt_iterate_watchers(merge_watcher); |
| 524 | ebt_iterate_targets(merge_target); |
| 525 | } |
| 526 | |
Bart De Schuymer | 229079b | 2005-06-18 14:42:21 +0000 | [diff] [blame] | 527 | /* We use exec_style instead of #ifdef's because ebtables.so is a shared object. */ |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 528 | int do_command(int argc, char *argv[], int exec_style, |
| 529 | struct ebt_u_replace *replace_) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 530 | { |
Bart De Schuymer | 923a573 | 2002-08-11 12:01:33 +0000 | [diff] [blame] | 531 | char *buffer; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 532 | int c, i; |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 533 | int zerochain = -1; /* Needed for the -Z option (we can have -Z <this> -L <that>) */ |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 534 | int chcounter; /* Needed for -C */ |
Bart De Schuymer | f8f8f29 | 2002-06-25 15:43:57 +0000 | [diff] [blame] | 535 | int policy = 0; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 536 | int rule_nr = 0; |
| 537 | int rule_nr_end = 0; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 538 | struct ebt_u_target *t; |
| 539 | struct ebt_u_match *m; |
| 540 | struct ebt_u_watcher *w; |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 541 | struct ebt_u_match_list *m_l; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 542 | struct ebt_u_watcher_list *w_l; |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 543 | struct ebt_u_entries *entries; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 544 | |
Bart De Schuymer | a615b96 | 2002-11-03 14:54:09 +0000 | [diff] [blame] | 545 | opterr = 0; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 546 | ebt_modprobe = NULL; |
Bart De Schuymer | a615b96 | 2002-11-03 14:54:09 +0000 | [diff] [blame] | 547 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 548 | replace = replace_; |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 549 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 550 | /* The daemon doesn't use the environment variable */ |
| 551 | if (exec_style == EXEC_STYLE_PRG) { |
| 552 | buffer = getenv(ATOMIC_ENV_VARIABLE); |
| 553 | if (buffer) { |
| 554 | replace->filename = malloc(strlen(buffer) + 1); |
| 555 | if (!replace->filename) |
| 556 | ebt_print_memory(); |
| 557 | strcpy(replace->filename, buffer); |
| 558 | buffer = NULL; |
| 559 | } |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 560 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 561 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 562 | replace->flags &= OPT_KERNELDATA; /* ebtablesd needs OPT_KERNELDATA */ |
| 563 | replace->selected_chain = -1; |
| 564 | replace->command = 'h'; |
| 565 | |
| 566 | if (!new_entry) { |
| 567 | new_entry = (struct ebt_u_entry *)malloc(sizeof(struct ebt_u_entry)); |
| 568 | if (!new_entry) |
| 569 | ebt_print_memory(); |
| 570 | } |
| 571 | /* Put some sane values in our new entry */ |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 572 | ebt_initialize_entry(new_entry); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 573 | new_entry->replace = replace; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 574 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 575 | /* The scenario induced by this loop makes that: |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 576 | * '-t' ,'-M' and --atomic (if specified) have to come |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 577 | * before '-A' and the like */ |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 578 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 579 | /* Getopt saves the day */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 580 | while ((c = getopt_long(argc, argv, |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 581 | "-A:D:C:I:N:E:X::L::Z::F::P:Vhi:o:j:c:p:s:d:t:M:", ebt_options, NULL)) != -1) { |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 582 | switch (c) { |
| 583 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 584 | case 'A': /* Add a rule */ |
| 585 | case 'D': /* Delete a rule */ |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 586 | case 'C': /* Change counters */ |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 587 | case 'P': /* Define policy */ |
| 588 | case 'I': /* Insert a rule */ |
| 589 | case 'N': /* Make a user defined chain */ |
| 590 | case 'E': /* Rename chain */ |
| 591 | case 'X': /* Delete chain */ |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 592 | /* We allow -N chainname -P policy */ |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 593 | if (replace->command == 'N' && c == 'P') { |
| 594 | replace->command = c; |
| 595 | optind--; /* No table specified */ |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 596 | goto handle_P; |
| 597 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 598 | if (OPT_COMMANDS) |
| 599 | ebt_print_error2("Multiple commands are not allowed"); |
Bart De Schuymer | 90f2c2e | 2003-07-13 18:48:02 +0000 | [diff] [blame] | 600 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 601 | replace->command = c; |
| 602 | replace->flags |= OPT_COMMAND; |
| 603 | if (!(replace->flags & OPT_KERNELDATA)) |
| 604 | ebt_get_kernel_table(replace, 0); |
| 605 | if (optarg && (optarg[0] == '-' || !strcmp(optarg, "!"))) |
| 606 | ebt_print_error2("No chain name specified"); |
| 607 | if (c == 'N') { |
Bart De Schuymer | cdc2cd0 | 2005-10-01 20:12:50 +0000 | [diff] [blame] | 608 | if (ebt_get_chainnr(replace, optarg) != -1) |
| 609 | ebt_print_error2("Chain %s already exists", optarg); |
| 610 | else if (ebt_find_target(optarg)) |
| 611 | ebt_print_error2("Target with name %s exists", optarg); |
| 612 | else if (strlen(optarg) >= EBT_CHAIN_MAXNAMELEN) |
| 613 | ebt_print_error2("Chain name length can't exceed %d", |
| 614 | EBT_CHAIN_MAXNAMELEN - 1); |
Bart De Schuymer | 472e3f8 | 2005-11-11 21:05:57 +0000 | [diff] [blame] | 615 | else if (strchr(optarg, ' ') != NULL) |
| 616 | ebt_print_error2("Use of ' ' not allowed in chain names"); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 617 | ebt_new_chain(replace, optarg, EBT_ACCEPT); |
| 618 | /* This is needed to get -N x -P y working */ |
| 619 | replace->selected_chain = ebt_get_chainnr(replace, optarg); |
| 620 | break; |
| 621 | } else if (c == 'X') { |
| 622 | if (optind >= argc) { |
| 623 | replace->selected_chain = -1; |
| 624 | ebt_delete_chain(replace); |
Bart De Schuymer | 90f2c2e | 2003-07-13 18:48:02 +0000 | [diff] [blame] | 625 | break; |
| 626 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 627 | |
| 628 | if (optind < argc - 1) |
| 629 | ebt_print_error2("No extra options allowed with -X"); |
| 630 | |
| 631 | if ((replace->selected_chain = ebt_get_chainnr(replace, argv[optind])) == -1) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 632 | ebt_print_error2("Chain '%s' doesn't exist", argv[optind]); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 633 | ebt_delete_chain(replace); |
| 634 | if (ebt_errormsg[0] != '\0') |
| 635 | return -1; |
| 636 | optind++; |
Bart De Schuymer | 90f2c2e | 2003-07-13 18:48:02 +0000 | [diff] [blame] | 637 | break; |
| 638 | } |
| 639 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 640 | if ((replace->selected_chain = ebt_get_chainnr(replace, optarg)) == -1) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 641 | ebt_print_error2("Chain '%s' doesn't exist", optarg); |
Bart De Schuymer | 1ab4156 | 2002-06-23 17:09:54 +0000 | [diff] [blame] | 642 | if (c == 'E') { |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 643 | if (optind >= argc) |
| 644 | ebt_print_error2("No new chain name specified"); |
Bart De Schuymer | 472e3f8 | 2005-11-11 21:05:57 +0000 | [diff] [blame] | 645 | else if (optind < argc - 1) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 646 | ebt_print_error2("No extra options allowed with -E"); |
Bart De Schuymer | 472e3f8 | 2005-11-11 21:05:57 +0000 | [diff] [blame] | 647 | else if (strlen(argv[optind]) >= EBT_CHAIN_MAXNAMELEN) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 648 | ebt_print_error2("Chain name length can't exceed %d characters", EBT_CHAIN_MAXNAMELEN - 1); |
Bart De Schuymer | 472e3f8 | 2005-11-11 21:05:57 +0000 | [diff] [blame] | 649 | else if (ebt_get_chainnr(replace, argv[optind]) != -1) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 650 | ebt_print_error2("Chain '%s' already exists", argv[optind]); |
Bart De Schuymer | 472e3f8 | 2005-11-11 21:05:57 +0000 | [diff] [blame] | 651 | else if (ebt_find_target(argv[optind])) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 652 | ebt_print_error2("Target with name '%s' exists", argv[optind]); |
Bart De Schuymer | 472e3f8 | 2005-11-11 21:05:57 +0000 | [diff] [blame] | 653 | else if (strchr(argv[optind], ' ') != NULL) |
| 654 | ebt_print_error2("Use of ' ' not allowed in chain names"); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 655 | ebt_rename_chain(replace, argv[optind]); |
Bart De Schuymer | 1ab4156 | 2002-06-23 17:09:54 +0000 | [diff] [blame] | 656 | optind++; |
| 657 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 658 | } else if (c == 'D' && optind < argc && (argv[optind][0] != '-' || (argv[optind][1] >= '0' && argv[optind][1] <= '9'))) { |
| 659 | if (optind != argc - 1) |
| 660 | ebt_print_error2("No extra options allowed with -D start_nr[:end_nr]"); |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 661 | if (parse_rule_range(argv[optind], &rule_nr, &rule_nr_end)) |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 662 | ebt_print_error2("Problem with the specified rule number(s) '%s'", argv[optind]); |
Bart De Schuymer | cc44005 | 2002-11-06 21:10:33 +0000 | [diff] [blame] | 663 | optind++; |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 664 | } else if (c == 'C') { |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 665 | if ((chcounter = parse_change_counters_rule(argc, argv, &rule_nr, &rule_nr_end, exec_style)) == -1) |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 666 | return -1; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 667 | } else if (c == 'I') { |
| 668 | if (optind >= argc || (argv[optind][0] == '-' && (argv[optind][1] < '0' || argv[optind][1] > '9'))) |
Bart De Schuymer | 0158123 | 2005-07-24 09:46:09 +0000 | [diff] [blame] | 669 | rule_nr = 1; |
| 670 | else { |
| 671 | rule_nr = strtol(argv[optind], &buffer, 10); |
| 672 | if (*buffer != '\0') |
| 673 | ebt_print_error2("Problem with the specified rule number '%s'", argv[optind]); |
| 674 | optind++; |
| 675 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 676 | } else if (c == 'P') { |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 677 | handle_P: |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 678 | if (optind >= argc) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 679 | ebt_print_error2("No policy specified"); |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 680 | for (i = 0; i < NUM_STANDARD_TARGETS; i++) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 681 | if (!strcmp(argv[optind], ebt_standard_targets[i])) { |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 682 | policy = -i -1; |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 683 | if (policy == EBT_CONTINUE) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 684 | ebt_print_error2("Wrong policy '%s'", argv[optind]); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 685 | break; |
| 686 | } |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 687 | if (i == NUM_STANDARD_TARGETS) |
| 688 | ebt_print_error2("Unknown policy '%s'", argv[optind]); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 689 | optind++; |
| 690 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 691 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 692 | case 'L': /* List */ |
| 693 | case 'F': /* Flush */ |
| 694 | case 'Z': /* Zero counters */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 695 | if (c == 'Z') { |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 696 | if ((replace->flags & OPT_ZERO) || (replace->flags & OPT_COMMAND && replace->command != 'L')) |
| 697 | print_zero: |
| 698 | ebt_print_error2("Command -Z only allowed together with command -L"); |
| 699 | replace->flags |= OPT_ZERO; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 700 | } else { |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 701 | if (replace->flags & OPT_COMMAND) |
| 702 | ebt_print_error2("Multiple commands are not allowed"); |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 703 | replace->command = c; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 704 | replace->flags |= OPT_COMMAND; |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 705 | if (replace->flags & OPT_ZERO && c != 'L') |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 706 | goto print_zero; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 707 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 708 | |
| 709 | #ifdef SILENT_DAEMON |
| 710 | if (c== 'L' && exec_style == EXEC_STYLE_DAEMON) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 711 | ebt_print_error2("-L not supported in daemon mode"); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 712 | #endif |
| 713 | |
| 714 | if (!(replace->flags & OPT_KERNELDATA)) |
| 715 | ebt_get_kernel_table(replace, 0); |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 716 | i = -1; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 717 | if (optind < argc && argv[optind][0] != '-') { |
| 718 | if ((i = ebt_get_chainnr(replace, argv[optind])) == -1) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 719 | ebt_print_error2("Chain '%s' doesn't exist", argv[optind]); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 720 | optind++; |
| 721 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 722 | if (i != -1) { |
| 723 | if (c == 'Z') |
| 724 | zerochain = i; |
| 725 | else |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 726 | replace->selected_chain = i; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 727 | } |
| 728 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 729 | case 'V': /* Version */ |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 730 | if (OPT_COMMANDS) |
| 731 | ebt_print_error2("Multiple commands are not allowed"); |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 732 | replace->command = 'V'; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 733 | if (exec_style == EXEC_STYLE_DAEMON) |
| 734 | ebt_print_error2(PROGNAME" v"PROGVERSION" ("PROGDATE")\n"); |
Bart De Schuymer | 57a3f6a | 2003-04-01 16:59:33 +0000 | [diff] [blame] | 735 | PRINT_VERSION; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 736 | exit(0); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 737 | case 'M': /* Modprobe */ |
| 738 | if (OPT_COMMANDS) |
| 739 | ebt_print_error2("Please put the -M option earlier"); |
Bart De Schuymer | d5dc87d | 2005-07-16 22:35:32 +0000 | [diff] [blame] | 740 | free(ebt_modprobe); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 741 | ebt_modprobe = optarg; |
Bart De Schuymer | c853103 | 2002-06-14 21:55:29 +0000 | [diff] [blame] | 742 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 743 | case 'h': /* Help */ |
Bart De Schuymer | 4796286 | 2005-01-20 22:09:36 +0000 | [diff] [blame] | 744 | #ifdef SILENT_DAEMON |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 745 | if (exec_style == EXEC_STYLE_DAEMON) |
| 746 | ebt_print_error2("-h not supported in daemon mode"); |
Bart De Schuymer | 4796286 | 2005-01-20 22:09:36 +0000 | [diff] [blame] | 747 | #endif |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 748 | if (OPT_COMMANDS) |
| 749 | ebt_print_error2("Multiple commands are not allowed"); |
| 750 | replace->command = 'h'; |
Bart De Schuymer | c853103 | 2002-06-14 21:55:29 +0000 | [diff] [blame] | 751 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 752 | /* All other arguments should be extension names */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 753 | while (optind < argc) { |
| 754 | struct ebt_u_match *m; |
| 755 | struct ebt_u_watcher *w; |
| 756 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 757 | if (!strcasecmp("list_extensions", argv[optind])) { |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 758 | ebt_list_extensions(); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 759 | exit(0); |
| 760 | } |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 761 | if ((m = ebt_find_match(argv[optind]))) |
| 762 | ebt_add_match(new_entry, m); |
| 763 | else if ((w = ebt_find_watcher(argv[optind]))) |
| 764 | ebt_add_watcher(new_entry, w); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 765 | else { |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 766 | if (!(t = ebt_find_target(argv[optind]))) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 767 | ebt_print_error2("Extension '%s' not found", argv[optind]); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 768 | if (replace->flags & OPT_JUMP) |
| 769 | ebt_print_error2("Sorry, you can only see help for one target extension at a time"); |
| 770 | replace->flags |= OPT_JUMP; |
| 771 | new_entry->t = (struct ebt_entry_target *)t; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 772 | } |
| 773 | optind++; |
| 774 | } |
| 775 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 776 | case 't': /* Table */ |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 777 | if (OPT_COMMANDS) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 778 | ebt_print_error2("Please put the -t option first"); |
| 779 | ebt_check_option2(&(replace->flags), OPT_TABLE); |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 780 | if (strlen(optarg) > EBT_TABLE_MAXNAMELEN - 1) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 781 | ebt_print_error2("Table name length cannot exceed %d characters", EBT_TABLE_MAXNAMELEN - 1); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 782 | strcpy(replace->name, optarg); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 783 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 784 | case 'i': /* Input interface */ |
| 785 | case 2 : /* Logical input interface */ |
| 786 | case 'o': /* Output interface */ |
| 787 | case 3 : /* Logical output interface */ |
| 788 | case 'j': /* Target */ |
| 789 | case 'p': /* Net family protocol */ |
| 790 | case 's': /* Source mac */ |
| 791 | case 'd': /* Destination mac */ |
Bart De Schuymer | b5917d8 | 2005-01-25 21:15:59 +0000 | [diff] [blame] | 792 | case 'c': /* Set counters */ |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 793 | if (!OPT_COMMANDS) |
| 794 | ebt_print_error2("No command specified"); |
Bart De Schuymer | ab611e2 | 2005-02-14 20:20:03 +0000 | [diff] [blame] | 795 | if (replace->command != 'A' && replace->command != 'D' && replace->command != 'I' && replace->command != 'C') |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 796 | ebt_print_error2("Command and option do not match"); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 797 | if (c == 'i') { |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 798 | ebt_check_option2(&(replace->flags), OPT_IN); |
| 799 | if (replace->selected_chain > 2 && replace->selected_chain < NF_BR_BROUTING) |
| 800 | ebt_print_error2("Use -i only in INPUT, FORWARD, PREROUTING and BROUTING chains"); |
| 801 | if (ebt_check_inverse2(optarg)) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 802 | new_entry->invflags |= EBT_IIN; |
| 803 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 804 | if (strlen(optarg) >= IFNAMSIZ) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 805 | big_iface_length: |
| 806 | ebt_print_error2("Interface name length cannot exceed %d characters", IFNAMSIZ - 1); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 807 | strcpy(new_entry->in, optarg); |
| 808 | if (parse_iface(new_entry->in, "-i")) |
| 809 | return -1; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 810 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 811 | } else if (c == 2) { |
| 812 | ebt_check_option2(&(replace->flags), OPT_LOGICALIN); |
| 813 | if (replace->selected_chain > 2 && replace->selected_chain < NF_BR_BROUTING) |
| 814 | ebt_print_error2("Use --logical-in only in INPUT, FORWARD, PREROUTING and BROUTING chains"); |
| 815 | if (ebt_check_inverse2(optarg)) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 816 | new_entry->invflags |= EBT_ILOGICALIN; |
| 817 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 818 | if (strlen(optarg) >= IFNAMSIZ) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 819 | goto big_iface_length; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 820 | strcpy(new_entry->logical_in, optarg); |
| 821 | if (parse_iface(new_entry->logical_in, "--logical-in")) |
| 822 | return -1; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 823 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 824 | } else if (c == 'o') { |
| 825 | ebt_check_option2(&(replace->flags), OPT_OUT); |
| 826 | if (replace->selected_chain < 2 || replace->selected_chain == NF_BR_BROUTING) |
| 827 | ebt_print_error2("Use -o only in OUTPUT, FORWARD and POSTROUTING chains"); |
| 828 | if (ebt_check_inverse2(optarg)) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 829 | new_entry->invflags |= EBT_IOUT; |
| 830 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 831 | if (strlen(optarg) >= IFNAMSIZ) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 832 | goto big_iface_length; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 833 | strcpy(new_entry->out, optarg); |
| 834 | if (parse_iface(new_entry->out, "-o")) |
| 835 | return -1; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 836 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 837 | } else if (c == 3) { |
| 838 | ebt_check_option2(&(replace->flags), OPT_LOGICALOUT); |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 839 | if (replace->selected_chain < 2 || replace->selected_chain == NF_BR_BROUTING) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 840 | ebt_print_error2("Use --logical-out only in OUTPUT, FORWARD and POSTROUTING chains"); |
| 841 | if (ebt_check_inverse2(optarg)) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 842 | new_entry->invflags |= EBT_ILOGICALOUT; |
| 843 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 844 | if (strlen(optarg) >= IFNAMSIZ) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 845 | goto big_iface_length; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 846 | strcpy(new_entry->logical_out, optarg); |
| 847 | if (parse_iface(new_entry->logical_out, "--logical-out")) |
| 848 | return -1; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 849 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 850 | } else if (c == 'j') { |
| 851 | ebt_check_option2(&(replace->flags), OPT_JUMP); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 852 | for (i = 0; i < NUM_STANDARD_TARGETS; i++) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 853 | if (!strcmp(optarg, ebt_standard_targets[i])) { |
| 854 | t = ebt_find_target(EBT_STANDARD_TARGET); |
| 855 | ((struct ebt_standard_target *) t->t)->verdict = -i - 1; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 856 | break; |
| 857 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 858 | if (-i - 1 == EBT_RETURN && replace->selected_chain < NF_BR_NUMHOOKS) { |
| 859 | ebt_print_error2("Return target only for user defined chains"); |
| 860 | } else if (i != NUM_STANDARD_TARGETS) |
Bart De Schuymer | 7b9aaeb | 2002-06-23 20:38:34 +0000 | [diff] [blame] | 861 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 862 | |
| 863 | if ((i = ebt_get_chainnr(replace, optarg)) != -1) { |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 864 | if (i < NF_BR_NUMHOOKS) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 865 | ebt_print_error2("Don't jump to a standard chain"); |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 866 | t = ebt_find_target(EBT_STANDARD_TARGET); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 867 | ((struct ebt_standard_target *) t->t)->verdict = i - NF_BR_NUMHOOKS; |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 868 | break; |
| 869 | } else { |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 870 | /* Must be an extension then */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 871 | struct ebt_u_target *t; |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 872 | |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 873 | t = ebt_find_target(optarg); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 874 | /* -j standard not allowed either */ |
| 875 | if (!t || t == (struct ebt_u_target *)new_entry->t) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 876 | ebt_print_error2("Illegal target name '%s'", optarg); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 877 | new_entry->t = (struct ebt_entry_target *)t; |
| 878 | ebt_find_target(EBT_STANDARD_TARGET)->used = 0; |
| 879 | t->used = 1; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 880 | } |
| 881 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 882 | } else if (c == 's') { |
| 883 | ebt_check_option2(&(replace->flags), OPT_SOURCE); |
| 884 | if (ebt_check_inverse2(optarg)) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 885 | new_entry->invflags |= EBT_ISOURCE; |
| 886 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 887 | if (ebt_get_mac_and_mask(optarg, new_entry->sourcemac, new_entry->sourcemsk)) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 888 | ebt_print_error2("Problem with specified source mac '%s'", optarg); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 889 | new_entry->bitmask |= EBT_SOURCEMAC; |
| 890 | break; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 891 | } else if (c == 'd') { |
| 892 | ebt_check_option2(&(replace->flags), OPT_DEST); |
| 893 | if (ebt_check_inverse2(optarg)) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 894 | new_entry->invflags |= EBT_IDEST; |
| 895 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 896 | if (ebt_get_mac_and_mask(optarg, new_entry->destmac, new_entry->destmsk)) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 897 | ebt_print_error2("Problem with specified destination mac '%s'", optarg); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 898 | new_entry->bitmask |= EBT_DESTMAC; |
| 899 | break; |
Bart De Schuymer | b5917d8 | 2005-01-25 21:15:59 +0000 | [diff] [blame] | 900 | } else if (c == 'c') { |
| 901 | ebt_check_option2(&(replace->flags), OPT_COUNT); |
| 902 | if (ebt_check_inverse2(optarg)) |
| 903 | ebt_print_error2("Unexpected '!' after -c"); |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 904 | if (optind >= argc || optarg[0] == '-' || argv[optind][0] == '-') |
Bart De Schuymer | b5917d8 | 2005-01-25 21:15:59 +0000 | [diff] [blame] | 905 | ebt_print_error2("Option -c needs 2 arguments"); |
| 906 | |
| 907 | new_entry->cnt.pcnt = strtoull(optarg, &buffer, 10); |
| 908 | if (*buffer != '\0') |
Bart De Schuymer | cdc2cd0 | 2005-10-01 20:12:50 +0000 | [diff] [blame] | 909 | ebt_print_error2("Packet counter '%s' invalid", optarg); |
Bart De Schuymer | b5917d8 | 2005-01-25 21:15:59 +0000 | [diff] [blame] | 910 | new_entry->cnt.bcnt = strtoull(argv[optind], &buffer, 10); |
| 911 | if (*buffer != '\0') |
Bart De Schuymer | cdc2cd0 | 2005-10-01 20:12:50 +0000 | [diff] [blame] | 912 | ebt_print_error2("Packet counter '%s' invalid", argv[optind]); |
Bart De Schuymer | b5917d8 | 2005-01-25 21:15:59 +0000 | [diff] [blame] | 913 | optind++; |
| 914 | break; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 915 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 916 | ebt_check_option2(&(replace->flags), OPT_PROTOCOL); |
| 917 | if (ebt_check_inverse2(optarg)) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 918 | new_entry->invflags |= EBT_IPROTO; |
| 919 | |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 920 | new_entry->bitmask &= ~((unsigned int)EBT_NOPROTO); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 921 | i = strtol(optarg, &buffer, 16); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 922 | if (*buffer == '\0' && (i < 0 || i > 0xFFFF)) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 923 | ebt_print_error2("Problem with the specified protocol"); |
Bart De Schuymer | 28bf6f6 | 2002-06-26 18:57:24 +0000 | [diff] [blame] | 924 | if (*buffer != '\0') { |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 925 | struct ethertypeent *ent; |
| 926 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 927 | if (!strcasecmp(optarg, "LENGTH")) { |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 928 | new_entry->bitmask |= EBT_802_3; |
| 929 | break; |
| 930 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 931 | ent = getethertypebyname(optarg); |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 932 | if (!ent) |
Bart De Schuymer | cdc2cd0 | 2005-10-01 20:12:50 +0000 | [diff] [blame] | 933 | ebt_print_error2("Problem with the specified Ethernet protocol '%s', perhaps "_PATH_ETHERTYPES " is missing", optarg); |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 934 | new_entry->ethproto = ent->e_ethertype; |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 935 | } else |
| 936 | new_entry->ethproto = i; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 937 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 938 | if (new_entry->ethproto < 0x0600) |
| 939 | ebt_print_error2("Sorry, protocols have values above or equal to 0x0600"); |
| 940 | break; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 941 | case 4 : /* Lc */ |
Bart De Schuymer | 4796286 | 2005-01-20 22:09:36 +0000 | [diff] [blame] | 942 | #ifdef SILENT_DAEMON |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 943 | if (exec_style == EXEC_STYLE_DAEMON) |
| 944 | ebt_print_error2("--Lc is not supported in daemon mode"); |
Bart De Schuymer | 4796286 | 2005-01-20 22:09:36 +0000 | [diff] [blame] | 945 | #endif |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 946 | ebt_check_option2(&(replace->flags), LIST_C); |
| 947 | if (replace->command != 'L') |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 948 | ebt_print_error("Use --Lc with -L"); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 949 | replace->flags |= LIST_C; |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 950 | break; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 951 | case 5 : /* Ln */ |
Bart De Schuymer | 4796286 | 2005-01-20 22:09:36 +0000 | [diff] [blame] | 952 | #ifdef SILENT_DAEMON |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 953 | if (exec_style == EXEC_STYLE_DAEMON) |
| 954 | ebt_print_error2("--Ln is not supported in daemon mode"); |
Bart De Schuymer | 4796286 | 2005-01-20 22:09:36 +0000 | [diff] [blame] | 955 | #endif |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 956 | ebt_check_option2(&(replace->flags), LIST_N); |
| 957 | if (replace->command != 'L') |
| 958 | ebt_print_error2("Use --Ln with -L"); |
| 959 | if (replace->flags & LIST_X) |
| 960 | ebt_print_error2("--Lx is not compatible with --Ln"); |
| 961 | replace->flags |= LIST_N; |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 962 | break; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 963 | case 6 : /* Lx */ |
Bart De Schuymer | 4796286 | 2005-01-20 22:09:36 +0000 | [diff] [blame] | 964 | #ifdef SILENT_DAEMON |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 965 | if (exec_style == EXEC_STYLE_DAEMON) |
| 966 | ebt_print_error2("--Lx is not supported in daemon mode"); |
Bart De Schuymer | 4796286 | 2005-01-20 22:09:36 +0000 | [diff] [blame] | 967 | #endif |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 968 | ebt_check_option2(&(replace->flags), LIST_X); |
| 969 | if (replace->command != 'L') |
| 970 | ebt_print_error2("Use --Lx with -L"); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 971 | if (replace->flags & LIST_N) |
| 972 | ebt_print_error2("--Lx is not compatible with --Ln"); |
| 973 | replace->flags |= LIST_X; |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 974 | break; |
Bart De Schuymer | 22d03a2 | 2003-05-03 20:28:22 +0000 | [diff] [blame] | 975 | case 12 : /* Lmac2 */ |
Bart De Schuymer | 4796286 | 2005-01-20 22:09:36 +0000 | [diff] [blame] | 976 | #ifdef SILENT_DAEMON |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 977 | if (exec_style == EXEC_STYLE_DAEMON) |
| 978 | ebt_print_error("--Lmac2 is not supported in daemon mode"); |
Bart De Schuymer | 4796286 | 2005-01-20 22:09:36 +0000 | [diff] [blame] | 979 | #endif |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 980 | ebt_check_option2(&(replace->flags), LIST_MAC2); |
| 981 | if (replace->command != 'L') |
| 982 | ebt_print_error2("Use --Lmac2 with -L"); |
| 983 | replace->flags |= LIST_MAC2; |
Bart De Schuymer | 22d03a2 | 2003-05-03 20:28:22 +0000 | [diff] [blame] | 984 | break; |
Bart De Schuymer | 9895a8e | 2003-01-11 10:14:24 +0000 | [diff] [blame] | 985 | case 8 : /* atomic-commit */ |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 986 | if (exec_style == EXEC_STYLE_DAEMON) |
| 987 | ebt_print_error2("--atomic-commit is not supported in daemon mode"); |
| 988 | replace->command = c; |
| 989 | if (OPT_COMMANDS) |
| 990 | ebt_print_error2("Multiple commands are not allowed"); |
| 991 | replace->flags |= OPT_COMMAND; |
| 992 | if (!replace->filename) |
| 993 | ebt_print_error2("No atomic file specified"); |
| 994 | /* Get the information from the file */ |
| 995 | ebt_get_table(replace, 0); |
| 996 | /* We don't want the kernel giving us its counters, |
Bart De Schuymer | 64182a3 | 2004-01-21 20:39:54 +0000 | [diff] [blame] | 997 | * they would overwrite the counters extracted from |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 998 | * the file */ |
| 999 | replace->num_counters = 0; |
| 1000 | /* Make sure the table will be written to the kernel */ |
| 1001 | free(replace->filename); |
| 1002 | replace->filename = NULL; |
Bart De Schuymer | 6242374 | 2002-07-14 19:06:20 +0000 | [diff] [blame] | 1003 | break; |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 1004 | case 7 : /* atomic-init */ |
| 1005 | case 10: /* atomic-save */ |
| 1006 | case 11: /* init-table */ |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1007 | if (exec_style == EXEC_STYLE_DAEMON) { |
| 1008 | if (c == 7) { |
| 1009 | ebt_print_error2("--atomic-init is not supported in daemon mode"); |
| 1010 | } else if (c == 10) |
| 1011 | ebt_print_error2("--atomic-save is not supported in daemon mode"); |
| 1012 | ebt_print_error2("--init-table is not supported in daemon mode"); |
| 1013 | } |
| 1014 | replace->command = c; |
| 1015 | if (OPT_COMMANDS) |
| 1016 | ebt_print_error2("Multiple commands are not allowed"); |
| 1017 | if (c != 11 && !replace->filename) |
| 1018 | ebt_print_error2("No atomic file specified"); |
| 1019 | replace->flags |= OPT_COMMAND; |
Bart De Schuymer | 5885b36 | 2002-12-03 20:51:36 +0000 | [diff] [blame] | 1020 | { |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1021 | char *tmp = replace->filename; |
Bart De Schuymer | 5885b36 | 2002-12-03 20:51:36 +0000 | [diff] [blame] | 1022 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1023 | /* Get the kernel table */ |
| 1024 | replace->filename = NULL; |
Bart De Schuymer | 83a1b0f | 2005-09-28 19:36:17 +0000 | [diff] [blame] | 1025 | ebt_get_kernel_table(replace, c == 10 ? 0 : 1); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1026 | replace->filename = tmp; |
Bart De Schuymer | 5885b36 | 2002-12-03 20:51:36 +0000 | [diff] [blame] | 1027 | } |
Bart De Schuymer | 5885b36 | 2002-12-03 20:51:36 +0000 | [diff] [blame] | 1028 | break; |
Bart De Schuymer | c7bfa27 | 2002-11-20 19:40:13 +0000 | [diff] [blame] | 1029 | case 9 : /* atomic */ |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1030 | if (exec_style == EXEC_STYLE_DAEMON) |
| 1031 | ebt_print_error2("--atomic is not supported in daemon mode"); |
| 1032 | if (OPT_COMMANDS) |
| 1033 | ebt_print_error2("--atomic has to come before the command"); |
| 1034 | /* A possible memory leak here, but this is not |
| 1035 | * executed in daemon mode */ |
| 1036 | replace->filename = (char *)malloc(strlen(optarg) + 1); |
| 1037 | strcpy(replace->filename, optarg); |
Bart De Schuymer | 6242374 | 2002-07-14 19:06:20 +0000 | [diff] [blame] | 1038 | break; |
Bart De Schuymer | a615b96 | 2002-11-03 14:54:09 +0000 | [diff] [blame] | 1039 | case 1 : |
| 1040 | if (!strcmp(optarg, "!")) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1041 | ebt_check_inverse2(optarg); |
Bart De Schuymer | a615b96 | 2002-11-03 14:54:09 +0000 | [diff] [blame] | 1042 | else |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 1043 | ebt_print_error2("Bad argument : '%s'", optarg); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1044 | /* ebt_check_inverse() did optind++ */ |
Bart De Schuymer | a615b96 | 2002-11-03 14:54:09 +0000 | [diff] [blame] | 1045 | optind--; |
| 1046 | continue; |
Bart De Schuymer | 9af14f9 | 2002-07-10 20:49:10 +0000 | [diff] [blame] | 1047 | default: |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1048 | /* Is it a target option? */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1049 | t = (struct ebt_u_target *)new_entry->t; |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 1050 | if ((t->parse(c - t->option_offset, argv, argc, new_entry, &t->flags, &t->t))) { |
| 1051 | if (ebt_errormsg[0] != '\0') |
| 1052 | return -1; |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 1053 | goto check_extension; |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 1054 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1055 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1056 | /* Is it a match_option? */ |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 1057 | for (m = ebt_matches; m; m = m->next) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1058 | if (m->parse(c - m->option_offset, argv, argc, new_entry, &m->flags, &m->m)) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1059 | break; |
| 1060 | |
| 1061 | if (m != NULL) { |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 1062 | if (ebt_errormsg[0] != '\0') |
| 1063 | return -1; |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 1064 | if (m->used == 0) { |
| 1065 | ebt_add_match(new_entry, m); |
| 1066 | m->used = 1; |
| 1067 | } |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 1068 | goto check_extension; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1071 | /* Is it a watcher option? */ |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 1072 | for (w = ebt_watchers; w; w = w->next) |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 1073 | if (w->parse(c - w->option_offset, argv, argc, new_entry, &w->flags, &w->w)) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1074 | break; |
| 1075 | |
| 1076 | if (w == NULL) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1077 | ebt_print_error2("Unknown argument: '%s', %c, '%c'", argv[optind - 1], (char)optopt, (char)c); |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 1078 | if (ebt_errormsg[0] != '\0') |
| 1079 | return -1; |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 1080 | if (w->used == 0) { |
| 1081 | ebt_add_watcher(new_entry, w); |
| 1082 | w->used = 1; |
| 1083 | } |
Bart De Schuymer | dd5594b | 2002-06-26 18:05:20 +0000 | [diff] [blame] | 1084 | check_extension: |
Bart De Schuymer | 58ae040 | 2005-02-19 18:21:07 +0000 | [diff] [blame] | 1085 | if (replace->command != 'A' && replace->command != 'I' && |
| 1086 | replace->command != 'D' && replace->command != 'C') |
| 1087 | ebt_print_error2("Extensions only for -A, -I, -D and -C"); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1088 | } |
Bart De Schuymer | 8339ff1 | 2004-01-14 20:05:27 +0000 | [diff] [blame] | 1089 | ebt_invert = 0; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1092 | /* Just in case we didn't catch an error */ |
| 1093 | if (ebt_errormsg[0] != '\0') |
| 1094 | return -1; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1095 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1096 | if (!(table = ebt_find_table(replace->name))) |
| 1097 | ebt_print_error2("Bad table name"); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1098 | |
Bart De Schuymer | d2ced82 | 2005-01-23 19:19:00 +0000 | [diff] [blame] | 1099 | if (replace->command == 'h' && !(replace->flags & OPT_ZERO)) { |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1100 | print_help(); |
Bart De Schuymer | d2ced82 | 2005-01-23 19:19:00 +0000 | [diff] [blame] | 1101 | if (exec_style == EXEC_STYLE_PRG) |
| 1102 | exit(0); |
| 1103 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1104 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1105 | /* Do the final checks */ |
| 1106 | if (replace->command == 'A' || replace->command == 'I' || |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 1107 | replace->command == 'D' || replace->command == 'C') { |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1108 | /* This will put the hook_mask right for the chains */ |
| 1109 | ebt_check_for_loops(replace); |
| 1110 | if (ebt_errormsg[0] != '\0') |
| 1111 | return -1; |
| 1112 | entries = ebt_to_chain(replace); |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 1113 | m_l = new_entry->m_list; |
| 1114 | w_l = new_entry->w_list; |
| 1115 | t = (struct ebt_u_target *)new_entry->t; |
| 1116 | while (m_l) { |
| 1117 | m = (struct ebt_u_match *)(m_l->m); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1118 | m->final_check(new_entry, m->m, replace->name, |
Bart De Schuymer | 7b9aaeb | 2002-06-23 20:38:34 +0000 | [diff] [blame] | 1119 | entries->hook_mask, 0); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1120 | if (ebt_errormsg[0] != '\0') |
| 1121 | return -1; |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 1122 | m_l = m_l->next; |
| 1123 | } |
| 1124 | while (w_l) { |
| 1125 | w = (struct ebt_u_watcher *)(w_l->w); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1126 | w->final_check(new_entry, w->w, replace->name, |
Bart De Schuymer | 7b9aaeb | 2002-06-23 20:38:34 +0000 | [diff] [blame] | 1127 | entries->hook_mask, 0); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1128 | if (ebt_errormsg[0] != '\0') |
| 1129 | return -1; |
Bart De Schuymer | 60332e0 | 2002-06-23 08:01:47 +0000 | [diff] [blame] | 1130 | w_l = w_l->next; |
| 1131 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1132 | t->final_check(new_entry, t->t, replace->name, |
Bart De Schuymer | 7b9aaeb | 2002-06-23 20:38:34 +0000 | [diff] [blame] | 1133 | entries->hook_mask, 0); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1134 | if (ebt_errormsg[0] != '\0') |
| 1135 | return -1; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1136 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1137 | /* So, the extensions can work with the host endian. |
| 1138 | * The kernel does not have to do this of course */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1139 | new_entry->ethproto = htons(new_entry->ethproto); |
| 1140 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1141 | if (replace->command == 'P') { |
| 1142 | if (replace->selected_chain < NF_BR_NUMHOOKS && policy == EBT_RETURN) |
| 1143 | ebt_print_error2("Policy RETURN only allowed for user defined chains"); |
| 1144 | ebt_change_policy(replace, policy); |
| 1145 | if (ebt_errormsg[0] != '\0') |
| 1146 | return -1; |
| 1147 | } else if (replace->command == 'L') { |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1148 | list_rules(); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1149 | if (!(replace->flags & OPT_ZERO) && exec_style == EXEC_STYLE_PRG) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1150 | exit(0); |
| 1151 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1152 | if (replace->flags & OPT_ZERO) { |
| 1153 | replace->selected_chain = zerochain; |
| 1154 | ebt_zero_counters(replace); |
| 1155 | } else if (replace->command == 'F') { |
| 1156 | ebt_flush_chains(replace); |
| 1157 | } else if (replace->command == 'A' || replace->command == 'I') { |
| 1158 | ebt_add_rule(replace, new_entry, rule_nr); |
| 1159 | if (ebt_errormsg[0] != '\0') |
| 1160 | return -1; |
| 1161 | /* Makes undoing the add easier (jumps to delete_the_rule) */ |
| 1162 | if (rule_nr <= 0) |
| 1163 | rule_nr--; |
| 1164 | rule_nr_end = rule_nr; |
| 1165 | |
| 1166 | ebt_check_for_loops(replace); |
| 1167 | if (ebt_errormsg[0] != '\0') |
| 1168 | goto delete_the_rule; |
| 1169 | |
| 1170 | /* Do the final_check(), for all entries. |
| 1171 | * This is needed when adding a rule that has a chain target */ |
Bart De Schuymer | 7b9aaeb | 2002-06-23 20:38:34 +0000 | [diff] [blame] | 1172 | i = -1; |
| 1173 | while (1) { |
| 1174 | struct ebt_u_entry *e; |
| 1175 | |
| 1176 | i++; |
Bart De Schuymer | 9bfcfd8 | 2005-08-27 16:52:19 +0000 | [diff] [blame] | 1177 | entries = replace->chains[i]; |
Bart De Schuymer | 7b9aaeb | 2002-06-23 20:38:34 +0000 | [diff] [blame] | 1178 | if (!entries) { |
| 1179 | if (i < NF_BR_NUMHOOKS) |
| 1180 | continue; |
| 1181 | else |
| 1182 | break; |
| 1183 | } |
Bart De Schuymer | e94eaf7 | 2005-08-28 16:06:22 +0000 | [diff] [blame] | 1184 | e = entries->entries->next; |
| 1185 | while (e != entries->entries) { |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1186 | /* Userspace extensions use host endian */ |
Bart De Schuymer | 7b9aaeb | 2002-06-23 20:38:34 +0000 | [diff] [blame] | 1187 | e->ethproto = ntohs(e->ethproto); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1188 | ebt_do_final_checks(replace, e, entries); |
| 1189 | if (ebt_errormsg[0] != '\0') |
| 1190 | goto delete_the_rule; |
Bart De Schuymer | 7b9aaeb | 2002-06-23 20:38:34 +0000 | [diff] [blame] | 1191 | e->ethproto = htons(e->ethproto); |
| 1192 | e = e->next; |
| 1193 | } |
| 1194 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1195 | /* Don't reuse the added rule */ |
| 1196 | new_entry = NULL; |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 1197 | } else if (replace->command == 'D') { |
| 1198 | delete_the_rule: |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1199 | ebt_delete_rule(replace, new_entry, rule_nr, rule_nr_end); |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 1200 | if (ebt_errormsg[0] != '\0') |
| 1201 | return -1; |
| 1202 | } else if (replace->command == 'C') { |
Bart De Schuymer | 0436eda | 2005-03-28 20:29:37 +0000 | [diff] [blame] | 1203 | ebt_change_counters(replace, new_entry, rule_nr, rule_nr_end, &(new_entry->cnt_surplus), chcounter); |
Bart De Schuymer | ff58720 | 2005-02-08 20:02:28 +0000 | [diff] [blame] | 1204 | if (ebt_errormsg[0] != '\0') |
| 1205 | return -1; |
| 1206 | } |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1207 | /* Commands -N, -E, -X, --atomic-commit, --atomic-commit, --atomic-save, |
| 1208 | * --init-table fall through */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1209 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1210 | if (ebt_errormsg[0] != '\0') |
| 1211 | return -1; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1212 | if (table->check) |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1213 | table->check(replace); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1214 | |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1215 | if (exec_style == EXEC_STYLE_PRG) {/* Implies ebt_errormsg[0] == '\0' */ |
| 1216 | ebt_deliver_table(replace); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1217 | |
Bart De Schuymer | e94eaf7 | 2005-08-28 16:06:22 +0000 | [diff] [blame] | 1218 | if (replace->nentries) |
Bart De Schuymer | 83a1b0f | 2005-09-28 19:36:17 +0000 | [diff] [blame] | 1219 | ebt_deliver_counters(replace); |
Bart De Schuymer | 6622a01 | 2005-01-19 21:09:05 +0000 | [diff] [blame] | 1220 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1221 | return 0; |
| 1222 | } |