blob: 41d47e79375db93372c20e8868b73c1184333b8b [file] [log] [blame]
Harald Welteae1ff9f2000-12-01 14:26:20 +00001/* Code to restore the iptables state, from file by iptables-save.
Harald Welte10a907f2002-08-07 09:07:41 +00002 * (C) 2000-2002 by Harald Welte <laforge@gnumonks.org>
Harald Welteae1ff9f2000-12-01 14:26:20 +00003 * based on previous code from Rusty Russell <rusty@linuxcare.com.au>
4 *
Harald Welte10a907f2002-08-07 09:07:41 +00005 * This code is distributed under the terms of GNU GPL v2
Harald Welteccd49e52001-01-23 22:54:34 +00006 *
Martin Josefsson357d59d2004-12-27 19:49:28 +00007 * $Id$
Harald Welteae1ff9f2000-12-01 14:26:20 +00008 */
9
Marc Bouchere6869a82000-03-20 06:03:29 +000010#include <getopt.h>
11#include <sys/errno.h>
12#include <string.h>
13#include <stdio.h>
Harald Welteae1ff9f2000-12-01 14:26:20 +000014#include <stdlib.h>
15#include "iptables.h"
Yasuyuki KOZAKAI0b82e8e2007-07-24 05:47:40 +000016#include "xtables.h"
Harald Welteae1ff9f2000-12-01 14:26:20 +000017#include "libiptc/libiptc.h"
18
19#ifdef DEBUG
Harald Weltec45c3152000-12-06 08:11:24 +000020#define DEBUGP(x, args...) fprintf(stderr, x, ## args)
Harald Welteae1ff9f2000-12-01 14:26:20 +000021#else
Harald Weltec45c3152000-12-06 08:11:24 +000022#define DEBUGP(x, args...)
Harald Welteae1ff9f2000-12-01 14:26:20 +000023#endif
Marc Bouchere6869a82000-03-20 06:03:29 +000024
Harald Weltea9d27082000-12-19 16:10:42 +000025static int binary = 0, counters = 0, verbose = 0, noflush = 0;
26
Marc Bouchere6869a82000-03-20 06:03:29 +000027/* Keeping track of external matches and targets. */
28static struct option options[] = {
Harald Weltea9d27082000-12-19 16:10:42 +000029 { "binary", 0, 0, 'b' },
30 { "counters", 0, 0, 'c' },
Martin Josefssonec789712004-01-31 19:28:13 +000031 { "verbose", 0, 0, 'v' },
Martin Josefssonbb2f68a2004-02-01 22:03:27 +000032 { "test", 0, 0, 't' },
Harald Weltea9d27082000-12-19 16:10:42 +000033 { "help", 0, 0, 'h' },
34 { "noflush", 0, 0, 'n'},
Harald Welte58918652001-06-16 18:25:25 +000035 { "modprobe", 1, 0, 'M'},
Peter Warasinb9cde3a2007-11-05 19:35:31 +000036 { "table", 1, 0, 'T'},
Marc Bouchere6869a82000-03-20 06:03:29 +000037 { 0 }
38};
39
40static void print_usage(const char *name, const char *version) __attribute__((noreturn));
41
42static void print_usage(const char *name, const char *version)
43{
Martin Josefssonbb2f68a2004-02-01 22:03:27 +000044 fprintf(stderr, "Usage: %s [-b] [-c] [-v] [-t] [-h]\n"
Harald Weltea9d27082000-12-19 16:10:42 +000045 " [ --binary ]\n"
46 " [ --counters ]\n"
47 " [ --verbose ]\n"
Martin Josefssonbb2f68a2004-02-01 22:03:27 +000048 " [ --test ]\n"
Harald Weltea9d27082000-12-19 16:10:42 +000049 " [ --help ]\n"
Harald Welte58918652001-06-16 18:25:25 +000050 " [ --noflush ]\n"
Peter Warasinb9cde3a2007-11-05 19:35:31 +000051 " [ --table=<TABLE> ]\n"
Harald Welte58918652001-06-16 18:25:25 +000052 " [ --modprobe=<command>]\n", name);
Harald Weltea9d27082000-12-19 16:10:42 +000053
Marc Bouchere6869a82000-03-20 06:03:29 +000054 exit(1);
55}
56
Harald Welte58918652001-06-16 18:25:25 +000057iptc_handle_t create_handle(const char *tablename, const char* modprobe )
Marc Bouchere6869a82000-03-20 06:03:29 +000058{
Harald Welteae1ff9f2000-12-01 14:26:20 +000059 iptc_handle_t handle;
Marc Bouchere6869a82000-03-20 06:03:29 +000060
Harald Welteae1ff9f2000-12-01 14:26:20 +000061 handle = iptc_init(tablename);
Harald Welte58918652001-06-16 18:25:25 +000062
63 if (!handle) {
64 /* try to insmod the module if iptc_init failed */
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000065 load_xtables_ko(modprobe, 0);
Harald Welte58918652001-06-16 18:25:25 +000066 handle = iptc_init(tablename);
67 }
68
Harald Welteae1ff9f2000-12-01 14:26:20 +000069 if (!handle) {
Patrick McHardy5b098ac2007-02-14 13:59:12 +000070 exit_error(PARAMETER_PROBLEM, "%s: unable to initialize "
Harald Welteae1ff9f2000-12-01 14:26:20 +000071 "table '%s'\n", program_name, tablename);
72 exit(1);
Marc Bouchere6869a82000-03-20 06:03:29 +000073 }
Harald Welteae1ff9f2000-12-01 14:26:20 +000074 return handle;
Marc Bouchere6869a82000-03-20 06:03:29 +000075}
76
Lutz Jaenickee78c69c2006-12-09 13:06:04 +000077static int parse_counters(char *string, struct ipt_counters *ctr)
Harald Welted8e65632001-01-05 15:20:07 +000078{
Patrick McHardy875441e2007-10-17 08:48:58 +000079 unsigned long long pcnt, bcnt;
80 int ret;
Patrick McHardyb73691f2007-09-05 14:10:53 +000081
Patrick McHardy875441e2007-10-17 08:48:58 +000082 ret = sscanf(string, "[%llu:%llu]",
83 (unsigned long long *)&pcnt,
84 (unsigned long long *)&bcnt);
85 ctr->pcnt = pcnt;
86 ctr->bcnt = bcnt;
87 return ret == 2;
Harald Welted8e65632001-01-05 15:20:07 +000088}
Harald Welteae1ff9f2000-12-01 14:26:20 +000089
Harald Welte9f7fa492001-03-15 15:12:02 +000090/* global new argv and argc */
Harald Welte26e643f2001-05-03 20:50:03 +000091static char *newargv[255];
Harald Welte9f7fa492001-03-15 15:12:02 +000092static int newargc;
93
94/* function adding one argument to newargv, updating newargc
95 * returns true if argument added, false otherwise */
96static int add_argv(char *what) {
Harald Weltebb41f882001-10-21 14:11:54 +000097 DEBUGP("add_argv: %s\n", what);
Harald Welte9f7fa492001-03-15 15:12:02 +000098 if (what && ((newargc + 1) < sizeof(newargv)/sizeof(char *))) {
Harald Welte26e643f2001-05-03 20:50:03 +000099 newargv[newargc] = strdup(what);
Harald Welte9f7fa492001-03-15 15:12:02 +0000100 newargc++;
101 return 1;
102 } else
103 return 0;
104}
105
Harald Welte26e643f2001-05-03 20:50:03 +0000106static void free_argv(void) {
107 int i;
108
109 for (i = 0; i < newargc; i++)
110 free(newargv[i]);
111}
112
Bastiaan Bakker4e3771f2004-06-25 11:18:57 +0000113#ifdef IPTABLES_MULTI
114int
115iptables_restore_main(int argc, char *argv[])
116#else
117int
118main(int argc, char *argv[])
119#endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000120{
Martin Josefsson841e4ae2003-05-02 15:30:11 +0000121 iptc_handle_t handle = NULL;
Marc Bouchere6869a82000-03-20 06:03:29 +0000122 char buffer[10240];
Harald Weltea9d27082000-12-19 16:10:42 +0000123 int c;
Harald Welteae1ff9f2000-12-01 14:26:20 +0000124 char curtable[IPT_TABLE_MAXNAMELEN + 1];
Marc Bouchere6869a82000-03-20 06:03:29 +0000125 FILE *in;
Harald Welte58918652001-06-16 18:25:25 +0000126 const char *modprobe = 0;
Martin Josefssonbb2f68a2004-02-01 22:03:27 +0000127 int in_table = 0, testing = 0;
Peter Warasinb9cde3a2007-11-05 19:35:31 +0000128 const char *tablename = 0;
Marc Bouchere6869a82000-03-20 06:03:29 +0000129
130 program_name = "iptables-restore";
Harald Welte80fe35d2002-05-29 13:08:15 +0000131 program_version = IPTABLES_VERSION;
Illes Marci63e90632003-03-03 08:08:37 +0000132 line = 0;
Marc Bouchere6869a82000-03-20 06:03:29 +0000133
Martin Josefsson357d59d2004-12-27 19:49:28 +0000134 lib_dir = getenv("IPTABLES_LIB_DIR");
135 if (!lib_dir)
136 lib_dir = IPT_LIB_DIR;
137
Harald Welte3efb6ea2001-08-06 18:50:21 +0000138#ifdef NO_SHARED_LIBS
139 init_extensions();
140#endif
141
Peter Warasinb9cde3a2007-11-05 19:35:31 +0000142 while ((c = getopt_long(argc, argv, "bcvthnM:T:", options, NULL)) != -1) {
Harald Weltea9d27082000-12-19 16:10:42 +0000143 switch (c) {
144 case 'b':
145 binary = 1;
146 break;
147 case 'c':
148 counters = 1;
149 break;
Marc Boucher1277b592001-12-06 15:06:34 +0000150 case 'v':
151 verbose = 1;
152 break;
Martin Josefssonbb2f68a2004-02-01 22:03:27 +0000153 case 't':
154 testing = 1;
155 break;
Harald Weltea9d27082000-12-19 16:10:42 +0000156 case 'h':
157 print_usage("iptables-restore",
Harald Welte80fe35d2002-05-29 13:08:15 +0000158 IPTABLES_VERSION);
Harald Weltea9d27082000-12-19 16:10:42 +0000159 break;
160 case 'n':
161 noflush = 1;
162 break;
Harald Welte58918652001-06-16 18:25:25 +0000163 case 'M':
164 modprobe = optarg;
165 break;
Peter Warasinb9cde3a2007-11-05 19:35:31 +0000166 case 'T':
167 tablename = optarg;
168 break;
Harald Weltea9d27082000-12-19 16:10:42 +0000169 }
170 }
171
Marc Bouchere6869a82000-03-20 06:03:29 +0000172 if (optind == argc - 1) {
173 in = fopen(argv[optind], "r");
174 if (!in) {
Pavel Rusnak972af092007-05-10 15:00:39 +0000175 fprintf(stderr, "Can't open %s: %s\n", argv[optind],
Marc Bouchere6869a82000-03-20 06:03:29 +0000176 strerror(errno));
177 exit(1);
178 }
179 }
180 else if (optind < argc) {
Pavel Rusnak972af092007-05-10 15:00:39 +0000181 fprintf(stderr, "Unknown arguments found on commandline\n");
Marc Bouchere6869a82000-03-20 06:03:29 +0000182 exit(1);
183 }
184 else in = stdin;
Harald Welte9f7fa492001-03-15 15:12:02 +0000185
Marc Bouchere6869a82000-03-20 06:03:29 +0000186 /* Grab standard input. */
187 while (fgets(buffer, sizeof(buffer), in)) {
Harald Welteb3f22192003-03-06 11:56:31 +0000188 int ret = 0;
Marc Bouchere6869a82000-03-20 06:03:29 +0000189
190 line++;
Martin Josefsson5065afa2004-01-31 19:33:47 +0000191 if (buffer[0] == '\n')
192 continue;
Marc Bouchere6869a82000-03-20 06:03:29 +0000193 else if (buffer[0] == '#') {
Martin Josefsson3673dcb2004-01-31 19:41:49 +0000194 if (verbose)
195 fputs(buffer, stdout);
Marc Bouchere6869a82000-03-20 06:03:29 +0000196 continue;
Illes Marci26100fa2003-03-03 08:05:07 +0000197 } else if ((strcmp(buffer, "COMMIT\n") == 0) && (in_table)) {
Martin Josefssonbb2f68a2004-02-01 22:03:27 +0000198 if (!testing) {
199 DEBUGP("Calling commit\n");
200 ret = iptc_commit(&handle);
201 } else {
202 DEBUGP("Not calling commit, testing\n");
203 ret = 1;
204 }
Illes Marci26100fa2003-03-03 08:05:07 +0000205 in_table = 0;
Harald Welteb3f22192003-03-06 11:56:31 +0000206 } else if ((buffer[0] == '*') && (!in_table)) {
Harald Welteae1ff9f2000-12-01 14:26:20 +0000207 /* New table */
208 char *table;
209
210 table = strtok(buffer+1, " \t\n");
211 DEBUGP("line %u, table '%s'\n", line, table);
212 if (!table) {
213 exit_error(PARAMETER_PROBLEM,
214 "%s: line %u table name invalid\n",
215 program_name, line);
216 exit(1);
217 }
218 strncpy(curtable, table, IPT_TABLE_MAXNAMELEN);
Karsten Desler073df8f2004-01-31 15:33:55 +0000219 curtable[IPT_TABLE_MAXNAMELEN] = '\0';
Harald Welteae1ff9f2000-12-01 14:26:20 +0000220
Peter Warasinb9cde3a2007-11-05 19:35:31 +0000221 if (tablename && (strcmp(tablename, table) != 0))
222 continue;
Martin Josefsson841e4ae2003-05-02 15:30:11 +0000223 if (handle)
224 iptc_free(&handle);
225
Harald Welte58918652001-06-16 18:25:25 +0000226 handle = create_handle(table, modprobe);
Harald Weltea9d27082000-12-19 16:10:42 +0000227 if (noflush == 0) {
228 DEBUGP("Cleaning all chains of table '%s'\n",
229 table);
230 for_each_chain(flush_entries, verbose, 1,
231 &handle);
232
233 DEBUGP("Deleting all user-defined chains "
234 "of table '%s'\n", table);
235 for_each_chain(delete_chain, verbose, 0,
236 &handle) ;
237 }
Harald Welteae1ff9f2000-12-01 14:26:20 +0000238
239 ret = 1;
Illes Marci26100fa2003-03-03 08:05:07 +0000240 in_table = 1;
Harald Welteae1ff9f2000-12-01 14:26:20 +0000241
Illes Marci26100fa2003-03-03 08:05:07 +0000242 } else if ((buffer[0] == ':') && (in_table)) {
Marc Bouchere6869a82000-03-20 06:03:29 +0000243 /* New chain. */
Harald Welteae1ff9f2000-12-01 14:26:20 +0000244 char *policy, *chain;
Marc Bouchere6869a82000-03-20 06:03:29 +0000245
Marc Bouchere6869a82000-03-20 06:03:29 +0000246 chain = strtok(buffer+1, " \t\n");
Harald Welteae1ff9f2000-12-01 14:26:20 +0000247 DEBUGP("line %u, chain '%s'\n", line, chain);
Marc Bouchere6869a82000-03-20 06:03:29 +0000248 if (!chain) {
249 exit_error(PARAMETER_PROBLEM,
250 "%s: line %u chain name invalid\n",
251 program_name, line);
252 exit(1);
253 }
Harald Welteae1ff9f2000-12-01 14:26:20 +0000254
Harald Welte3a506ac2004-08-30 16:00:09 +0000255 if (iptc_builtin(chain, handle) <= 0) {
Charlie Brady595e4932005-06-12 15:54:15 +0000256 if (noflush && iptc_is_chain(chain, handle)) {
257 DEBUGP("Flushing existing user defined chain '%s'\n", chain);
258 if (!iptc_flush_entries(chain, &handle))
259 exit_error(PARAMETER_PROBLEM,
260 "error flushing chain "
261 "'%s':%s\n", chain,
262 strerror(errno));
263 } else {
264 DEBUGP("Creating new chain '%s'\n", chain);
265 if (!iptc_create_chain(chain, &handle))
266 exit_error(PARAMETER_PROBLEM,
267 "error creating chain "
268 "'%s':%s\n", chain,
269 strerror(errno));
270 }
Harald Welte9f7fa492001-03-15 15:12:02 +0000271 }
Harald Welteae1ff9f2000-12-01 14:26:20 +0000272
Marc Bouchere6869a82000-03-20 06:03:29 +0000273 policy = strtok(NULL, " \t\n");
Harald Welteae1ff9f2000-12-01 14:26:20 +0000274 DEBUGP("line %u, policy '%s'\n", line, policy);
Marc Bouchere6869a82000-03-20 06:03:29 +0000275 if (!policy) {
276 exit_error(PARAMETER_PROBLEM,
277 "%s: line %u policy invalid\n",
278 program_name, line);
279 exit(1);
280 }
Harald Welteae1ff9f2000-12-01 14:26:20 +0000281
282 if (strcmp(policy, "-") != 0) {
Harald Welted8e65632001-01-05 15:20:07 +0000283 struct ipt_counters count;
284
285 if (counters) {
286 char *ctrs;
287 ctrs = strtok(NULL, " \t\n");
288
Harald Welte6f38a302006-02-09 14:35:38 +0000289 if (!ctrs || !parse_counters(ctrs, &count))
290 exit_error(PARAMETER_PROBLEM,
291 "invalid policy counters "
292 "for chain '%s'\n", chain);
Harald Welted8e65632001-01-05 15:20:07 +0000293
294 } else {
295 memset(&count, 0,
296 sizeof(struct ipt_counters));
297 }
Harald Welteae1ff9f2000-12-01 14:26:20 +0000298
299 DEBUGP("Setting policy of chain %s to %s\n",
300 chain, policy);
301
Harald Welted8e65632001-01-05 15:20:07 +0000302 if (!iptc_set_policy(chain, policy, &count,
303 &handle))
Harald Welteae1ff9f2000-12-01 14:26:20 +0000304 exit_error(OTHER_PROBLEM,
305 "Can't set policy `%s'"
306 " on `%s' line %u: %s\n",
307 chain, policy, line,
308 iptc_strerror(errno));
309 }
310
311 ret = 1;
312
Illes Marci26100fa2003-03-03 08:05:07 +0000313 } else if (in_table) {
Harald Welte9f7fa492001-03-15 15:12:02 +0000314 int a;
Marc Bouchere6869a82000-03-20 06:03:29 +0000315 char *ptr = buffer;
Harald Welteccd49e52001-01-23 22:54:34 +0000316 char *pcnt = NULL;
317 char *bcnt = NULL;
Harald Welte9f7fa492001-03-15 15:12:02 +0000318 char *parsestart;
319
Harald Welte26e643f2001-05-03 20:50:03 +0000320 /* the parser */
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000321 char *curchar;
Harald Welte26e643f2001-05-03 20:50:03 +0000322 int quote_open;
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000323 int param_len;
Harald Welte26e643f2001-05-03 20:50:03 +0000324
Harald Welte9f7fa492001-03-15 15:12:02 +0000325 /* reset the newargv */
326 newargc = 0;
Marc Bouchere6869a82000-03-20 06:03:29 +0000327
Marc Bouchere6869a82000-03-20 06:03:29 +0000328 if (buffer[0] == '[') {
Harald Welte9f7fa492001-03-15 15:12:02 +0000329 /* we have counters in our input */
Marc Bouchere6869a82000-03-20 06:03:29 +0000330 ptr = strchr(buffer, ']');
331 if (!ptr)
332 exit_error(PARAMETER_PROBLEM,
333 "Bad line %u: need ]\n",
334 line);
Harald Welte9f7fa492001-03-15 15:12:02 +0000335
Harald Welteccd49e52001-01-23 22:54:34 +0000336 pcnt = strtok(buffer+1, ":");
Harald Welte9f7fa492001-03-15 15:12:02 +0000337 if (!pcnt)
338 exit_error(PARAMETER_PROBLEM,
339 "Bad line %u: need :\n",
340 line);
341
Harald Welteccd49e52001-01-23 22:54:34 +0000342 bcnt = strtok(NULL, "]");
Harald Welte9f7fa492001-03-15 15:12:02 +0000343 if (!bcnt)
344 exit_error(PARAMETER_PROBLEM,
345 "Bad line %u: need ]\n",
346 line);
347
348 /* start command parsing after counter */
349 parsestart = ptr + 1;
350 } else {
351 /* start command parsing at start of line */
352 parsestart = buffer;
Marc Bouchere6869a82000-03-20 06:03:29 +0000353 }
Rusty Russell7e53bf92000-03-20 07:03:28 +0000354
Harald Welte9f7fa492001-03-15 15:12:02 +0000355 add_argv(argv[0]);
356 add_argv("-t");
357 add_argv((char *) &curtable);
358
Harald Welteccd49e52001-01-23 22:54:34 +0000359 if (counters && pcnt && bcnt) {
Harald Welte9f7fa492001-03-15 15:12:02 +0000360 add_argv("--set-counters");
361 add_argv((char *) pcnt);
362 add_argv((char *) bcnt);
Harald Welteccd49e52001-01-23 22:54:34 +0000363 }
Harald Welteae1ff9f2000-12-01 14:26:20 +0000364
Harald Welte26e643f2001-05-03 20:50:03 +0000365 /* After fighting with strtok enough, here's now
366 * a 'real' parser. According to Rusty I'm now no
367 * longer a real hacker, but I can live with that */
368
369 quote_open = 0;
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000370 param_len = 0;
Harald Welte26e643f2001-05-03 20:50:03 +0000371
372 for (curchar = parsestart; *curchar; curchar++) {
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000373 char param_buffer[1024];
374
Harald Welte26e643f2001-05-03 20:50:03 +0000375 if (*curchar == '"') {
Michael Rash29cdbd02004-01-05 09:41:50 +0000376 /* quote_open cannot be true if there
377 * was no previous character. Thus,
378 * curchar-1 has to be within bounds */
379 if (quote_open &&
380 *(curchar-1) != '\\') {
Harald Welte26e643f2001-05-03 20:50:03 +0000381 quote_open = 0;
382 *curchar = ' ';
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000383 } else if (!quote_open) {
Harald Welte26e643f2001-05-03 20:50:03 +0000384 quote_open = 1;
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000385 continue;
Harald Welte26e643f2001-05-03 20:50:03 +0000386 }
387 }
388 if (*curchar == ' '
389 || *curchar == '\t'
390 || * curchar == '\n') {
Harald Welte26e643f2001-05-03 20:50:03 +0000391
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000392 if (quote_open) {
393 param_buffer[param_len++] =
394 *curchar;
Harald Welte26e643f2001-05-03 20:50:03 +0000395 continue;
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000396 }
Harald Welte26e643f2001-05-03 20:50:03 +0000397
Harald Welte974d0102001-05-26 04:41:56 +0000398 if (!param_len) {
399 /* two spaces? */
Harald Welte974d0102001-05-26 04:41:56 +0000400 continue;
401 }
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000402
403 param_buffer[param_len] = '\0';
Harald Weltebb41f882001-10-21 14:11:54 +0000404
405 /* check if table name specified */
Harald Welte48a6f902001-10-22 15:16:21 +0000406 if (!strncmp(param_buffer, "-t", 3)
407 || !strncmp(param_buffer, "--table", 8)) {
Harald Weltebb41f882001-10-21 14:11:54 +0000408 exit_error(PARAMETER_PROBLEM,
409 "Line %u seems to have a "
410 "-t table option.\n", line);
411 exit(1);
412 }
413
Harald Welte26e643f2001-05-03 20:50:03 +0000414 add_argv(param_buffer);
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000415 param_len = 0;
Harald Welte26e643f2001-05-03 20:50:03 +0000416 } else {
Pablo Neira Ayusob4f31642007-04-18 10:27:02 +0000417 /* Skip backslash that escapes quote:
418 * the standard input does not require
419 * escaping. However, the output
420 * generated by iptables-save
421 * introduces bashlash to keep
422 * consistent with iptables
423 */
424 if (quote_open &&
425 *curchar == '\\' &&
426 *(curchar+1) == '"')
427 continue;
428
429 /* regular character, copy to buffer */
430 param_buffer[param_len++] = *curchar;
431
432 if (param_len >= sizeof(param_buffer))
433 exit_error(PARAMETER_PROBLEM,
434 "Parameter too long!");
Harald Welte26e643f2001-05-03 20:50:03 +0000435 }
Marc Bouchere6869a82000-03-20 06:03:29 +0000436 }
437
Harald Welte26e643f2001-05-03 20:50:03 +0000438 DEBUGP("calling do_command(%u, argv, &%s, handle):\n",
439 newargc, curtable);
Harald Welteae1ff9f2000-12-01 14:26:20 +0000440
Harald Weltefa48fc82001-10-16 09:51:33 +0000441 for (a = 0; a < newargc; a++)
Harald Welteae1ff9f2000-12-01 14:26:20 +0000442 DEBUGP("argv[%u]: %s\n", a, newargv[a]);
443
Harald Welte26e643f2001-05-03 20:50:03 +0000444 ret = do_command(newargc, newargv,
445 &newargv[2], &handle);
446
447 free_argv();
Marc Bouchere6869a82000-03-20 06:03:29 +0000448 }
Peter Warasinb9cde3a2007-11-05 19:35:31 +0000449 if (tablename && (strcmp(tablename, curtable) != 0))
450 continue;
Marc Bouchere6869a82000-03-20 06:03:29 +0000451 if (!ret) {
452 fprintf(stderr, "%s: line %u failed\n",
453 program_name, line);
454 exit(1);
455 }
456 }
Martin Josefsson3229a7c2004-02-01 21:46:04 +0000457 if (in_table) {
458 fprintf(stderr, "%s: COMMIT expected at line %u\n",
459 program_name, line + 1);
460 exit(1);
461 }
Marc Bouchere6869a82000-03-20 06:03:29 +0000462
463 return 0;
464}