Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1 | /* Code to take an iptables-style command line and do it. */ |
| 2 | |
| 3 | /* |
| 4 | * Author: Paul.Russell@rustcorp.com.au and mneuling@radlogic.com.au |
| 5 | * |
Harald Welte | d4ab5ad | 2002-08-07 09:07:24 +0000 | [diff] [blame] | 6 | * (C) 2000-2002 by the netfilter coreteam <coreteam@netfilter.org>: |
| 7 | * Paul 'Rusty' Russell <rusty@rustcorp.com.au> |
| 8 | * Marc Boucher <marc+nf@mbsi.ca> |
| 9 | * James Morris <jmorris@intercode.com.au> |
| 10 | * Harald Welte <laforge@gnumonks.org> |
| 11 | * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> |
| 12 | * |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | */ |
| 27 | |
| 28 | #include <getopt.h> |
| 29 | #include <string.h> |
| 30 | #include <netdb.h> |
| 31 | #include <errno.h> |
| 32 | #include <stdio.h> |
| 33 | #include <stdlib.h> |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 34 | #include <ctype.h> |
| 35 | #include <stdarg.h> |
| 36 | #include <limits.h> |
Harald Welte | 82dd2ec | 2000-12-19 05:18:15 +0000 | [diff] [blame] | 37 | #include <unistd.h> |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 38 | #include <iptables.h> |
Yasuyuki KOZAKAI | 3dfa448 | 2007-07-24 05:45:33 +0000 | [diff] [blame] | 39 | #include <xtables.h> |
Harald Welte | 82dd2ec | 2000-12-19 05:18:15 +0000 | [diff] [blame] | 40 | #include <fcntl.h> |
Phil Oester | 8cf6591 | 2005-09-19 15:00:33 +0000 | [diff] [blame] | 41 | #include <sys/utsname.h> |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 42 | |
| 43 | #ifndef TRUE |
| 44 | #define TRUE 1 |
| 45 | #endif |
| 46 | #ifndef FALSE |
| 47 | #define FALSE 0 |
| 48 | #endif |
| 49 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 50 | #define FMT_NUMERIC 0x0001 |
| 51 | #define FMT_NOCOUNTS 0x0002 |
| 52 | #define FMT_KILOMEGAGIGA 0x0004 |
| 53 | #define FMT_OPTIONS 0x0008 |
| 54 | #define FMT_NOTABLE 0x0010 |
| 55 | #define FMT_NOTARGET 0x0020 |
| 56 | #define FMT_VIA 0x0040 |
| 57 | #define FMT_NONEWLINE 0x0080 |
| 58 | #define FMT_LINENUMBERS 0x0100 |
| 59 | |
| 60 | #define FMT_PRINT_RULE (FMT_NOCOUNTS | FMT_OPTIONS | FMT_VIA \ |
| 61 | | FMT_NUMERIC | FMT_NOTABLE) |
| 62 | #define FMT(tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab)) |
| 63 | |
| 64 | |
| 65 | #define CMD_NONE 0x0000U |
| 66 | #define CMD_INSERT 0x0001U |
| 67 | #define CMD_DELETE 0x0002U |
| 68 | #define CMD_DELETE_NUM 0x0004U |
| 69 | #define CMD_REPLACE 0x0008U |
| 70 | #define CMD_APPEND 0x0010U |
| 71 | #define CMD_LIST 0x0020U |
| 72 | #define CMD_FLUSH 0x0040U |
| 73 | #define CMD_ZERO 0x0080U |
| 74 | #define CMD_NEW_CHAIN 0x0100U |
| 75 | #define CMD_DELETE_CHAIN 0x0200U |
| 76 | #define CMD_SET_POLICY 0x0400U |
Harald Welte | 0eca33f | 2006-04-21 11:56:30 +0000 | [diff] [blame] | 77 | #define CMD_RENAME_CHAIN 0x0800U |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 78 | #define CMD_LIST_RULES 0x1000U |
| 79 | #define NUMBER_OF_CMD 14 |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 80 | static const char cmdflags[] = { 'I', 'D', 'D', 'R', 'A', 'L', 'F', 'Z', |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 81 | 'N', 'X', 'P', 'E', 'S' }; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 82 | |
| 83 | #define OPTION_OFFSET 256 |
| 84 | |
| 85 | #define OPT_NONE 0x00000U |
| 86 | #define OPT_NUMERIC 0x00001U |
| 87 | #define OPT_SOURCE 0x00002U |
| 88 | #define OPT_DESTINATION 0x00004U |
| 89 | #define OPT_PROTOCOL 0x00008U |
| 90 | #define OPT_JUMP 0x00010U |
| 91 | #define OPT_VERBOSE 0x00020U |
| 92 | #define OPT_EXPANDED 0x00040U |
| 93 | #define OPT_VIANAMEIN 0x00080U |
| 94 | #define OPT_VIANAMEOUT 0x00100U |
| 95 | #define OPT_FRAGMENT 0x00200U |
| 96 | #define OPT_LINENUMBERS 0x00400U |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 97 | #define OPT_COUNTERS 0x00800U |
| 98 | #define NUMBER_OF_OPT 12 |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 99 | static const char optflags[NUMBER_OF_OPT] |
Jonas Berlin | 4a06cf0 | 2005-04-01 06:38:25 +0000 | [diff] [blame] | 100 | = { 'n', 's', 'd', 'p', 'j', 'v', 'x', 'i', 'o', 'f', '0', 'c'}; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 101 | |
| 102 | static struct option original_opts[] = { |
Gáspár Lajos | 7bc3cb7 | 2008-03-27 08:20:39 +0100 | [diff] [blame] | 103 | {.name = "append", .has_arg = 1, .val = 'A'}, |
| 104 | {.name = "delete", .has_arg = 1, .val = 'D'}, |
| 105 | {.name = "insert", .has_arg = 1, .val = 'I'}, |
| 106 | {.name = "replace", .has_arg = 1, .val = 'R'}, |
| 107 | {.name = "list", .has_arg = 2, .val = 'L'}, |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 108 | {.name = "list-rules", .has_arg = 2, .val = 'S'}, |
Gáspár Lajos | 7bc3cb7 | 2008-03-27 08:20:39 +0100 | [diff] [blame] | 109 | {.name = "flush", .has_arg = 2, .val = 'F'}, |
| 110 | {.name = "zero", .has_arg = 2, .val = 'Z'}, |
| 111 | {.name = "new-chain", .has_arg = 1, .val = 'N'}, |
| 112 | {.name = "delete-chain", .has_arg = 2, .val = 'X'}, |
| 113 | {.name = "rename-chain", .has_arg = 1, .val = 'E'}, |
| 114 | {.name = "policy", .has_arg = 1, .val = 'P'}, |
| 115 | {.name = "source", .has_arg = 1, .val = 's'}, |
| 116 | {.name = "destination", .has_arg = 1, .val = 'd'}, |
| 117 | {.name = "src", .has_arg = 1, .val = 's'}, /* synonym */ |
| 118 | {.name = "dst", .has_arg = 1, .val = 'd'}, /* synonym */ |
| 119 | {.name = "protocol", .has_arg = 1, .val = 'p'}, |
| 120 | {.name = "in-interface", .has_arg = 1, .val = 'i'}, |
| 121 | {.name = "jump", .has_arg = 1, .val = 'j'}, |
| 122 | {.name = "table", .has_arg = 1, .val = 't'}, |
| 123 | {.name = "match", .has_arg = 1, .val = 'm'}, |
| 124 | {.name = "numeric", .has_arg = 0, .val = 'n'}, |
| 125 | {.name = "out-interface", .has_arg = 1, .val = 'o'}, |
| 126 | {.name = "verbose", .has_arg = 0, .val = 'v'}, |
| 127 | {.name = "exact", .has_arg = 0, .val = 'x'}, |
| 128 | {.name = "fragments", .has_arg = 0, .val = 'f'}, |
| 129 | {.name = "version", .has_arg = 0, .val = 'V'}, |
| 130 | {.name = "help", .has_arg = 2, .val = 'h'}, |
| 131 | {.name = "line-numbers", .has_arg = 0, .val = '0'}, |
| 132 | {.name = "modprobe", .has_arg = 1, .val = 'M'}, |
| 133 | {.name = "set-counters", .has_arg = 1, .val = 'c'}, |
| 134 | {.name = "goto", .has_arg = 1, .val = 'g'}, |
| 135 | {NULL}, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
Illes Marci | 63e9063 | 2003-03-03 08:08:37 +0000 | [diff] [blame] | 138 | /* we need this for iptables-restore. iptables-restore.c sets line to the |
| 139 | * current line of the input file, in order to give a more precise error |
| 140 | * message. iptables itself doesn't need this, so it is initialized to the |
| 141 | * magic number of -1 */ |
| 142 | int line = -1; |
| 143 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 144 | static struct option *opts = original_opts; |
| 145 | static unsigned int global_option_offset = 0; |
| 146 | |
| 147 | /* Table of legal combinations of commands and options. If any of the |
| 148 | * given commands make an option legal, that option is legal (applies to |
| 149 | * CMD_LIST and CMD_ZERO only). |
| 150 | * Key: |
| 151 | * + compulsory |
| 152 | * x illegal |
| 153 | * optional |
| 154 | */ |
| 155 | |
| 156 | static char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] = |
| 157 | /* Well, it's better than "Re: Linux vs FreeBSD" */ |
| 158 | { |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 159 | /* -n -s -d -p -j -v -x -i -o -f --line -c */ |
Patrick McHardyHarald Welte | 2cfbd9f | 2006-04-22 02:08:12 +0000 | [diff] [blame] | 160 | /*INSERT*/ {'x',' ',' ',' ',' ',' ','x',' ',' ',' ','x',' '}, |
| 161 | /*DELETE*/ {'x',' ',' ',' ',' ',' ','x',' ',' ',' ','x','x'}, |
| 162 | /*DELETE_NUM*/{'x','x','x','x','x',' ','x','x','x','x','x','x'}, |
| 163 | /*REPLACE*/ {'x',' ',' ',' ',' ',' ','x',' ',' ',' ','x',' '}, |
| 164 | /*APPEND*/ {'x',' ',' ',' ',' ',' ','x',' ',' ',' ','x',' '}, |
| 165 | /*LIST*/ {' ','x','x','x','x',' ',' ','x','x','x',' ','x'}, |
| 166 | /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, |
| 167 | /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, |
| 168 | /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, |
| 169 | /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, |
Henrik Nordstrom | 48c1bc6 | 2008-05-12 20:53:16 +0200 | [diff] [blame] | 170 | /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x','x',' '}, |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 171 | /*RENAME*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, |
| 172 | /*LIST_RULES*/{'x','x','x','x','x',' ','x','x','x','x','x','x'} |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | static int inverse_for_options[NUMBER_OF_OPT] = |
| 176 | { |
| 177 | /* -n */ 0, |
| 178 | /* -s */ IPT_INV_SRCIP, |
| 179 | /* -d */ IPT_INV_DSTIP, |
| 180 | /* -p */ IPT_INV_PROTO, |
| 181 | /* -j */ 0, |
| 182 | /* -v */ 0, |
| 183 | /* -x */ 0, |
| 184 | /* -i */ IPT_INV_VIA_IN, |
| 185 | /* -o */ IPT_INV_VIA_OUT, |
| 186 | /* -f */ IPT_INV_FRAG, |
Patrick McHardyHarald Welte | 2cfbd9f | 2006-04-22 02:08:12 +0000 | [diff] [blame] | 187 | /*--line*/ 0, |
| 188 | /* -c */ 0, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | const char *program_version; |
| 192 | const char *program_name; |
| 193 | |
Phil Oester | 8cf6591 | 2005-09-19 15:00:33 +0000 | [diff] [blame] | 194 | int kernel_version; |
| 195 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 196 | /* A few hardcoded protocols for 'all' and in case the user has no |
| 197 | /etc/protocols */ |
| 198 | struct pprot { |
| 199 | char *name; |
| 200 | u_int8_t num; |
| 201 | }; |
| 202 | |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 203 | struct afinfo afinfo = { |
| 204 | .family = AF_INET, |
| 205 | .libprefix = "libipt_", |
| 206 | .ipproto = IPPROTO_IP, |
| 207 | .kmod = "ip_tables", |
| 208 | .so_rev_match = IPT_SO_GET_REVISION_MATCH, |
| 209 | .so_rev_target = IPT_SO_GET_REVISION_TARGET, |
| 210 | }; |
| 211 | |
Rusty Russell | a3e6aaa | 2000-12-19 04:45:23 +0000 | [diff] [blame] | 212 | /* Primitive headers... */ |
András Kis-Szabó | 764316a | 2001-02-26 17:31:20 +0000 | [diff] [blame] | 213 | /* defined in netinet/in.h */ |
| 214 | #if 0 |
Rusty Russell | a3e6aaa | 2000-12-19 04:45:23 +0000 | [diff] [blame] | 215 | #ifndef IPPROTO_ESP |
| 216 | #define IPPROTO_ESP 50 |
| 217 | #endif |
| 218 | #ifndef IPPROTO_AH |
| 219 | #define IPPROTO_AH 51 |
| 220 | #endif |
András Kis-Szabó | 764316a | 2001-02-26 17:31:20 +0000 | [diff] [blame] | 221 | #endif |
Rusty Russell | a3e6aaa | 2000-12-19 04:45:23 +0000 | [diff] [blame] | 222 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 223 | static const struct pprot chain_protos[] = { |
| 224 | { "tcp", IPPROTO_TCP }, |
| 225 | { "udp", IPPROTO_UDP }, |
Patrick McHardy | 9561606 | 2007-01-11 09:08:22 +0000 | [diff] [blame] | 226 | { "udplite", IPPROTO_UDPLITE }, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 227 | { "icmp", IPPROTO_ICMP }, |
Jan Echternach | af8fe9e | 2000-08-27 07:41:39 +0000 | [diff] [blame] | 228 | { "esp", IPPROTO_ESP }, |
| 229 | { "ah", IPPROTO_AH }, |
Harald Welte | 1291523 | 2004-02-21 09:20:34 +0000 | [diff] [blame] | 230 | { "sctp", IPPROTO_SCTP }, |
Phil Oester | b740891 | 2007-04-30 00:01:39 +0000 | [diff] [blame] | 231 | { "all", 0 }, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 232 | }; |
| 233 | |
Patrick McHardyJesper Brouer | c1eae41 | 2006-07-25 01:50:48 +0000 | [diff] [blame] | 234 | static char * |
Rusty Russell | 28381a4 | 2000-05-10 00:19:50 +0000 | [diff] [blame] | 235 | proto_to_name(u_int8_t proto, int nolookup) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 236 | { |
| 237 | unsigned int i; |
| 238 | |
Rusty Russell | 28381a4 | 2000-05-10 00:19:50 +0000 | [diff] [blame] | 239 | if (proto && !nolookup) { |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 240 | struct protoent *pent = getprotobynumber(proto); |
| 241 | if (pent) |
| 242 | return pent->p_name; |
| 243 | } |
| 244 | |
| 245 | for (i = 0; i < sizeof(chain_protos)/sizeof(struct pprot); i++) |
| 246 | if (chain_protos[i].num == proto) |
| 247 | return chain_protos[i].name; |
| 248 | |
| 249 | return NULL; |
| 250 | } |
| 251 | |
Pablo Neira Ayuso | 267a570 | 2006-11-29 13:32:32 +0000 | [diff] [blame] | 252 | enum { |
| 253 | IPT_DOTTED_ADDR = 0, |
| 254 | IPT_DOTTED_MASK |
| 255 | }; |
| 256 | |
Pablo Neira | dfdcd64 | 2005-05-29 19:05:23 +0000 | [diff] [blame] | 257 | static void free_opts(int reset_offset) |
| 258 | { |
| 259 | if (opts != original_opts) { |
| 260 | free(opts); |
| 261 | opts = original_opts; |
| 262 | if (reset_offset) |
| 263 | global_option_offset = 0; |
| 264 | } |
| 265 | } |
| 266 | |
Patrick McHardy | 0b63936 | 2007-09-08 16:00:01 +0000 | [diff] [blame] | 267 | static void |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 268 | exit_tryhelp(int status) |
| 269 | { |
Maciej Soltysiak | edad9bb | 2003-03-31 12:11:55 +0000 | [diff] [blame] | 270 | if (line != -1) |
Harald Welte | a5bb0a6 | 2003-05-03 18:56:19 +0000 | [diff] [blame] | 271 | fprintf(stderr, "Error occurred at line: %d\n", line); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 272 | fprintf(stderr, "Try `%s -h' or '%s --help' for more information.\n", |
| 273 | program_name, program_name ); |
Pablo Neira | dfdcd64 | 2005-05-29 19:05:23 +0000 | [diff] [blame] | 274 | free_opts(1); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 275 | exit(status); |
| 276 | } |
| 277 | |
Patrick McHardy | 0b63936 | 2007-09-08 16:00:01 +0000 | [diff] [blame] | 278 | static void |
Martin Josefsson | 66aea6f | 2004-05-26 15:41:54 +0000 | [diff] [blame] | 279 | exit_printhelp(struct iptables_rule_match *matches) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 280 | { |
Martin Josefsson | 66aea6f | 2004-05-26 15:41:54 +0000 | [diff] [blame] | 281 | struct iptables_rule_match *matchp = NULL; |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 282 | struct xtables_target *t = NULL; |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 283 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 284 | printf("%s v%s\n\n" |
András Kis-Szabó | 0c4188f | 2002-08-14 11:40:41 +0000 | [diff] [blame] | 285 | "Usage: %s -[AD] chain rule-specification [options]\n" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 286 | " %s -[RI] chain rulenum rule-specification [options]\n" |
| 287 | " %s -D chain rulenum [options]\n" |
| 288 | " %s -[LFZ] [chain] [options]\n" |
| 289 | " %s -[NX] chain\n" |
| 290 | " %s -E old-chain-name new-chain-name\n" |
| 291 | " %s -P chain target [options]\n" |
| 292 | " %s -h (print this help information)\n\n", |
| 293 | program_name, program_version, program_name, program_name, |
| 294 | program_name, program_name, program_name, program_name, |
| 295 | program_name, program_name); |
| 296 | |
| 297 | printf( |
| 298 | "Commands:\n" |
| 299 | "Either long or short options are allowed.\n" |
| 300 | " --append -A chain Append to chain\n" |
| 301 | " --delete -D chain Delete matching rule from chain\n" |
| 302 | " --delete -D chain rulenum\n" |
| 303 | " Delete rule rulenum (1 = first) from chain\n" |
| 304 | " --insert -I chain [rulenum]\n" |
| 305 | " Insert in chain as rulenum (default 1=first)\n" |
| 306 | " --replace -R chain rulenum\n" |
| 307 | " Replace rule rulenum (1 = first) in chain\n" |
| 308 | " --list -L [chain] List the rules in a chain or all chains\n" |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 309 | " --list-rules\n" |
| 310 | " -S [chain] Print the rules in a chain or all chains\n" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 311 | " --flush -F [chain] Delete all rules in chain or all chains\n" |
| 312 | " --zero -Z [chain] Zero counters in chain or all chains\n" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 313 | " --new -N chain Create a new user-defined chain\n" |
| 314 | " --delete-chain\n" |
| 315 | " -X [chain] Delete a user-defined chain\n" |
| 316 | " --policy -P chain target\n" |
| 317 | " Change policy on chain to target\n" |
| 318 | " --rename-chain\n" |
| 319 | " -E old-chain new-chain\n" |
| 320 | " Change chain name, (moving any references)\n" |
| 321 | |
| 322 | "Options:\n" |
| 323 | " --proto -p [!] proto protocol: by number or name, eg. `tcp'\n" |
| 324 | " --source -s [!] address[/mask]\n" |
| 325 | " source specification\n" |
| 326 | " --destination -d [!] address[/mask]\n" |
| 327 | " destination specification\n" |
| 328 | " --in-interface -i [!] input name[+]\n" |
| 329 | " network interface name ([+] for wildcard)\n" |
| 330 | " --jump -j target\n" |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 331 | " target for rule (may load target extension)\n" |
Henrik Nordstrom | 17fc163 | 2005-11-05 09:26:40 +0000 | [diff] [blame] | 332 | #ifdef IPT_F_GOTO |
| 333 | " --goto -g chain\n" |
| 334 | " jump to chain with no return\n" |
| 335 | #endif |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 336 | " --match -m match\n" |
| 337 | " extended match (may load extension)\n" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 338 | " --numeric -n numeric output of addresses and ports\n" |
| 339 | " --out-interface -o [!] output name[+]\n" |
| 340 | " network interface name ([+] for wildcard)\n" |
| 341 | " --table -t table table to manipulate (default: `filter')\n" |
| 342 | " --verbose -v verbose mode\n" |
Harald Welte | 82dd2ec | 2000-12-19 05:18:15 +0000 | [diff] [blame] | 343 | " --line-numbers print line numbers when listing\n" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 344 | " --exact -x expand numbers (display exact values)\n" |
| 345 | "[!] --fragment -f match second or further fragments only\n" |
Rusty Russell | a4d3e1f | 2001-01-07 06:56:02 +0000 | [diff] [blame] | 346 | " --modprobe=<command> try to insert modules using this command\n" |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 347 | " --set-counters PKTS BYTES set the counter during insert/append\n" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 348 | "[!] --version -V print package version.\n"); |
| 349 | |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 350 | /* Print out any special helps. A user might like to be able |
| 351 | to add a --help to the commandline, and see expected |
Martin Josefsson | 66aea6f | 2004-05-26 15:41:54 +0000 | [diff] [blame] | 352 | results. So we call help for all specified matches & targets */ |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 353 | for (t = xtables_targets; t ;t = t->next) { |
Martin Josefsson | 66aea6f | 2004-05-26 15:41:54 +0000 | [diff] [blame] | 354 | if (t->used) { |
| 355 | printf("\n"); |
| 356 | t->help(); |
| 357 | } |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 358 | } |
Martin Josefsson | 66aea6f | 2004-05-26 15:41:54 +0000 | [diff] [blame] | 359 | for (matchp = matches; matchp; matchp = matchp->next) { |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 360 | printf("\n"); |
Martin Josefsson | 66aea6f | 2004-05-26 15:41:54 +0000 | [diff] [blame] | 361 | matchp->match->help(); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 362 | } |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 363 | exit(0); |
| 364 | } |
| 365 | |
Patrick McHardy | 0b63936 | 2007-09-08 16:00:01 +0000 | [diff] [blame] | 366 | void |
| 367 | exit_error(enum exittype status, const char *msg, ...) |
| 368 | { |
| 369 | va_list args; |
| 370 | |
| 371 | va_start(args, msg); |
| 372 | fprintf(stderr, "%s v%s: ", program_name, program_version); |
| 373 | vfprintf(stderr, msg, args); |
| 374 | va_end(args); |
| 375 | fprintf(stderr, "\n"); |
| 376 | if (status == PARAMETER_PROBLEM) |
| 377 | exit_tryhelp(status); |
| 378 | if (status == VERSION_PROBLEM) |
| 379 | fprintf(stderr, |
| 380 | "Perhaps iptables or your kernel needs to be upgraded.\n"); |
| 381 | /* On error paths, make sure that we don't leak memory */ |
| 382 | free_opts(1); |
| 383 | exit(status); |
| 384 | } |
| 385 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 386 | static void |
| 387 | generic_opt_check(int command, int options) |
| 388 | { |
| 389 | int i, j, legal = 0; |
| 390 | |
| 391 | /* Check that commands are valid with options. Complicated by the |
| 392 | * fact that if an option is legal with *any* command given, it is |
| 393 | * legal overall (ie. -z and -l). |
| 394 | */ |
| 395 | for (i = 0; i < NUMBER_OF_OPT; i++) { |
| 396 | legal = 0; /* -1 => illegal, 1 => legal, 0 => undecided. */ |
| 397 | |
| 398 | for (j = 0; j < NUMBER_OF_CMD; j++) { |
| 399 | if (!(command & (1<<j))) |
| 400 | continue; |
| 401 | |
| 402 | if (!(options & (1<<i))) { |
| 403 | if (commands_v_options[j][i] == '+') |
| 404 | exit_error(PARAMETER_PROBLEM, |
| 405 | "You need to supply the `-%c' " |
| 406 | "option for this command\n", |
| 407 | optflags[i]); |
| 408 | } else { |
| 409 | if (commands_v_options[j][i] != 'x') |
| 410 | legal = 1; |
| 411 | else if (legal == 0) |
| 412 | legal = -1; |
| 413 | } |
| 414 | } |
| 415 | if (legal == -1) |
| 416 | exit_error(PARAMETER_PROBLEM, |
| 417 | "Illegal option `-%c' with this command\n", |
| 418 | optflags[i]); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | static char |
| 423 | opt2char(int option) |
| 424 | { |
| 425 | const char *ptr; |
| 426 | for (ptr = optflags; option > 1; option >>= 1, ptr++); |
| 427 | |
| 428 | return *ptr; |
| 429 | } |
| 430 | |
| 431 | static char |
| 432 | cmd2char(int option) |
| 433 | { |
| 434 | const char *ptr; |
| 435 | for (ptr = cmdflags; option > 1; option >>= 1, ptr++); |
| 436 | |
| 437 | return *ptr; |
| 438 | } |
| 439 | |
| 440 | static void |
Harald Welte | efa8fc2 | 2005-07-19 22:03:49 +0000 | [diff] [blame] | 441 | add_command(unsigned int *cmd, const int newcmd, const int othercmds, |
| 442 | int invert) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 443 | { |
| 444 | if (invert) |
| 445 | exit_error(PARAMETER_PROBLEM, "unexpected ! flag"); |
| 446 | if (*cmd & (~othercmds)) |
| 447 | exit_error(PARAMETER_PROBLEM, "Can't use -%c with -%c\n", |
| 448 | cmd2char(newcmd), cmd2char(*cmd & (~othercmds))); |
| 449 | *cmd |= newcmd; |
| 450 | } |
| 451 | |
| 452 | int |
Jan Engelhardt | dbb7754 | 2008-02-11 00:33:30 +0100 | [diff] [blame] | 453 | check_inverse(const char option[], int *invert, int *my_optind, int argc) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 454 | { |
| 455 | if (option && strcmp(option, "!") == 0) { |
| 456 | if (*invert) |
| 457 | exit_error(PARAMETER_PROBLEM, |
| 458 | "Multiple `!' flags not allowed"); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 459 | *invert = TRUE; |
Jan Engelhardt | dbb7754 | 2008-02-11 00:33:30 +0100 | [diff] [blame] | 460 | if (my_optind != NULL) { |
| 461 | ++*my_optind; |
| 462 | if (argc && *my_optind > argc) |
Harald Welte | b77f1da | 2002-03-14 11:35:58 +0000 | [diff] [blame] | 463 | exit_error(PARAMETER_PROBLEM, |
| 464 | "no argument following `!'"); |
| 465 | } |
| 466 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 467 | return TRUE; |
| 468 | } |
| 469 | return FALSE; |
| 470 | } |
| 471 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 472 | /* |
| 473 | * All functions starting with "parse" should succeed, otherwise |
| 474 | * the program fails. |
| 475 | * Most routines return pointers to static data that may change |
| 476 | * between calls to the same or other routines with a few exceptions: |
| 477 | * "host_to_addr", "parse_hostnetwork", and "parse_hostnetworkmask" |
| 478 | * return global static data. |
| 479 | */ |
| 480 | |
Rusty Russell | 28381a4 | 2000-05-10 00:19:50 +0000 | [diff] [blame] | 481 | /* Christophe Burki wants `-p 6' to imply `-m tcp'. */ |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 482 | static struct xtables_match * |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 483 | find_proto(const char *pname, enum ipt_tryload tryload, int nolookup, struct iptables_rule_match **matches) |
Rusty Russell | 28381a4 | 2000-05-10 00:19:50 +0000 | [diff] [blame] | 484 | { |
Harald Welte | ed49849 | 2001-07-23 01:24:22 +0000 | [diff] [blame] | 485 | unsigned int proto; |
Rusty Russell | 28381a4 | 2000-05-10 00:19:50 +0000 | [diff] [blame] | 486 | |
Harald Welte | 0b0013a | 2002-02-18 16:15:31 +0000 | [diff] [blame] | 487 | if (string_to_number(pname, 0, 255, &proto) != -1) { |
| 488 | char *protoname = proto_to_name(proto, nolookup); |
Rusty Russell | 28381a4 | 2000-05-10 00:19:50 +0000 | [diff] [blame] | 489 | |
Harald Welte | 0b0013a | 2002-02-18 16:15:31 +0000 | [diff] [blame] | 490 | if (protoname) |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 491 | return find_match(protoname, tryload, matches); |
Harald Welte | 0b0013a | 2002-02-18 16:15:31 +0000 | [diff] [blame] | 492 | } else |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 493 | return find_match(pname, tryload, matches); |
Harald Welte | 0b0013a | 2002-02-18 16:15:31 +0000 | [diff] [blame] | 494 | |
| 495 | return NULL; |
Rusty Russell | 28381a4 | 2000-05-10 00:19:50 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Marc Boucher | b93c798 | 2001-12-06 14:50:19 +0000 | [diff] [blame] | 498 | u_int16_t |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 499 | parse_protocol(const char *s) |
| 500 | { |
Harald Welte | ed49849 | 2001-07-23 01:24:22 +0000 | [diff] [blame] | 501 | unsigned int proto; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 502 | |
Harald Welte | ed49849 | 2001-07-23 01:24:22 +0000 | [diff] [blame] | 503 | if (string_to_number(s, 0, 255, &proto) == -1) { |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 504 | struct protoent *pent; |
| 505 | |
Harald Welte | cbe1ec7 | 2006-02-11 09:50:11 +0000 | [diff] [blame] | 506 | /* first deal with the special case of 'all' to prevent |
| 507 | * people from being able to redefine 'all' in nsswitch |
| 508 | * and/or provoke expensive [not working] ldap/nis/... |
| 509 | * lookups */ |
| 510 | if (!strcmp(s, "all")) |
| 511 | return 0; |
| 512 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 513 | if ((pent = getprotobyname(s))) |
| 514 | proto = pent->p_proto; |
| 515 | else { |
| 516 | unsigned int i; |
| 517 | for (i = 0; |
| 518 | i < sizeof(chain_protos)/sizeof(struct pprot); |
| 519 | i++) { |
| 520 | if (strcmp(s, chain_protos[i].name) == 0) { |
| 521 | proto = chain_protos[i].num; |
| 522 | break; |
| 523 | } |
| 524 | } |
| 525 | if (i == sizeof(chain_protos)/sizeof(struct pprot)) |
| 526 | exit_error(PARAMETER_PROBLEM, |
| 527 | "unknown protocol `%s' specified", |
| 528 | s); |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | return (u_int16_t)proto; |
| 533 | } |
| 534 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 535 | /* Can't be zero. */ |
| 536 | static int |
| 537 | parse_rulenumber(const char *rule) |
| 538 | { |
Harald Welte | ed49849 | 2001-07-23 01:24:22 +0000 | [diff] [blame] | 539 | unsigned int rulenum; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 540 | |
Harald Welte | ed49849 | 2001-07-23 01:24:22 +0000 | [diff] [blame] | 541 | if (string_to_number(rule, 1, INT_MAX, &rulenum) == -1) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 542 | exit_error(PARAMETER_PROBLEM, |
| 543 | "Invalid rule number `%s'", rule); |
| 544 | |
| 545 | return rulenum; |
| 546 | } |
| 547 | |
| 548 | static const char * |
| 549 | parse_target(const char *targetname) |
| 550 | { |
| 551 | const char *ptr; |
| 552 | |
| 553 | if (strlen(targetname) < 1) |
| 554 | exit_error(PARAMETER_PROBLEM, |
| 555 | "Invalid target name (too short)"); |
| 556 | |
| 557 | if (strlen(targetname)+1 > sizeof(ipt_chainlabel)) |
| 558 | exit_error(PARAMETER_PROBLEM, |
Martin Josefsson | a28d495 | 2004-05-26 16:04:48 +0000 | [diff] [blame] | 559 | "Invalid target name `%s' (%u chars max)", |
| 560 | targetname, (unsigned int)sizeof(ipt_chainlabel)-1); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 561 | |
| 562 | for (ptr = targetname; *ptr; ptr++) |
| 563 | if (isspace(*ptr)) |
| 564 | exit_error(PARAMETER_PROBLEM, |
| 565 | "Invalid target name `%s'", targetname); |
| 566 | return targetname; |
| 567 | } |
| 568 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 569 | static void |
| 570 | set_option(unsigned int *options, unsigned int option, u_int8_t *invflg, |
| 571 | int invert) |
| 572 | { |
| 573 | if (*options & option) |
| 574 | exit_error(PARAMETER_PROBLEM, "multiple -%c flags not allowed", |
| 575 | opt2char(option)); |
| 576 | *options |= option; |
| 577 | |
| 578 | if (invert) { |
| 579 | unsigned int i; |
| 580 | for (i = 0; 1 << i != option; i++); |
| 581 | |
| 582 | if (!inverse_for_options[i]) |
| 583 | exit_error(PARAMETER_PROBLEM, |
| 584 | "cannot have ! before -%c", |
| 585 | opt2char(option)); |
| 586 | *invflg |= inverse_for_options[i]; |
| 587 | } |
| 588 | } |
| 589 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 590 | static struct option * |
Jan Echternach | 5a1041d | 2000-08-26 04:44:39 +0000 | [diff] [blame] | 591 | merge_options(struct option *oldopts, const struct option *newopts, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 592 | unsigned int *option_offset) |
| 593 | { |
| 594 | unsigned int num_old, num_new, i; |
| 595 | struct option *merge; |
| 596 | |
Jan Engelhardt | d014540 | 2007-07-30 14:32:26 +0000 | [diff] [blame] | 597 | if (newopts == NULL) |
| 598 | return oldopts; |
| 599 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 600 | for (num_old = 0; oldopts[num_old].name; num_old++); |
| 601 | for (num_new = 0; newopts[num_new].name; num_new++); |
| 602 | |
| 603 | global_option_offset += OPTION_OFFSET; |
| 604 | *option_offset = global_option_offset; |
| 605 | |
| 606 | merge = malloc(sizeof(struct option) * (num_new + num_old + 1)); |
Pablo Neira Ayuso | 8e707d7 | 2008-01-17 17:30:27 +0000 | [diff] [blame] | 607 | if (merge == NULL) |
| 608 | return NULL; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 609 | memcpy(merge, oldopts, num_old * sizeof(struct option)); |
Marcus Sundberg | d91ed75 | 2005-07-29 13:26:35 +0000 | [diff] [blame] | 610 | free_opts(0); /* Release previous options merged if any */ |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 611 | for (i = 0; i < num_new; i++) { |
| 612 | merge[num_old + i] = newopts[i]; |
| 613 | merge[num_old + i].val += *option_offset; |
| 614 | } |
| 615 | memset(merge + num_old + num_new, 0, sizeof(struct option)); |
| 616 | |
| 617 | return merge; |
| 618 | } |
| 619 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 620 | static void |
Harald Welte | a0b4f79 | 2001-03-25 19:55:04 +0000 | [diff] [blame] | 621 | print_num(u_int64_t number, unsigned int format) |
| 622 | { |
| 623 | if (format & FMT_KILOMEGAGIGA) { |
| 624 | if (number > 99999) { |
| 625 | number = (number + 500) / 1000; |
| 626 | if (number > 9999) { |
| 627 | number = (number + 500) / 1000; |
| 628 | if (number > 9999) { |
| 629 | number = (number + 500) / 1000; |
Rusty Russell | 5a66fe4 | 2001-08-15 11:21:59 +0000 | [diff] [blame] | 630 | if (number > 9999) { |
| 631 | number = (number + 500) / 1000; |
Martin Josefsson | a28d495 | 2004-05-26 16:04:48 +0000 | [diff] [blame] | 632 | printf(FMT("%4lluT ","%lluT "), (unsigned long long)number); |
Rusty Russell | 5a66fe4 | 2001-08-15 11:21:59 +0000 | [diff] [blame] | 633 | } |
Martin Josefsson | a28d495 | 2004-05-26 16:04:48 +0000 | [diff] [blame] | 634 | else printf(FMT("%4lluG ","%lluG "), (unsigned long long)number); |
Harald Welte | a0b4f79 | 2001-03-25 19:55:04 +0000 | [diff] [blame] | 635 | } |
Martin Josefsson | a28d495 | 2004-05-26 16:04:48 +0000 | [diff] [blame] | 636 | else printf(FMT("%4lluM ","%lluM "), (unsigned long long)number); |
Harald Welte | a0b4f79 | 2001-03-25 19:55:04 +0000 | [diff] [blame] | 637 | } else |
Martin Josefsson | a28d495 | 2004-05-26 16:04:48 +0000 | [diff] [blame] | 638 | printf(FMT("%4lluK ","%lluK "), (unsigned long long)number); |
Harald Welte | a0b4f79 | 2001-03-25 19:55:04 +0000 | [diff] [blame] | 639 | } else |
Martin Josefsson | a28d495 | 2004-05-26 16:04:48 +0000 | [diff] [blame] | 640 | printf(FMT("%5llu ","%llu "), (unsigned long long)number); |
Harald Welte | a0b4f79 | 2001-03-25 19:55:04 +0000 | [diff] [blame] | 641 | } else |
Martin Josefsson | a28d495 | 2004-05-26 16:04:48 +0000 | [diff] [blame] | 642 | printf(FMT("%8llu ","%llu "), (unsigned long long)number); |
Harald Welte | a0b4f79 | 2001-03-25 19:55:04 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | |
| 646 | static void |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 647 | print_header(unsigned int format, const char *chain, iptc_handle_t *handle) |
| 648 | { |
| 649 | struct ipt_counters counters; |
| 650 | const char *pol = iptc_get_policy(chain, &counters, handle); |
| 651 | printf("Chain %s", chain); |
| 652 | if (pol) { |
| 653 | printf(" (policy %s", pol); |
Harald Welte | a0b4f79 | 2001-03-25 19:55:04 +0000 | [diff] [blame] | 654 | if (!(format & FMT_NOCOUNTS)) { |
| 655 | fputc(' ', stdout); |
| 656 | print_num(counters.pcnt, (format|FMT_NOTABLE)); |
| 657 | fputs("packets, ", stdout); |
| 658 | print_num(counters.bcnt, (format|FMT_NOTABLE)); |
| 659 | fputs("bytes", stdout); |
| 660 | } |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 661 | printf(")\n"); |
| 662 | } else { |
| 663 | unsigned int refs; |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 664 | if (!iptc_get_references(&refs, chain, handle)) |
| 665 | printf(" (ERROR obtaining refs)\n"); |
| 666 | else |
| 667 | printf(" (%u references)\n", refs); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | if (format & FMT_LINENUMBERS) |
| 671 | printf(FMT("%-4s ", "%s "), "num"); |
| 672 | if (!(format & FMT_NOCOUNTS)) { |
| 673 | if (format & FMT_KILOMEGAGIGA) { |
| 674 | printf(FMT("%5s ","%s "), "pkts"); |
| 675 | printf(FMT("%5s ","%s "), "bytes"); |
| 676 | } else { |
| 677 | printf(FMT("%8s ","%s "), "pkts"); |
| 678 | printf(FMT("%10s ","%s "), "bytes"); |
| 679 | } |
| 680 | } |
| 681 | if (!(format & FMT_NOTARGET)) |
| 682 | printf(FMT("%-9s ","%s "), "target"); |
| 683 | fputs(" prot ", stdout); |
| 684 | if (format & FMT_OPTIONS) |
| 685 | fputs("opt", stdout); |
| 686 | if (format & FMT_VIA) { |
| 687 | printf(FMT(" %-6s ","%s "), "in"); |
| 688 | printf(FMT("%-6s ","%s "), "out"); |
| 689 | } |
| 690 | printf(FMT(" %-19s ","%s "), "source"); |
| 691 | printf(FMT(" %-19s "," %s "), "destination"); |
| 692 | printf("\n"); |
| 693 | } |
| 694 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 695 | |
| 696 | static int |
| 697 | print_match(const struct ipt_entry_match *m, |
| 698 | const struct ipt_ip *ip, |
| 699 | int numeric) |
| 700 | { |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 701 | struct xtables_match *match = find_match(m->u.user.name, TRY_LOAD, NULL); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 702 | |
| 703 | if (match) { |
| 704 | if (match->print) |
| 705 | match->print(ip, m, numeric); |
Rusty Russell | 629149f | 2000-09-01 06:01:00 +0000 | [diff] [blame] | 706 | else |
Rusty Russell | b039b02 | 2000-09-01 06:04:05 +0000 | [diff] [blame] | 707 | printf("%s ", match->name); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 708 | } else { |
Rusty Russell | 228e98d | 2000-04-27 10:28:06 +0000 | [diff] [blame] | 709 | if (m->u.user.name[0]) |
| 710 | printf("UNKNOWN match `%s' ", m->u.user.name); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 711 | } |
| 712 | /* Don't stop iterating. */ |
| 713 | return 0; |
| 714 | } |
| 715 | |
Jan Engelhardt | 6cf172e | 2008-03-10 17:48:59 +0100 | [diff] [blame] | 716 | /* e is called `fw' here for historical reasons */ |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 717 | static void |
| 718 | print_firewall(const struct ipt_entry *fw, |
| 719 | const char *targname, |
| 720 | unsigned int num, |
| 721 | unsigned int format, |
| 722 | const iptc_handle_t handle) |
| 723 | { |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 724 | struct xtables_target *target = NULL; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 725 | const struct ipt_entry_target *t; |
| 726 | u_int8_t flags; |
| 727 | char buf[BUFSIZ]; |
| 728 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 729 | if (!iptc_is_chain(targname, handle)) |
Rusty Russell | 52a5149 | 2000-05-02 16:44:29 +0000 | [diff] [blame] | 730 | target = find_target(targname, TRY_LOAD); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 731 | else |
Rusty Russell | 52a5149 | 2000-05-02 16:44:29 +0000 | [diff] [blame] | 732 | target = find_target(IPT_STANDARD_TARGET, LOAD_MUST_SUCCEED); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 733 | |
| 734 | t = ipt_get_target((struct ipt_entry *)fw); |
| 735 | flags = fw->ip.flags; |
| 736 | |
| 737 | if (format & FMT_LINENUMBERS) |
| 738 | printf(FMT("%-4u ", "%u "), num+1); |
| 739 | |
| 740 | if (!(format & FMT_NOCOUNTS)) { |
| 741 | print_num(fw->counters.pcnt, format); |
| 742 | print_num(fw->counters.bcnt, format); |
| 743 | } |
| 744 | |
| 745 | if (!(format & FMT_NOTARGET)) |
| 746 | printf(FMT("%-9s ", "%s "), targname); |
| 747 | |
| 748 | fputc(fw->ip.invflags & IPT_INV_PROTO ? '!' : ' ', stdout); |
| 749 | { |
Rusty Russell | 28381a4 | 2000-05-10 00:19:50 +0000 | [diff] [blame] | 750 | char *pname = proto_to_name(fw->ip.proto, format&FMT_NUMERIC); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 751 | if (pname) |
| 752 | printf(FMT("%-5s", "%s "), pname); |
| 753 | else |
| 754 | printf(FMT("%-5hu", "%hu "), fw->ip.proto); |
| 755 | } |
| 756 | |
| 757 | if (format & FMT_OPTIONS) { |
| 758 | if (format & FMT_NOTABLE) |
| 759 | fputs("opt ", stdout); |
| 760 | fputc(fw->ip.invflags & IPT_INV_FRAG ? '!' : '-', stdout); |
| 761 | fputc(flags & IPT_F_FRAG ? 'f' : '-', stdout); |
| 762 | fputc(' ', stdout); |
| 763 | } |
| 764 | |
| 765 | if (format & FMT_VIA) { |
| 766 | char iface[IFNAMSIZ+2]; |
| 767 | |
| 768 | if (fw->ip.invflags & IPT_INV_VIA_IN) { |
| 769 | iface[0] = '!'; |
| 770 | iface[1] = '\0'; |
| 771 | } |
| 772 | else iface[0] = '\0'; |
| 773 | |
| 774 | if (fw->ip.iniface[0] != '\0') { |
| 775 | strcat(iface, fw->ip.iniface); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 776 | } |
| 777 | else if (format & FMT_NUMERIC) strcat(iface, "*"); |
| 778 | else strcat(iface, "any"); |
| 779 | printf(FMT(" %-6s ","in %s "), iface); |
| 780 | |
| 781 | if (fw->ip.invflags & IPT_INV_VIA_OUT) { |
| 782 | iface[0] = '!'; |
| 783 | iface[1] = '\0'; |
| 784 | } |
| 785 | else iface[0] = '\0'; |
| 786 | |
| 787 | if (fw->ip.outiface[0] != '\0') { |
| 788 | strcat(iface, fw->ip.outiface); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 789 | } |
| 790 | else if (format & FMT_NUMERIC) strcat(iface, "*"); |
| 791 | else strcat(iface, "any"); |
| 792 | printf(FMT("%-6s ","out %s "), iface); |
| 793 | } |
| 794 | |
| 795 | fputc(fw->ip.invflags & IPT_INV_SRCIP ? '!' : ' ', stdout); |
| 796 | if (fw->ip.smsk.s_addr == 0L && !(format & FMT_NUMERIC)) |
| 797 | printf(FMT("%-19s ","%s "), "anywhere"); |
| 798 | else { |
| 799 | if (format & FMT_NUMERIC) |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 800 | sprintf(buf, "%s", ipaddr_to_numeric(&fw->ip.src)); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 801 | else |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 802 | sprintf(buf, "%s", ipaddr_to_anyname(&fw->ip.src)); |
| 803 | strcat(buf, ipmask_to_numeric(&fw->ip.smsk)); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 804 | printf(FMT("%-19s ","%s "), buf); |
| 805 | } |
| 806 | |
| 807 | fputc(fw->ip.invflags & IPT_INV_DSTIP ? '!' : ' ', stdout); |
| 808 | if (fw->ip.dmsk.s_addr == 0L && !(format & FMT_NUMERIC)) |
Harald Welte | 25fc1d7 | 2003-05-31 21:30:33 +0000 | [diff] [blame] | 809 | printf(FMT("%-19s ","-> %s"), "anywhere"); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 810 | else { |
| 811 | if (format & FMT_NUMERIC) |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 812 | sprintf(buf, "%s", ipaddr_to_numeric(&fw->ip.dst)); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 813 | else |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 814 | sprintf(buf, "%s", ipaddr_to_anyname(&fw->ip.dst)); |
| 815 | strcat(buf, ipmask_to_numeric(&fw->ip.dmsk)); |
Harald Welte | 25fc1d7 | 2003-05-31 21:30:33 +0000 | [diff] [blame] | 816 | printf(FMT("%-19s ","-> %s"), buf); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | if (format & FMT_NOTABLE) |
| 820 | fputs(" ", stdout); |
| 821 | |
Harald Welte | 72bd87e | 2005-11-24 17:04:05 +0000 | [diff] [blame] | 822 | #ifdef IPT_F_GOTO |
Henrik Nordstrom | 17fc163 | 2005-11-05 09:26:40 +0000 | [diff] [blame] | 823 | if(fw->ip.flags & IPT_F_GOTO) |
| 824 | printf("[goto] "); |
Harald Welte | 72bd87e | 2005-11-24 17:04:05 +0000 | [diff] [blame] | 825 | #endif |
Henrik Nordstrom | 17fc163 | 2005-11-05 09:26:40 +0000 | [diff] [blame] | 826 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 827 | IPT_MATCH_ITERATE(fw, print_match, &fw->ip, format & FMT_NUMERIC); |
| 828 | |
| 829 | if (target) { |
| 830 | if (target->print) |
| 831 | /* Print the target information. */ |
| 832 | target->print(&fw->ip, t, format & FMT_NUMERIC); |
Rusty Russell | 228e98d | 2000-04-27 10:28:06 +0000 | [diff] [blame] | 833 | } else if (t->u.target_size != sizeof(*t)) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 834 | printf("[%u bytes of unknown target data] ", |
Martin Josefsson | a28d495 | 2004-05-26 16:04:48 +0000 | [diff] [blame] | 835 | (unsigned int)(t->u.target_size - sizeof(*t))); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 836 | |
| 837 | if (!(format & FMT_NONEWLINE)) |
| 838 | fputc('\n', stdout); |
| 839 | } |
| 840 | |
| 841 | static void |
| 842 | print_firewall_line(const struct ipt_entry *fw, |
| 843 | const iptc_handle_t h) |
| 844 | { |
| 845 | struct ipt_entry_target *t; |
| 846 | |
| 847 | t = ipt_get_target((struct ipt_entry *)fw); |
Rusty Russell | 228e98d | 2000-04-27 10:28:06 +0000 | [diff] [blame] | 848 | print_firewall(fw, t->u.user.name, 0, FMT_PRINT_RULE, h); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static int |
| 852 | append_entry(const ipt_chainlabel chain, |
| 853 | struct ipt_entry *fw, |
| 854 | unsigned int nsaddrs, |
| 855 | const struct in_addr saddrs[], |
| 856 | unsigned int ndaddrs, |
| 857 | const struct in_addr daddrs[], |
| 858 | int verbose, |
| 859 | iptc_handle_t *handle) |
| 860 | { |
| 861 | unsigned int i, j; |
| 862 | int ret = 1; |
| 863 | |
| 864 | for (i = 0; i < nsaddrs; i++) { |
| 865 | fw->ip.src.s_addr = saddrs[i].s_addr; |
| 866 | for (j = 0; j < ndaddrs; j++) { |
| 867 | fw->ip.dst.s_addr = daddrs[j].s_addr; |
| 868 | if (verbose) |
| 869 | print_firewall_line(fw, *handle); |
| 870 | ret &= iptc_append_entry(chain, fw, handle); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | return ret; |
| 875 | } |
| 876 | |
| 877 | static int |
| 878 | replace_entry(const ipt_chainlabel chain, |
| 879 | struct ipt_entry *fw, |
| 880 | unsigned int rulenum, |
| 881 | const struct in_addr *saddr, |
| 882 | const struct in_addr *daddr, |
| 883 | int verbose, |
| 884 | iptc_handle_t *handle) |
| 885 | { |
| 886 | fw->ip.src.s_addr = saddr->s_addr; |
| 887 | fw->ip.dst.s_addr = daddr->s_addr; |
| 888 | |
| 889 | if (verbose) |
| 890 | print_firewall_line(fw, *handle); |
| 891 | return iptc_replace_entry(chain, fw, rulenum, handle); |
| 892 | } |
| 893 | |
| 894 | static int |
| 895 | insert_entry(const ipt_chainlabel chain, |
| 896 | struct ipt_entry *fw, |
| 897 | unsigned int rulenum, |
| 898 | unsigned int nsaddrs, |
| 899 | const struct in_addr saddrs[], |
| 900 | unsigned int ndaddrs, |
| 901 | const struct in_addr daddrs[], |
| 902 | int verbose, |
| 903 | iptc_handle_t *handle) |
| 904 | { |
| 905 | unsigned int i, j; |
| 906 | int ret = 1; |
| 907 | |
| 908 | for (i = 0; i < nsaddrs; i++) { |
| 909 | fw->ip.src.s_addr = saddrs[i].s_addr; |
| 910 | for (j = 0; j < ndaddrs; j++) { |
| 911 | fw->ip.dst.s_addr = daddrs[j].s_addr; |
| 912 | if (verbose) |
| 913 | print_firewall_line(fw, *handle); |
| 914 | ret &= iptc_insert_entry(chain, fw, rulenum, handle); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | return ret; |
| 919 | } |
| 920 | |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 921 | static unsigned char * |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 922 | make_delete_mask(struct ipt_entry *fw, struct iptables_rule_match *matches) |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 923 | { |
| 924 | /* Establish mask for comparison */ |
| 925 | unsigned int size; |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 926 | struct iptables_rule_match *matchp; |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 927 | unsigned char *mask, *mptr; |
| 928 | |
| 929 | size = sizeof(struct ipt_entry); |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 930 | for (matchp = matches; matchp; matchp = matchp->next) |
| 931 | size += IPT_ALIGN(sizeof(struct ipt_entry_match)) + matchp->match->size; |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 932 | |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 933 | mask = fw_calloc(1, size |
Rusty Russell | 73f72f5 | 2000-07-03 10:17:57 +0000 | [diff] [blame] | 934 | + IPT_ALIGN(sizeof(struct ipt_entry_target)) |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 935 | + xtables_targets->size); |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 936 | |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 937 | memset(mask, 0xFF, sizeof(struct ipt_entry)); |
| 938 | mptr = mask + sizeof(struct ipt_entry); |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 939 | |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 940 | for (matchp = matches; matchp; matchp = matchp->next) { |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 941 | memset(mptr, 0xFF, |
Rusty Russell | 73f72f5 | 2000-07-03 10:17:57 +0000 | [diff] [blame] | 942 | IPT_ALIGN(sizeof(struct ipt_entry_match)) |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 943 | + matchp->match->userspacesize); |
| 944 | mptr += IPT_ALIGN(sizeof(struct ipt_entry_match)) + matchp->match->size; |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Rusty Russell | a4d3e1f | 2001-01-07 06:56:02 +0000 | [diff] [blame] | 947 | memset(mptr, 0xFF, |
Rusty Russell | 73f72f5 | 2000-07-03 10:17:57 +0000 | [diff] [blame] | 948 | IPT_ALIGN(sizeof(struct ipt_entry_target)) |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 949 | + xtables_targets->userspacesize); |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 950 | |
| 951 | return mask; |
| 952 | } |
| 953 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 954 | static int |
| 955 | delete_entry(const ipt_chainlabel chain, |
| 956 | struct ipt_entry *fw, |
| 957 | unsigned int nsaddrs, |
| 958 | const struct in_addr saddrs[], |
| 959 | unsigned int ndaddrs, |
| 960 | const struct in_addr daddrs[], |
| 961 | int verbose, |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 962 | iptc_handle_t *handle, |
| 963 | struct iptables_rule_match *matches) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 964 | { |
| 965 | unsigned int i, j; |
| 966 | int ret = 1; |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 967 | unsigned char *mask; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 968 | |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 969 | mask = make_delete_mask(fw, matches); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 970 | for (i = 0; i < nsaddrs; i++) { |
| 971 | fw->ip.src.s_addr = saddrs[i].s_addr; |
| 972 | for (j = 0; j < ndaddrs; j++) { |
| 973 | fw->ip.dst.s_addr = daddrs[j].s_addr; |
| 974 | if (verbose) |
| 975 | print_firewall_line(fw, *handle); |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 976 | ret &= iptc_delete_entry(chain, fw, mask, handle); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 977 | } |
| 978 | } |
Martin Josefsson | 4dd5fed | 2004-05-18 18:09:43 +0000 | [diff] [blame] | 979 | free(mask); |
| 980 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 981 | return ret; |
| 982 | } |
| 983 | |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 984 | int |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 985 | for_each_chain(int (*fn)(const ipt_chainlabel, int, iptc_handle_t *), |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 986 | int verbose, int builtinstoo, iptc_handle_t *handle) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 987 | { |
| 988 | int ret = 1; |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 989 | const char *chain; |
| 990 | char *chains; |
| 991 | unsigned int i, chaincount = 0; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 992 | |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 993 | chain = iptc_first_chain(handle); |
| 994 | while (chain) { |
| 995 | chaincount++; |
| 996 | chain = iptc_next_chain(handle); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 999 | chains = fw_malloc(sizeof(ipt_chainlabel) * chaincount); |
| 1000 | i = 0; |
| 1001 | chain = iptc_first_chain(handle); |
| 1002 | while (chain) { |
| 1003 | strcpy(chains + i*sizeof(ipt_chainlabel), chain); |
| 1004 | i++; |
| 1005 | chain = iptc_next_chain(handle); |
| 1006 | } |
| 1007 | |
| 1008 | for (i = 0; i < chaincount; i++) { |
| 1009 | if (!builtinstoo |
| 1010 | && iptc_builtin(chains + i*sizeof(ipt_chainlabel), |
Harald Welte | 3a506ac | 2004-08-30 16:00:09 +0000 | [diff] [blame] | 1011 | *handle) == 1) |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 1012 | continue; |
| 1013 | ret &= fn(chains + i*sizeof(ipt_chainlabel), verbose, handle); |
| 1014 | } |
| 1015 | |
| 1016 | free(chains); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1017 | return ret; |
| 1018 | } |
| 1019 | |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 1020 | int |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1021 | flush_entries(const ipt_chainlabel chain, int verbose, |
| 1022 | iptc_handle_t *handle) |
| 1023 | { |
| 1024 | if (!chain) |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 1025 | return for_each_chain(flush_entries, verbose, 1, handle); |
Rusty Russell | 7e53bf9 | 2000-03-20 07:03:28 +0000 | [diff] [blame] | 1026 | |
| 1027 | if (verbose) |
| 1028 | fprintf(stdout, "Flushing chain `%s'\n", chain); |
| 1029 | return iptc_flush_entries(chain, handle); |
| 1030 | } |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1031 | |
| 1032 | static int |
| 1033 | zero_entries(const ipt_chainlabel chain, int verbose, |
| 1034 | iptc_handle_t *handle) |
| 1035 | { |
| 1036 | if (!chain) |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 1037 | return for_each_chain(zero_entries, verbose, 1, handle); |
Rusty Russell | 7e53bf9 | 2000-03-20 07:03:28 +0000 | [diff] [blame] | 1038 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1039 | if (verbose) |
| 1040 | fprintf(stdout, "Zeroing chain `%s'\n", chain); |
| 1041 | return iptc_zero_entries(chain, handle); |
| 1042 | } |
| 1043 | |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 1044 | int |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1045 | delete_chain(const ipt_chainlabel chain, int verbose, |
| 1046 | iptc_handle_t *handle) |
| 1047 | { |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 1048 | if (!chain) |
| 1049 | return for_each_chain(delete_chain, verbose, 0, handle); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1050 | |
| 1051 | if (verbose) |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1052 | fprintf(stdout, "Deleting chain `%s'\n", chain); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1053 | return iptc_delete_chain(chain, handle); |
| 1054 | } |
| 1055 | |
| 1056 | static int |
| 1057 | list_entries(const ipt_chainlabel chain, int verbose, int numeric, |
| 1058 | int expanded, int linenumbers, iptc_handle_t *handle) |
| 1059 | { |
| 1060 | int found = 0; |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 1061 | unsigned int format; |
| 1062 | const char *this; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1063 | |
| 1064 | format = FMT_OPTIONS; |
| 1065 | if (!verbose) |
| 1066 | format |= FMT_NOCOUNTS; |
| 1067 | else |
| 1068 | format |= FMT_VIA; |
| 1069 | |
| 1070 | if (numeric) |
| 1071 | format |= FMT_NUMERIC; |
| 1072 | |
| 1073 | if (!expanded) |
| 1074 | format |= FMT_KILOMEGAGIGA; |
| 1075 | |
| 1076 | if (linenumbers) |
| 1077 | format |= FMT_LINENUMBERS; |
| 1078 | |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 1079 | for (this = iptc_first_chain(handle); |
| 1080 | this; |
| 1081 | this = iptc_next_chain(handle)) { |
| 1082 | const struct ipt_entry *i; |
| 1083 | unsigned int num; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1084 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1085 | if (chain && strcmp(chain, this) != 0) |
| 1086 | continue; |
| 1087 | |
| 1088 | if (found) printf("\n"); |
| 1089 | |
| 1090 | print_header(format, this, handle); |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 1091 | i = iptc_first_rule(this, handle); |
| 1092 | |
| 1093 | num = 0; |
| 1094 | while (i) { |
| 1095 | print_firewall(i, |
| 1096 | iptc_get_target(i, handle), |
| 1097 | num++, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1098 | format, |
| 1099 | *handle); |
Rusty Russell | 9e1d214 | 2000-04-23 09:11:12 +0000 | [diff] [blame] | 1100 | i = iptc_next_rule(i, handle); |
| 1101 | } |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1102 | found = 1; |
| 1103 | } |
| 1104 | |
| 1105 | errno = ENOENT; |
| 1106 | return found; |
| 1107 | } |
| 1108 | |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 1109 | static void print_proto(u_int16_t proto, int invert) |
| 1110 | { |
| 1111 | if (proto) { |
| 1112 | unsigned int i; |
| 1113 | const char *invertstr = invert ? "! " : ""; |
| 1114 | |
| 1115 | struct protoent *pent = getprotobynumber(proto); |
| 1116 | if (pent) { |
| 1117 | printf("-p %s%s ", invertstr, pent->p_name); |
| 1118 | return; |
| 1119 | } |
| 1120 | |
| 1121 | for (i = 0; i < sizeof(chain_protos)/sizeof(struct pprot); i++) |
| 1122 | if (chain_protos[i].num == proto) { |
| 1123 | printf("-p %s%s ", |
| 1124 | invertstr, chain_protos[i].name); |
| 1125 | return; |
| 1126 | } |
| 1127 | |
| 1128 | printf("-p %s%u ", invertstr, proto); |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | #define IP_PARTS_NATIVE(n) \ |
| 1133 | (unsigned int)((n)>>24)&0xFF, \ |
| 1134 | (unsigned int)((n)>>16)&0xFF, \ |
| 1135 | (unsigned int)((n)>>8)&0xFF, \ |
| 1136 | (unsigned int)((n)&0xFF) |
| 1137 | |
| 1138 | #define IP_PARTS(n) IP_PARTS_NATIVE(ntohl(n)) |
| 1139 | |
| 1140 | /* This assumes that mask is contiguous, and byte-bounded. */ |
| 1141 | static void |
| 1142 | print_iface(char letter, const char *iface, const unsigned char *mask, |
| 1143 | int invert) |
| 1144 | { |
| 1145 | unsigned int i; |
| 1146 | |
| 1147 | if (mask[0] == 0) |
| 1148 | return; |
| 1149 | |
| 1150 | printf("-%c %s", letter, invert ? "! " : ""); |
| 1151 | |
| 1152 | for (i = 0; i < IFNAMSIZ; i++) { |
| 1153 | if (mask[i] != 0) { |
| 1154 | if (iface[i] != '\0') |
| 1155 | printf("%c", iface[i]); |
| 1156 | } else { |
| 1157 | /* we can access iface[i-1] here, because |
| 1158 | * a few lines above we make sure that mask[0] != 0 */ |
| 1159 | if (iface[i-1] != '\0') |
| 1160 | printf("+"); |
| 1161 | break; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | printf(" "); |
| 1166 | } |
| 1167 | |
| 1168 | static int print_match_save(const struct ipt_entry_match *e, |
| 1169 | const struct ipt_ip *ip) |
| 1170 | { |
| 1171 | struct xtables_match *match |
| 1172 | = find_match(e->u.user.name, TRY_LOAD, NULL); |
| 1173 | |
| 1174 | if (match) { |
| 1175 | printf("-m %s ", e->u.user.name); |
| 1176 | |
| 1177 | /* some matches don't provide a save function */ |
| 1178 | if (match->save) |
| 1179 | match->save(ip, e); |
| 1180 | } else { |
| 1181 | if (e->u.match_size) { |
| 1182 | fprintf(stderr, |
| 1183 | "Can't find library for match `%s'\n", |
| 1184 | e->u.user.name); |
| 1185 | exit(1); |
| 1186 | } |
| 1187 | } |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | /* print a given ip including mask if neccessary */ |
| 1192 | static void print_ip(char *prefix, u_int32_t ip, u_int32_t mask, int invert) |
| 1193 | { |
| 1194 | u_int32_t bits, hmask = ntohl(mask); |
| 1195 | int i; |
| 1196 | |
| 1197 | if (!mask && !ip && !invert) |
| 1198 | return; |
| 1199 | |
| 1200 | printf("%s %s%u.%u.%u.%u", |
| 1201 | prefix, |
| 1202 | invert ? "! " : "", |
| 1203 | IP_PARTS(ip)); |
| 1204 | |
| 1205 | if (mask == 0xFFFFFFFFU) { |
| 1206 | printf("/32 "); |
| 1207 | return; |
| 1208 | } |
| 1209 | |
| 1210 | i = 32; |
| 1211 | bits = 0xFFFFFFFEU; |
| 1212 | while (--i >= 0 && hmask != bits) |
| 1213 | bits <<= 1; |
| 1214 | if (i >= 0) |
| 1215 | printf("/%u ", i); |
| 1216 | else |
| 1217 | printf("/%u.%u.%u.%u ", IP_PARTS(mask)); |
| 1218 | } |
| 1219 | |
| 1220 | /* We want this to be readable, so only print out neccessary fields. |
| 1221 | * Because that's the kind of world I want to live in. */ |
| 1222 | void print_rule(const struct ipt_entry *e, |
| 1223 | iptc_handle_t *h, const char *chain, int counters) |
| 1224 | { |
| 1225 | struct ipt_entry_target *t; |
| 1226 | const char *target_name; |
| 1227 | |
| 1228 | /* print counters for iptables-save */ |
| 1229 | if (counters > 0) |
| 1230 | printf("[%llu:%llu] ", (unsigned long long)e->counters.pcnt, (unsigned long long)e->counters.bcnt); |
| 1231 | |
| 1232 | /* print chain name */ |
| 1233 | printf("-A %s ", chain); |
| 1234 | |
| 1235 | /* Print IP part. */ |
| 1236 | print_ip("-s", e->ip.src.s_addr,e->ip.smsk.s_addr, |
| 1237 | e->ip.invflags & IPT_INV_SRCIP); |
| 1238 | |
| 1239 | print_ip("-d", e->ip.dst.s_addr, e->ip.dmsk.s_addr, |
| 1240 | e->ip.invflags & IPT_INV_DSTIP); |
| 1241 | |
| 1242 | print_iface('i', e->ip.iniface, e->ip.iniface_mask, |
| 1243 | e->ip.invflags & IPT_INV_VIA_IN); |
| 1244 | |
| 1245 | print_iface('o', e->ip.outiface, e->ip.outiface_mask, |
| 1246 | e->ip.invflags & IPT_INV_VIA_OUT); |
| 1247 | |
| 1248 | print_proto(e->ip.proto, e->ip.invflags & IPT_INV_PROTO); |
| 1249 | |
| 1250 | if (e->ip.flags & IPT_F_FRAG) |
| 1251 | printf("%s-f ", |
| 1252 | e->ip.invflags & IPT_INV_FRAG ? "! " : ""); |
| 1253 | |
| 1254 | /* Print matchinfo part */ |
| 1255 | if (e->target_offset) { |
| 1256 | IPT_MATCH_ITERATE(e, print_match_save, &e->ip); |
| 1257 | } |
| 1258 | |
| 1259 | /* print counters for iptables -R */ |
| 1260 | if (counters < 0) |
| 1261 | printf("-c %llu %llu ", (unsigned long long)e->counters.pcnt, (unsigned long long)e->counters.bcnt); |
| 1262 | |
| 1263 | /* Print target name */ |
| 1264 | target_name = iptc_get_target(e, h); |
| 1265 | if (target_name && (*target_name != '\0')) |
| 1266 | #ifdef IPT_F_GOTO |
| 1267 | printf("-%c %s ", e->ip.flags & IPT_F_GOTO ? 'g' : 'j', target_name); |
| 1268 | #else |
| 1269 | printf("-j %s ", target_name); |
| 1270 | #endif |
| 1271 | |
| 1272 | /* Print targinfo part */ |
| 1273 | t = ipt_get_target((struct ipt_entry *)e); |
| 1274 | if (t->u.user.name[0]) { |
| 1275 | struct xtables_target *target |
| 1276 | = find_target(t->u.user.name, TRY_LOAD); |
| 1277 | |
| 1278 | if (!target) { |
| 1279 | fprintf(stderr, "Can't find library for target `%s'\n", |
| 1280 | t->u.user.name); |
| 1281 | exit(1); |
| 1282 | } |
| 1283 | |
| 1284 | if (target->save) |
| 1285 | target->save(&e->ip, t); |
| 1286 | else { |
| 1287 | /* If the target size is greater than ipt_entry_target |
| 1288 | * there is something to be saved, we just don't know |
| 1289 | * how to print it */ |
| 1290 | if (t->u.target_size != |
| 1291 | sizeof(struct ipt_entry_target)) { |
| 1292 | fprintf(stderr, "Target `%s' is missing " |
| 1293 | "save function\n", |
| 1294 | t->u.user.name); |
| 1295 | exit(1); |
| 1296 | } |
| 1297 | } |
| 1298 | } |
| 1299 | printf("\n"); |
| 1300 | } |
| 1301 | |
| 1302 | static int |
| 1303 | list_rules(const ipt_chainlabel chain, int counters, |
| 1304 | iptc_handle_t *handle) |
| 1305 | { |
| 1306 | const char *this = NULL; |
| 1307 | int found = 0; |
| 1308 | |
| 1309 | if (counters) |
| 1310 | counters = -1; /* iptables -c format */ |
| 1311 | |
| 1312 | /* Dump out chain names first, |
| 1313 | * thereby preventing dependency conflicts */ |
| 1314 | for (this = iptc_first_chain(handle); |
| 1315 | this; |
| 1316 | this = iptc_next_chain(handle)) { |
| 1317 | if (chain && strcmp(this, chain) != 0) |
| 1318 | continue; |
| 1319 | |
| 1320 | if (iptc_builtin(this, *handle)) { |
| 1321 | struct ipt_counters count; |
| 1322 | printf("-P %s %s", this, iptc_get_policy(this, &count, handle)); |
| 1323 | if (counters) |
| 1324 | printf(" -c %llu %llu", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt); |
| 1325 | printf("\n"); |
| 1326 | } else { |
| 1327 | printf("-N %s\n", this); |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | for (this = iptc_first_chain(handle); |
| 1332 | this; |
| 1333 | this = iptc_next_chain(handle)) { |
| 1334 | const struct ipt_entry *e; |
| 1335 | |
| 1336 | if (chain && strcmp(this, chain) != 0) |
| 1337 | continue; |
| 1338 | |
| 1339 | /* Dump out rules */ |
| 1340 | e = iptc_first_rule(this, handle); |
| 1341 | while(e) { |
| 1342 | print_rule(e, handle, this, counters); |
| 1343 | e = iptc_next_rule(e, handle); |
| 1344 | } |
| 1345 | found = 1; |
| 1346 | } |
| 1347 | |
| 1348 | errno = ENOENT; |
| 1349 | return found; |
| 1350 | } |
| 1351 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1352 | static struct ipt_entry * |
| 1353 | generate_entry(const struct ipt_entry *fw, |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1354 | struct iptables_rule_match *matches, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1355 | struct ipt_entry_target *target) |
| 1356 | { |
| 1357 | unsigned int size; |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1358 | struct iptables_rule_match *matchp; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1359 | struct ipt_entry *e; |
| 1360 | |
| 1361 | size = sizeof(struct ipt_entry); |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1362 | for (matchp = matches; matchp; matchp = matchp->next) |
| 1363 | size += matchp->match->m->u.match_size; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1364 | |
Rusty Russell | 228e98d | 2000-04-27 10:28:06 +0000 | [diff] [blame] | 1365 | e = fw_malloc(size + target->u.target_size); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1366 | *e = *fw; |
| 1367 | e->target_offset = size; |
Rusty Russell | 228e98d | 2000-04-27 10:28:06 +0000 | [diff] [blame] | 1368 | e->next_offset = size + target->u.target_size; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1369 | |
| 1370 | size = 0; |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1371 | for (matchp = matches; matchp; matchp = matchp->next) { |
| 1372 | memcpy(e->elems + size, matchp->match->m, matchp->match->m->u.match_size); |
| 1373 | size += matchp->match->m->u.match_size; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1374 | } |
Rusty Russell | 228e98d | 2000-04-27 10:28:06 +0000 | [diff] [blame] | 1375 | memcpy(e->elems + size, target, target->u.target_size); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1376 | |
| 1377 | return e; |
| 1378 | } |
| 1379 | |
Jan Engelhardt | 33690a1 | 2008-02-11 00:54:00 +0100 | [diff] [blame] | 1380 | static void clear_rule_matches(struct iptables_rule_match **matches) |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1381 | { |
| 1382 | struct iptables_rule_match *matchp, *tmp; |
| 1383 | |
| 1384 | for (matchp = *matches; matchp;) { |
| 1385 | tmp = matchp->next; |
Harald Welte | d6bc608 | 2006-02-11 09:34:16 +0000 | [diff] [blame] | 1386 | if (matchp->match->m) { |
Martin Josefsson | 4dd5fed | 2004-05-18 18:09:43 +0000 | [diff] [blame] | 1387 | free(matchp->match->m); |
Harald Welte | d6bc608 | 2006-02-11 09:34:16 +0000 | [diff] [blame] | 1388 | matchp->match->m = NULL; |
| 1389 | } |
Joszef Kadlecsik | a258ad7 | 2006-03-03 09:36:50 +0000 | [diff] [blame] | 1390 | if (matchp->match == matchp->match->next) { |
| 1391 | free(matchp->match); |
| 1392 | matchp->match = NULL; |
| 1393 | } |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1394 | free(matchp); |
| 1395 | matchp = tmp; |
| 1396 | } |
| 1397 | |
| 1398 | *matches = NULL; |
| 1399 | } |
| 1400 | |
Rusty Russell | 3aef54d | 2005-01-03 03:48:40 +0000 | [diff] [blame] | 1401 | static void set_revision(char *name, u_int8_t revision) |
| 1402 | { |
| 1403 | /* Old kernel sources don't have ".revision" field, |
| 1404 | but we stole a byte from name. */ |
| 1405 | name[IPT_FUNCTION_MAXNAMELEN - 2] = '\0'; |
| 1406 | name[IPT_FUNCTION_MAXNAMELEN - 1] = revision; |
| 1407 | } |
| 1408 | |
Phil Oester | 8cf6591 | 2005-09-19 15:00:33 +0000 | [diff] [blame] | 1409 | void |
| 1410 | get_kernel_version(void) { |
| 1411 | static struct utsname uts; |
| 1412 | int x = 0, y = 0, z = 0; |
| 1413 | |
| 1414 | if (uname(&uts) == -1) { |
| 1415 | fprintf(stderr, "Unable to retrieve kernel version.\n"); |
| 1416 | free_opts(1); |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1417 | exit(1); |
Phil Oester | 8cf6591 | 2005-09-19 15:00:33 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | sscanf(uts.release, "%d.%d.%d", &x, &y, &z); |
| 1421 | kernel_version = LINUX_VERSION(x, y, z); |
| 1422 | } |
| 1423 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1424 | int do_command(int argc, char *argv[], char **table, iptc_handle_t *handle) |
| 1425 | { |
| 1426 | struct ipt_entry fw, *e = NULL; |
| 1427 | int invert = 0; |
| 1428 | unsigned int nsaddrs = 0, ndaddrs = 0; |
| 1429 | struct in_addr *saddrs = NULL, *daddrs = NULL; |
| 1430 | |
| 1431 | int c, verbose = 0; |
| 1432 | const char *chain = NULL; |
| 1433 | const char *shostnetworkmask = NULL, *dhostnetworkmask = NULL; |
| 1434 | const char *policy = NULL, *newname = NULL; |
| 1435 | unsigned int rulenum = 0, options = 0, command = 0; |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 1436 | const char *pcnt = NULL, *bcnt = NULL; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1437 | int ret = 1; |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 1438 | struct xtables_match *m; |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1439 | struct iptables_rule_match *matches = NULL; |
| 1440 | struct iptables_rule_match *matchp; |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 1441 | struct xtables_target *target = NULL; |
| 1442 | struct xtables_target *t; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1443 | const char *jumpto = ""; |
| 1444 | char *protocol = NULL; |
Harald Welte | 2d86b77 | 2002-08-26 12:21:44 +0000 | [diff] [blame] | 1445 | int proto_used = 0; |
Patrick McHardy | 875441e | 2007-10-17 08:48:58 +0000 | [diff] [blame] | 1446 | unsigned long long cnt; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1447 | |
| 1448 | memset(&fw, 0, sizeof(fw)); |
| 1449 | |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 1450 | /* re-set optind to 0 in case do_command gets called |
| 1451 | * a second time */ |
| 1452 | optind = 0; |
| 1453 | |
| 1454 | /* clear mflags in case do_command gets called a second time |
| 1455 | * (we clear the global list of all matches for security)*/ |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 1456 | for (m = xtables_matches; m; m = m->next) |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 1457 | m->mflags = 0; |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 1458 | |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 1459 | for (t = xtables_targets; t; t = t->next) { |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 1460 | t->tflags = 0; |
| 1461 | t->used = 0; |
| 1462 | } |
| 1463 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1464 | /* Suppress error messages: we may add new options if we |
| 1465 | demand-load a protocol. */ |
| 1466 | opterr = 0; |
| 1467 | |
| 1468 | while ((c = getopt_long(argc, argv, |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 1469 | "-A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:fbvnt:m:xc:g:", |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1470 | opts, NULL)) != -1) { |
| 1471 | switch (c) { |
| 1472 | /* |
| 1473 | * Command selection |
| 1474 | */ |
| 1475 | case 'A': |
| 1476 | add_command(&command, CMD_APPEND, CMD_NONE, |
| 1477 | invert); |
| 1478 | chain = optarg; |
| 1479 | break; |
| 1480 | |
| 1481 | case 'D': |
| 1482 | add_command(&command, CMD_DELETE, CMD_NONE, |
| 1483 | invert); |
| 1484 | chain = optarg; |
| 1485 | if (optind < argc && argv[optind][0] != '-' |
| 1486 | && argv[optind][0] != '!') { |
| 1487 | rulenum = parse_rulenumber(argv[optind++]); |
| 1488 | command = CMD_DELETE_NUM; |
| 1489 | } |
| 1490 | break; |
| 1491 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1492 | case 'R': |
| 1493 | add_command(&command, CMD_REPLACE, CMD_NONE, |
| 1494 | invert); |
| 1495 | chain = optarg; |
| 1496 | if (optind < argc && argv[optind][0] != '-' |
| 1497 | && argv[optind][0] != '!') |
| 1498 | rulenum = parse_rulenumber(argv[optind++]); |
| 1499 | else |
| 1500 | exit_error(PARAMETER_PROBLEM, |
| 1501 | "-%c requires a rule number", |
| 1502 | cmd2char(CMD_REPLACE)); |
| 1503 | break; |
| 1504 | |
| 1505 | case 'I': |
| 1506 | add_command(&command, CMD_INSERT, CMD_NONE, |
| 1507 | invert); |
| 1508 | chain = optarg; |
| 1509 | if (optind < argc && argv[optind][0] != '-' |
| 1510 | && argv[optind][0] != '!') |
| 1511 | rulenum = parse_rulenumber(argv[optind++]); |
| 1512 | else rulenum = 1; |
| 1513 | break; |
| 1514 | |
| 1515 | case 'L': |
| 1516 | add_command(&command, CMD_LIST, CMD_ZERO, |
| 1517 | invert); |
| 1518 | if (optarg) chain = optarg; |
| 1519 | else if (optind < argc && argv[optind][0] != '-' |
| 1520 | && argv[optind][0] != '!') |
| 1521 | chain = argv[optind++]; |
| 1522 | break; |
| 1523 | |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 1524 | case 'S': |
| 1525 | add_command(&command, CMD_LIST_RULES, CMD_ZERO, |
| 1526 | invert); |
| 1527 | if (optarg) chain = optarg; |
| 1528 | else if (optind < argc && argv[optind][0] != '-' |
| 1529 | && argv[optind][0] != '!') |
| 1530 | chain = argv[optind++]; |
| 1531 | break; |
| 1532 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1533 | case 'F': |
| 1534 | add_command(&command, CMD_FLUSH, CMD_NONE, |
| 1535 | invert); |
| 1536 | if (optarg) chain = optarg; |
| 1537 | else if (optind < argc && argv[optind][0] != '-' |
| 1538 | && argv[optind][0] != '!') |
| 1539 | chain = argv[optind++]; |
| 1540 | break; |
| 1541 | |
| 1542 | case 'Z': |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 1543 | add_command(&command, CMD_ZERO, CMD_LIST|CMD_LIST_RULES, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1544 | invert); |
| 1545 | if (optarg) chain = optarg; |
| 1546 | else if (optind < argc && argv[optind][0] != '-' |
| 1547 | && argv[optind][0] != '!') |
| 1548 | chain = argv[optind++]; |
| 1549 | break; |
| 1550 | |
| 1551 | case 'N': |
Yasuyuki KOZAKAI | 8d8c8ea | 2005-06-13 01:06:10 +0000 | [diff] [blame] | 1552 | if (optarg && (*optarg == '-' || *optarg == '!')) |
Harald Welte | 6336bfd | 2002-05-07 14:41:43 +0000 | [diff] [blame] | 1553 | exit_error(PARAMETER_PROBLEM, |
| 1554 | "chain name not allowed to start " |
Yasuyuki KOZAKAI | 8d8c8ea | 2005-06-13 01:06:10 +0000 | [diff] [blame] | 1555 | "with `%c'\n", *optarg); |
Joszef Kadlecsik | 08f1527 | 2002-06-24 12:37:29 +0000 | [diff] [blame] | 1556 | if (find_target(optarg, TRY_LOAD)) |
| 1557 | exit_error(PARAMETER_PROBLEM, |
| 1558 | "chain name may not clash " |
| 1559 | "with target name\n"); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1560 | add_command(&command, CMD_NEW_CHAIN, CMD_NONE, |
| 1561 | invert); |
| 1562 | chain = optarg; |
| 1563 | break; |
| 1564 | |
| 1565 | case 'X': |
| 1566 | add_command(&command, CMD_DELETE_CHAIN, CMD_NONE, |
| 1567 | invert); |
| 1568 | if (optarg) chain = optarg; |
| 1569 | else if (optind < argc && argv[optind][0] != '-' |
| 1570 | && argv[optind][0] != '!') |
| 1571 | chain = argv[optind++]; |
| 1572 | break; |
| 1573 | |
| 1574 | case 'E': |
| 1575 | add_command(&command, CMD_RENAME_CHAIN, CMD_NONE, |
| 1576 | invert); |
| 1577 | chain = optarg; |
| 1578 | if (optind < argc && argv[optind][0] != '-' |
| 1579 | && argv[optind][0] != '!') |
| 1580 | newname = argv[optind++]; |
M.P.Anand Babu | c9f20d3 | 2000-06-09 09:22:38 +0000 | [diff] [blame] | 1581 | else |
| 1582 | exit_error(PARAMETER_PROBLEM, |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1583 | "-%c requires old-chain-name and " |
M.P.Anand Babu | c9f20d3 | 2000-06-09 09:22:38 +0000 | [diff] [blame] | 1584 | "new-chain-name", |
| 1585 | cmd2char(CMD_RENAME_CHAIN)); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1586 | break; |
| 1587 | |
| 1588 | case 'P': |
| 1589 | add_command(&command, CMD_SET_POLICY, CMD_NONE, |
| 1590 | invert); |
| 1591 | chain = optarg; |
| 1592 | if (optind < argc && argv[optind][0] != '-' |
| 1593 | && argv[optind][0] != '!') |
| 1594 | policy = argv[optind++]; |
| 1595 | else |
| 1596 | exit_error(PARAMETER_PROBLEM, |
| 1597 | "-%c requires a chain and a policy", |
| 1598 | cmd2char(CMD_SET_POLICY)); |
| 1599 | break; |
| 1600 | |
| 1601 | case 'h': |
| 1602 | if (!optarg) |
| 1603 | optarg = argv[optind]; |
| 1604 | |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 1605 | /* iptables -p icmp -h */ |
Martin Josefsson | 66aea6f | 2004-05-26 15:41:54 +0000 | [diff] [blame] | 1606 | if (!matches && protocol) |
| 1607 | find_match(protocol, TRY_LOAD, &matches); |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 1608 | |
Martin Josefsson | 66aea6f | 2004-05-26 15:41:54 +0000 | [diff] [blame] | 1609 | exit_printhelp(matches); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1610 | |
| 1611 | /* |
| 1612 | * Option selection |
| 1613 | */ |
| 1614 | case 'p': |
Harald Welte | b77f1da | 2002-03-14 11:35:58 +0000 | [diff] [blame] | 1615 | check_inverse(optarg, &invert, &optind, argc); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1616 | set_option(&options, OPT_PROTOCOL, &fw.ip.invflags, |
| 1617 | invert); |
| 1618 | |
| 1619 | /* Canonicalize into lower case */ |
| 1620 | for (protocol = argv[optind-1]; *protocol; protocol++) |
| 1621 | *protocol = tolower(*protocol); |
| 1622 | |
| 1623 | protocol = argv[optind-1]; |
| 1624 | fw.ip.proto = parse_protocol(protocol); |
| 1625 | |
| 1626 | if (fw.ip.proto == 0 |
| 1627 | && (fw.ip.invflags & IPT_INV_PROTO)) |
| 1628 | exit_error(PARAMETER_PROBLEM, |
| 1629 | "rule would never match protocol"); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1630 | break; |
| 1631 | |
| 1632 | case 's': |
Harald Welte | b77f1da | 2002-03-14 11:35:58 +0000 | [diff] [blame] | 1633 | check_inverse(optarg, &invert, &optind, argc); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1634 | set_option(&options, OPT_SOURCE, &fw.ip.invflags, |
| 1635 | invert); |
| 1636 | shostnetworkmask = argv[optind-1]; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1637 | break; |
| 1638 | |
| 1639 | case 'd': |
Harald Welte | b77f1da | 2002-03-14 11:35:58 +0000 | [diff] [blame] | 1640 | check_inverse(optarg, &invert, &optind, argc); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1641 | set_option(&options, OPT_DESTINATION, &fw.ip.invflags, |
| 1642 | invert); |
| 1643 | dhostnetworkmask = argv[optind-1]; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1644 | break; |
| 1645 | |
Henrik Nordstrom | 17fc163 | 2005-11-05 09:26:40 +0000 | [diff] [blame] | 1646 | #ifdef IPT_F_GOTO |
| 1647 | case 'g': |
| 1648 | set_option(&options, OPT_JUMP, &fw.ip.invflags, |
| 1649 | invert); |
| 1650 | fw.ip.flags |= IPT_F_GOTO; |
| 1651 | jumpto = parse_target(optarg); |
| 1652 | break; |
| 1653 | #endif |
| 1654 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1655 | case 'j': |
| 1656 | set_option(&options, OPT_JUMP, &fw.ip.invflags, |
| 1657 | invert); |
| 1658 | jumpto = parse_target(optarg); |
Rusty Russell | 859f726 | 2000-08-24 06:00:33 +0000 | [diff] [blame] | 1659 | /* TRY_LOAD (may be chain name) */ |
| 1660 | target = find_target(jumpto, TRY_LOAD); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1661 | |
| 1662 | if (target) { |
Rusty Russell | 228e98d | 2000-04-27 10:28:06 +0000 | [diff] [blame] | 1663 | size_t size; |
| 1664 | |
Rusty Russell | 73f72f5 | 2000-07-03 10:17:57 +0000 | [diff] [blame] | 1665 | size = IPT_ALIGN(sizeof(struct ipt_entry_target)) |
| 1666 | + target->size; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1667 | |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 1668 | target->t = fw_calloc(1, size); |
Rusty Russell | 228e98d | 2000-04-27 10:28:06 +0000 | [diff] [blame] | 1669 | target->t->u.target_size = size; |
| 1670 | strcpy(target->t->u.user.name, jumpto); |
Rusty Russell | 3aef54d | 2005-01-03 03:48:40 +0000 | [diff] [blame] | 1671 | set_revision(target->t->u.user.name, |
| 1672 | target->revision); |
Pablo Neira | 8115e54 | 2005-02-14 13:13:04 +0000 | [diff] [blame] | 1673 | if (target->init != NULL) |
Peter Riley | ea146a9 | 2007-09-02 13:09:07 +0000 | [diff] [blame] | 1674 | target->init(target->t); |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1675 | opts = merge_options(opts, |
| 1676 | target->extra_opts, |
Pablo Neira Ayuso | 8e707d7 | 2008-01-17 17:30:27 +0000 | [diff] [blame] | 1677 | &target->option_offset); |
| 1678 | if (opts == NULL) |
| 1679 | exit_error(OTHER_PROBLEM, |
| 1680 | "can't alloc memory!"); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1681 | } |
| 1682 | break; |
| 1683 | |
| 1684 | |
| 1685 | case 'i': |
Harald Welte | b77f1da | 2002-03-14 11:35:58 +0000 | [diff] [blame] | 1686 | check_inverse(optarg, &invert, &optind, argc); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1687 | set_option(&options, OPT_VIANAMEIN, &fw.ip.invflags, |
| 1688 | invert); |
| 1689 | parse_interface(argv[optind-1], |
| 1690 | fw.ip.iniface, |
| 1691 | fw.ip.iniface_mask); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1692 | break; |
| 1693 | |
| 1694 | case 'o': |
Harald Welte | b77f1da | 2002-03-14 11:35:58 +0000 | [diff] [blame] | 1695 | check_inverse(optarg, &invert, &optind, argc); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1696 | set_option(&options, OPT_VIANAMEOUT, &fw.ip.invflags, |
| 1697 | invert); |
| 1698 | parse_interface(argv[optind-1], |
| 1699 | fw.ip.outiface, |
| 1700 | fw.ip.outiface_mask); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1701 | break; |
| 1702 | |
| 1703 | case 'f': |
| 1704 | set_option(&options, OPT_FRAGMENT, &fw.ip.invflags, |
| 1705 | invert); |
| 1706 | fw.ip.flags |= IPT_F_FRAG; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1707 | break; |
| 1708 | |
| 1709 | case 'v': |
| 1710 | if (!verbose) |
| 1711 | set_option(&options, OPT_VERBOSE, |
| 1712 | &fw.ip.invflags, invert); |
| 1713 | verbose++; |
| 1714 | break; |
| 1715 | |
Rusty Russell | 52a5149 | 2000-05-02 16:44:29 +0000 | [diff] [blame] | 1716 | case 'm': { |
| 1717 | size_t size; |
| 1718 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1719 | if (invert) |
| 1720 | exit_error(PARAMETER_PROBLEM, |
| 1721 | "unexpected ! flag before --match"); |
| 1722 | |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1723 | m = find_match(optarg, LOAD_MUST_SUCCEED, &matches); |
Rusty Russell | 73f72f5 | 2000-07-03 10:17:57 +0000 | [diff] [blame] | 1724 | size = IPT_ALIGN(sizeof(struct ipt_entry_match)) |
| 1725 | + m->size; |
Rusty Russell | 52a5149 | 2000-05-02 16:44:29 +0000 | [diff] [blame] | 1726 | m->m = fw_calloc(1, size); |
| 1727 | m->m->u.match_size = size; |
Rusty Russell | 27ff347 | 2000-05-12 14:04:50 +0000 | [diff] [blame] | 1728 | strcpy(m->m->u.user.name, m->name); |
Rusty Russell | 3aef54d | 2005-01-03 03:48:40 +0000 | [diff] [blame] | 1729 | set_revision(m->m->u.user.name, m->revision); |
Pablo Neira | 8115e54 | 2005-02-14 13:13:04 +0000 | [diff] [blame] | 1730 | if (m->init != NULL) |
Peter Riley | ea146a9 | 2007-09-02 13:09:07 +0000 | [diff] [blame] | 1731 | m->init(m->m); |
Pablo Neira Ayuso | 8e707d7 | 2008-01-17 17:30:27 +0000 | [diff] [blame] | 1732 | if (m != m->next) { |
Joszef Kadlecsik | a258ad7 | 2006-03-03 09:36:50 +0000 | [diff] [blame] | 1733 | /* Merge options for non-cloned matches */ |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1734 | opts = merge_options(opts, |
| 1735 | m->extra_opts, |
Pablo Neira Ayuso | 8e707d7 | 2008-01-17 17:30:27 +0000 | [diff] [blame] | 1736 | &m->option_offset); |
| 1737 | if (opts == NULL) |
| 1738 | exit_error(OTHER_PROBLEM, |
| 1739 | "can't alloc memory!"); |
| 1740 | } |
Rusty Russell | 52a5149 | 2000-05-02 16:44:29 +0000 | [diff] [blame] | 1741 | } |
| 1742 | break; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1743 | |
| 1744 | case 'n': |
| 1745 | set_option(&options, OPT_NUMERIC, &fw.ip.invflags, |
| 1746 | invert); |
| 1747 | break; |
| 1748 | |
| 1749 | case 't': |
| 1750 | if (invert) |
| 1751 | exit_error(PARAMETER_PROBLEM, |
| 1752 | "unexpected ! flag before --table"); |
| 1753 | *table = argv[optind-1]; |
| 1754 | break; |
| 1755 | |
| 1756 | case 'x': |
| 1757 | set_option(&options, OPT_EXPANDED, &fw.ip.invflags, |
| 1758 | invert); |
| 1759 | break; |
| 1760 | |
| 1761 | case 'V': |
| 1762 | if (invert) |
| 1763 | printf("Not %s ;-)\n", program_version); |
| 1764 | else |
| 1765 | printf("%s v%s\n", |
| 1766 | program_name, program_version); |
| 1767 | exit(0); |
| 1768 | |
| 1769 | case '0': |
| 1770 | set_option(&options, OPT_LINENUMBERS, &fw.ip.invflags, |
| 1771 | invert); |
| 1772 | break; |
| 1773 | |
Harald Welte | 82dd2ec | 2000-12-19 05:18:15 +0000 | [diff] [blame] | 1774 | case 'M': |
Jan Engelhardt | dbb7754 | 2008-02-11 00:33:30 +0100 | [diff] [blame] | 1775 | modprobe_program = optarg; |
Harald Welte | 82dd2ec | 2000-12-19 05:18:15 +0000 | [diff] [blame] | 1776 | break; |
| 1777 | |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 1778 | case 'c': |
| 1779 | |
| 1780 | set_option(&options, OPT_COUNTERS, &fw.ip.invflags, |
| 1781 | invert); |
| 1782 | pcnt = optarg; |
| 1783 | if (optind < argc && argv[optind][0] != '-' |
| 1784 | && argv[optind][0] != '!') |
| 1785 | bcnt = argv[optind++]; |
| 1786 | else |
| 1787 | exit_error(PARAMETER_PROBLEM, |
| 1788 | "-%c requires packet and byte counter", |
| 1789 | opt2char(OPT_COUNTERS)); |
| 1790 | |
Patrick McHardy | 875441e | 2007-10-17 08:48:58 +0000 | [diff] [blame] | 1791 | if (sscanf(pcnt, "%llu", (unsigned long long *)&cnt) != 1) |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 1792 | exit_error(PARAMETER_PROBLEM, |
| 1793 | "-%c packet counter not numeric", |
| 1794 | opt2char(OPT_COUNTERS)); |
Patrick McHardy | 875441e | 2007-10-17 08:48:58 +0000 | [diff] [blame] | 1795 | fw.counters.pcnt = cnt; |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 1796 | |
Patrick McHardy | 875441e | 2007-10-17 08:48:58 +0000 | [diff] [blame] | 1797 | if (sscanf(bcnt, "%llu", (unsigned long long *)&cnt) != 1) |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 1798 | exit_error(PARAMETER_PROBLEM, |
| 1799 | "-%c byte counter not numeric", |
| 1800 | opt2char(OPT_COUNTERS)); |
Patrick McHardy | 875441e | 2007-10-17 08:48:58 +0000 | [diff] [blame] | 1801 | fw.counters.bcnt = cnt; |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 1802 | break; |
| 1803 | |
| 1804 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1805 | case 1: /* non option */ |
| 1806 | if (optarg[0] == '!' && optarg[1] == '\0') { |
| 1807 | if (invert) |
| 1808 | exit_error(PARAMETER_PROBLEM, |
| 1809 | "multiple consecutive ! not" |
| 1810 | " allowed"); |
| 1811 | invert = TRUE; |
| 1812 | optarg[0] = '\0'; |
| 1813 | continue; |
| 1814 | } |
Max Kellermann | aae4f82 | 2007-10-17 16:36:49 +0000 | [diff] [blame] | 1815 | fprintf(stderr, "Bad argument `%s'\n", optarg); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1816 | exit_tryhelp(2); |
| 1817 | |
| 1818 | default: |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1819 | if (!target |
| 1820 | || !(target->parse(c - target->option_offset, |
| 1821 | argv, invert, |
| 1822 | &target->tflags, |
| 1823 | &fw, &target->t))) { |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1824 | for (matchp = matches; matchp; matchp = matchp->next) { |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1825 | if (matchp->completed) |
Joszef Kadlecsik | a258ad7 | 2006-03-03 09:36:50 +0000 | [diff] [blame] | 1826 | continue; |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1827 | if (matchp->match->parse(c - matchp->match->option_offset, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1828 | argv, invert, |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1829 | &matchp->match->mflags, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1830 | &fw, |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1831 | &matchp->match->m)) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1832 | break; |
| 1833 | } |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1834 | m = matchp ? matchp->match : NULL; |
Harald Welte | 2d86b77 | 2002-08-26 12:21:44 +0000 | [diff] [blame] | 1835 | |
| 1836 | /* If you listen carefully, you can |
| 1837 | actually hear this code suck. */ |
| 1838 | |
| 1839 | /* some explanations (after four different bugs |
Joszef Kadlecsik | a258ad7 | 2006-03-03 09:36:50 +0000 | [diff] [blame] | 1840 | * in 3 different releases): If we encounter a |
Harald Welte | 2d86b77 | 2002-08-26 12:21:44 +0000 | [diff] [blame] | 1841 | * parameter, that has not been parsed yet, |
| 1842 | * it's not an option of an explicitly loaded |
| 1843 | * match or a target. However, we support |
| 1844 | * implicit loading of the protocol match |
| 1845 | * extension. '-p tcp' means 'l4 proto 6' and |
| 1846 | * at the same time 'load tcp protocol match on |
| 1847 | * demand if we specify --dport'. |
| 1848 | * |
| 1849 | * To make this work, we need to make sure: |
| 1850 | * - the parameter has not been parsed by |
| 1851 | * a match (m above) |
| 1852 | * - a protocol has been specified |
| 1853 | * - the protocol extension has not been |
| 1854 | * loaded yet, or is loaded and unused |
| 1855 | * [think of iptables-restore!] |
| 1856 | * - the protocol extension can be successively |
| 1857 | * loaded |
| 1858 | */ |
| 1859 | if (m == NULL |
| 1860 | && protocol |
| 1861 | && (!find_proto(protocol, DONT_LOAD, |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1862 | options&OPT_NUMERIC, NULL) |
Harald Welte | 2d86b77 | 2002-08-26 12:21:44 +0000 | [diff] [blame] | 1863 | || (find_proto(protocol, DONT_LOAD, |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1864 | options&OPT_NUMERIC, NULL) |
Harald Welte | 2d86b77 | 2002-08-26 12:21:44 +0000 | [diff] [blame] | 1865 | && (proto_used == 0)) |
| 1866 | ) |
| 1867 | && (m = find_proto(protocol, TRY_LOAD, |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1868 | options&OPT_NUMERIC, &matches))) { |
Harald Welte | 2d86b77 | 2002-08-26 12:21:44 +0000 | [diff] [blame] | 1869 | /* Try loading protocol */ |
| 1870 | size_t size; |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1871 | |
Harald Welte | 2d86b77 | 2002-08-26 12:21:44 +0000 | [diff] [blame] | 1872 | proto_used = 1; |
| 1873 | |
| 1874 | size = IPT_ALIGN(sizeof(struct ipt_entry_match)) |
| 1875 | + m->size; |
| 1876 | |
| 1877 | m->m = fw_calloc(1, size); |
| 1878 | m->m->u.match_size = size; |
| 1879 | strcpy(m->m->u.user.name, m->name); |
Rusty Russell | 3aef54d | 2005-01-03 03:48:40 +0000 | [diff] [blame] | 1880 | set_revision(m->m->u.user.name, |
| 1881 | m->revision); |
Pablo Neira | 8115e54 | 2005-02-14 13:13:04 +0000 | [diff] [blame] | 1882 | if (m->init != NULL) |
Peter Riley | ea146a9 | 2007-09-02 13:09:07 +0000 | [diff] [blame] | 1883 | m->init(m->m); |
Harald Welte | 2d86b77 | 2002-08-26 12:21:44 +0000 | [diff] [blame] | 1884 | |
| 1885 | opts = merge_options(opts, |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1886 | m->extra_opts, |
Pablo Neira Ayuso | 8e707d7 | 2008-01-17 17:30:27 +0000 | [diff] [blame] | 1887 | &m->option_offset); |
| 1888 | if (opts == NULL) |
| 1889 | exit_error(OTHER_PROBLEM, |
| 1890 | "can't alloc memory!"); |
Harald Welte | 2d86b77 | 2002-08-26 12:21:44 +0000 | [diff] [blame] | 1891 | |
| 1892 | optind--; |
| 1893 | continue; |
| 1894 | } |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1895 | if (!m) |
| 1896 | exit_error(PARAMETER_PROBLEM, |
| 1897 | "Unknown arg `%s'", |
| 1898 | argv[optind-1]); |
| 1899 | } |
| 1900 | } |
| 1901 | invert = FALSE; |
| 1902 | } |
| 1903 | |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 1904 | for (matchp = matches; matchp; matchp = matchp->next) |
Jan Engelhardt | 830132a | 2007-10-04 16:24:50 +0000 | [diff] [blame] | 1905 | if (matchp->match->final_check != NULL) |
| 1906 | matchp->match->final_check(matchp->match->mflags); |
Sven Koch | fb1279a | 2001-02-27 12:25:12 +0000 | [diff] [blame] | 1907 | |
Jan Engelhardt | 830132a | 2007-10-04 16:24:50 +0000 | [diff] [blame] | 1908 | if (target != NULL && target->final_check != NULL) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1909 | target->final_check(target->tflags); |
| 1910 | |
| 1911 | /* Fix me: must put inverse options checking here --MN */ |
| 1912 | |
| 1913 | if (optind < argc) |
| 1914 | exit_error(PARAMETER_PROBLEM, |
| 1915 | "unknown arguments found on commandline"); |
| 1916 | if (!command) |
| 1917 | exit_error(PARAMETER_PROBLEM, "no command specified"); |
| 1918 | if (invert) |
| 1919 | exit_error(PARAMETER_PROBLEM, |
| 1920 | "nothing appropriate following !"); |
| 1921 | |
Harald Welte | 6336bfd | 2002-05-07 14:41:43 +0000 | [diff] [blame] | 1922 | if (command & (CMD_REPLACE | CMD_INSERT | CMD_DELETE | CMD_APPEND)) { |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1923 | if (!(options & OPT_DESTINATION)) |
| 1924 | dhostnetworkmask = "0.0.0.0/0"; |
| 1925 | if (!(options & OPT_SOURCE)) |
| 1926 | shostnetworkmask = "0.0.0.0/0"; |
| 1927 | } |
| 1928 | |
| 1929 | if (shostnetworkmask) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1930 | ipparse_hostnetworkmask(shostnetworkmask, &saddrs, |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1931 | &fw.ip.smsk, &nsaddrs); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1932 | |
| 1933 | if (dhostnetworkmask) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1934 | ipparse_hostnetworkmask(dhostnetworkmask, &daddrs, |
Max Kellermann | 5b76f68 | 2008-01-29 13:42:48 +0000 | [diff] [blame] | 1935 | &fw.ip.dmsk, &ndaddrs); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1936 | |
| 1937 | if ((nsaddrs > 1 || ndaddrs > 1) && |
| 1938 | (fw.ip.invflags & (IPT_INV_SRCIP | IPT_INV_DSTIP))) |
| 1939 | exit_error(PARAMETER_PROBLEM, "! not allowed with multiple" |
| 1940 | " source or destination IP addresses"); |
| 1941 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1942 | if (command == CMD_REPLACE && (nsaddrs != 1 || ndaddrs != 1)) |
| 1943 | exit_error(PARAMETER_PROBLEM, "Replacement rule does not " |
| 1944 | "specify a unique address"); |
| 1945 | |
| 1946 | generic_opt_check(command, options); |
| 1947 | |
| 1948 | if (chain && strlen(chain) > IPT_FUNCTION_MAXNAMELEN) |
| 1949 | exit_error(PARAMETER_PROBLEM, |
| 1950 | "chain name `%s' too long (must be under %i chars)", |
| 1951 | chain, IPT_FUNCTION_MAXNAMELEN); |
| 1952 | |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 1953 | /* only allocate handle if we weren't called with a handle */ |
Martin Josefsson | 8371e15 | 2003-05-05 19:33:40 +0000 | [diff] [blame] | 1954 | if (!*handle) |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 1955 | *handle = iptc_init(*table); |
| 1956 | |
Rusty Russell | 8beb049 | 2004-12-22 00:37:10 +0000 | [diff] [blame] | 1957 | /* try to insmod the module if iptc_init failed */ |
Jan Engelhardt | dbb7754 | 2008-02-11 00:33:30 +0100 | [diff] [blame] | 1958 | if (!*handle && load_xtables_ko(modprobe_program, 0) != -1) |
Harald Welte | 82dd2ec | 2000-12-19 05:18:15 +0000 | [diff] [blame] | 1959 | *handle = iptc_init(*table); |
Harald Welte | 82dd2ec | 2000-12-19 05:18:15 +0000 | [diff] [blame] | 1960 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1961 | if (!*handle) |
| 1962 | exit_error(VERSION_PROBLEM, |
| 1963 | "can't initialize iptables table `%s': %s", |
| 1964 | *table, iptc_strerror(errno)); |
| 1965 | |
Harald Welte | 6336bfd | 2002-05-07 14:41:43 +0000 | [diff] [blame] | 1966 | if (command == CMD_APPEND |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1967 | || command == CMD_DELETE |
| 1968 | || command == CMD_INSERT |
| 1969 | || command == CMD_REPLACE) { |
Rusty Russell | a4860fd | 2000-06-17 16:13:02 +0000 | [diff] [blame] | 1970 | if (strcmp(chain, "PREROUTING") == 0 |
| 1971 | || strcmp(chain, "INPUT") == 0) { |
| 1972 | /* -o not valid with incoming packets. */ |
| 1973 | if (options & OPT_VIANAMEOUT) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1974 | exit_error(PARAMETER_PROBLEM, |
| 1975 | "Can't use -%c with %s\n", |
| 1976 | opt2char(OPT_VIANAMEOUT), |
| 1977 | chain); |
| 1978 | } |
| 1979 | |
Rusty Russell | a4860fd | 2000-06-17 16:13:02 +0000 | [diff] [blame] | 1980 | if (strcmp(chain, "POSTROUTING") == 0 |
| 1981 | || strcmp(chain, "OUTPUT") == 0) { |
| 1982 | /* -i not valid with outgoing packets */ |
| 1983 | if (options & OPT_VIANAMEIN) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1984 | exit_error(PARAMETER_PROBLEM, |
| 1985 | "Can't use -%c with %s\n", |
| 1986 | opt2char(OPT_VIANAMEIN), |
| 1987 | chain); |
| 1988 | } |
| 1989 | |
| 1990 | if (target && iptc_is_chain(jumpto, *handle)) { |
Max Kellermann | aae4f82 | 2007-10-17 16:36:49 +0000 | [diff] [blame] | 1991 | fprintf(stderr, |
| 1992 | "Warning: using chain %s, not extension\n", |
| 1993 | jumpto); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1994 | |
Martin Josefsson | 4dd5fed | 2004-05-18 18:09:43 +0000 | [diff] [blame] | 1995 | if (target->t) |
| 1996 | free(target->t); |
| 1997 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1998 | target = NULL; |
| 1999 | } |
| 2000 | |
| 2001 | /* If they didn't specify a target, or it's a chain |
| 2002 | name, use standard. */ |
| 2003 | if (!target |
| 2004 | && (strlen(jumpto) == 0 |
| 2005 | || iptc_is_chain(jumpto, *handle))) { |
| 2006 | size_t size; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2007 | |
Rusty Russell | 52a5149 | 2000-05-02 16:44:29 +0000 | [diff] [blame] | 2008 | target = find_target(IPT_STANDARD_TARGET, |
| 2009 | LOAD_MUST_SUCCEED); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2010 | |
| 2011 | size = sizeof(struct ipt_entry_target) |
Rusty Russell | 228e98d | 2000-04-27 10:28:06 +0000 | [diff] [blame] | 2012 | + target->size; |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 2013 | target->t = fw_calloc(1, size); |
Rusty Russell | 228e98d | 2000-04-27 10:28:06 +0000 | [diff] [blame] | 2014 | target->t->u.target_size = size; |
| 2015 | strcpy(target->t->u.user.name, jumpto); |
Pablo Neira | 0b90564 | 2005-11-17 13:04:49 +0000 | [diff] [blame] | 2016 | if (!iptc_is_chain(jumpto, *handle)) |
| 2017 | set_revision(target->t->u.user.name, |
| 2018 | target->revision); |
Pablo Neira | 8115e54 | 2005-02-14 13:13:04 +0000 | [diff] [blame] | 2019 | if (target->init != NULL) |
Peter Riley | ea146a9 | 2007-09-02 13:09:07 +0000 | [diff] [blame] | 2020 | target->init(target->t); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Rusty Russell | 7e53bf9 | 2000-03-20 07:03:28 +0000 | [diff] [blame] | 2023 | if (!target) { |
Harald Welte | f2a24bd | 2000-08-30 02:11:18 +0000 | [diff] [blame] | 2024 | /* it is no chain, and we can't load a plugin. |
| 2025 | * We cannot know if the plugin is corrupt, non |
Rusty Russell | a4d3e1f | 2001-01-07 06:56:02 +0000 | [diff] [blame] | 2026 | * existant OR if the user just misspelled a |
Harald Welte | f2a24bd | 2000-08-30 02:11:18 +0000 | [diff] [blame] | 2027 | * chain. */ |
Henrik Nordstrom | 17fc163 | 2005-11-05 09:26:40 +0000 | [diff] [blame] | 2028 | #ifdef IPT_F_GOTO |
| 2029 | if (fw.ip.flags & IPT_F_GOTO) |
| 2030 | exit_error(PARAMETER_PROBLEM, |
| 2031 | "goto '%s' is not a chain\n", jumpto); |
| 2032 | #endif |
Harald Welte | f2a24bd | 2000-08-30 02:11:18 +0000 | [diff] [blame] | 2033 | find_target(jumpto, LOAD_MUST_SUCCEED); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2034 | } else { |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 2035 | e = generate_entry(&fw, matches, target->t); |
Martin Josefsson | 4dd5fed | 2004-05-18 18:09:43 +0000 | [diff] [blame] | 2036 | free(target->t); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | switch (command) { |
| 2041 | case CMD_APPEND: |
| 2042 | ret = append_entry(chain, e, |
| 2043 | nsaddrs, saddrs, ndaddrs, daddrs, |
| 2044 | options&OPT_VERBOSE, |
| 2045 | handle); |
| 2046 | break; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2047 | case CMD_DELETE: |
| 2048 | ret = delete_entry(chain, e, |
| 2049 | nsaddrs, saddrs, ndaddrs, daddrs, |
| 2050 | options&OPT_VERBOSE, |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 2051 | handle, matches); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2052 | break; |
| 2053 | case CMD_DELETE_NUM: |
| 2054 | ret = iptc_delete_num_entry(chain, rulenum - 1, handle); |
| 2055 | break; |
| 2056 | case CMD_REPLACE: |
| 2057 | ret = replace_entry(chain, e, rulenum - 1, |
| 2058 | saddrs, daddrs, options&OPT_VERBOSE, |
| 2059 | handle); |
| 2060 | break; |
| 2061 | case CMD_INSERT: |
| 2062 | ret = insert_entry(chain, e, rulenum - 1, |
| 2063 | nsaddrs, saddrs, ndaddrs, daddrs, |
| 2064 | options&OPT_VERBOSE, |
| 2065 | handle); |
| 2066 | break; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2067 | case CMD_FLUSH: |
| 2068 | ret = flush_entries(chain, options&OPT_VERBOSE, handle); |
| 2069 | break; |
| 2070 | case CMD_ZERO: |
| 2071 | ret = zero_entries(chain, options&OPT_VERBOSE, handle); |
| 2072 | break; |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 2073 | case CMD_LIST: |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2074 | case CMD_LIST|CMD_ZERO: |
| 2075 | ret = list_entries(chain, |
| 2076 | options&OPT_VERBOSE, |
| 2077 | options&OPT_NUMERIC, |
| 2078 | options&OPT_EXPANDED, |
| 2079 | options&OPT_LINENUMBERS, |
| 2080 | handle); |
Henrik Nordstrom | 96296cf | 2008-05-13 13:08:26 +0200 | [diff] [blame^] | 2081 | if (ret && (command & CMD_ZERO)) |
| 2082 | ret = zero_entries(chain, |
| 2083 | options&OPT_VERBOSE, handle); |
| 2084 | break; |
| 2085 | case CMD_LIST_RULES: |
| 2086 | case CMD_LIST_RULES|CMD_ZERO: |
| 2087 | ret = list_rules(chain, |
| 2088 | options&OPT_VERBOSE, |
| 2089 | handle); |
| 2090 | if (ret && (command & CMD_ZERO)) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2091 | ret = zero_entries(chain, |
| 2092 | options&OPT_VERBOSE, handle); |
| 2093 | break; |
| 2094 | case CMD_NEW_CHAIN: |
| 2095 | ret = iptc_create_chain(chain, handle); |
| 2096 | break; |
| 2097 | case CMD_DELETE_CHAIN: |
| 2098 | ret = delete_chain(chain, options&OPT_VERBOSE, handle); |
| 2099 | break; |
| 2100 | case CMD_RENAME_CHAIN: |
| 2101 | ret = iptc_rename_chain(chain, newname, handle); |
| 2102 | break; |
| 2103 | case CMD_SET_POLICY: |
Henrik Nordstrom | 48c1bc6 | 2008-05-12 20:53:16 +0200 | [diff] [blame] | 2104 | ret = iptc_set_policy(chain, policy, options&OPT_COUNTERS ? &fw.counters : NULL, handle); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2105 | break; |
| 2106 | default: |
| 2107 | /* We should never reach this... */ |
| 2108 | exit_tryhelp(2); |
| 2109 | } |
| 2110 | |
| 2111 | if (verbose > 1) |
| 2112 | dump_entries(*handle); |
| 2113 | |
Martin Josefsson | 78cafda | 2004-02-02 20:01:18 +0000 | [diff] [blame] | 2114 | clear_rule_matches(&matches); |
| 2115 | |
Martin Josefsson | 4dd5fed | 2004-05-18 18:09:43 +0000 | [diff] [blame] | 2116 | if (e != NULL) { |
| 2117 | free(e); |
| 2118 | e = NULL; |
| 2119 | } |
| 2120 | |
keso | 6997cdf | 2004-07-04 15:20:53 +0000 | [diff] [blame] | 2121 | free(saddrs); |
| 2122 | free(daddrs); |
Pablo Neira | dfdcd64 | 2005-05-29 19:05:23 +0000 | [diff] [blame] | 2123 | free_opts(1); |
Martin Josefsson | 4dd5fed | 2004-05-18 18:09:43 +0000 | [diff] [blame] | 2124 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2125 | return ret; |
| 2126 | } |