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