diff options
author | Martin Josefsson <gandalf@wlug.westbo.se> | 2004-02-01 22:03:27 +0000 |
---|---|---|
committer | Martin Josefsson <gandalf@wlug.westbo.se> | 2004-02-01 22:03:27 +0000 |
commit | bb2f68ae205ad5fe0c76c85c11e6d0f5a09fb862 (patch) | |
tree | 4653d95324c2337ff07b9ef61e6660080b1e3ce2 | |
parent | 3229a7cbdbf36fd499efacc8834ea525e0902eb7 (diff) |
Add --test (-t) in order to test the whole file without changing anything if something fails
-rw-r--r-- | iptables-restore.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/iptables-restore.c b/iptables-restore.c index 27422e32..46590ca9 100644 --- a/iptables-restore.c +++ b/iptables-restore.c @@ -4,7 +4,7 @@ * * This code is distributed under the terms of GNU GPL v2 * - * $Id: iptables-restore.c,v 1.31 2004/01/31 19:41:49 gandalf Exp $ + * $Id: iptables-restore.c,v 1.32 2004/02/01 21:46:04 gandalf Exp $ */ #include <getopt.h> @@ -28,6 +28,7 @@ static struct option options[] = { { "binary", 0, 0, 'b' }, { "counters", 0, 0, 'c' }, { "verbose", 0, 0, 'v' }, + { "test", 0, 0, 't' }, { "help", 0, 0, 'h' }, { "noflush", 0, 0, 'n'}, { "modprobe", 1, 0, 'M'}, @@ -38,10 +39,11 @@ static void print_usage(const char *name, const char *version) __attribute__((no static void print_usage(const char *name, const char *version) { - fprintf(stderr, "Usage: %s [-b] [-c] [-v] [-h]\n" + fprintf(stderr, "Usage: %s [-b] [-c] [-v] [-t] [-h]\n" " [ --binary ]\n" " [ --counters ]\n" " [ --verbose ]\n" + " [ --test ]\n" " [ --help ]\n" " [ --noflush ]\n" " [ --modprobe=<command>]\n", name); @@ -105,7 +107,7 @@ int main(int argc, char *argv[]) char curtable[IPT_TABLE_MAXNAMELEN + 1]; FILE *in; const char *modprobe = 0; - int in_table = 0; + int in_table = 0, testing = 0; program_name = "iptables-restore"; program_version = IPTABLES_VERSION; @@ -115,7 +117,7 @@ int main(int argc, char *argv[]) init_extensions(); #endif - while ((c = getopt_long(argc, argv, "bcvhnM:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "bcvthnM:", options, NULL)) != -1) { switch (c) { case 'b': binary = 1; @@ -126,6 +128,9 @@ int main(int argc, char *argv[]) case 'v': verbose = 1; break; + case 't': + testing = 1; + break; case 'h': print_usage("iptables-restore", IPTABLES_VERSION); @@ -165,8 +170,13 @@ int main(int argc, char *argv[]) fputs(buffer, stdout); continue; } else if ((strcmp(buffer, "COMMIT\n") == 0) && (in_table)) { - DEBUGP("Calling commit\n"); - ret = iptc_commit(&handle); + if (!testing) { + DEBUGP("Calling commit\n"); + ret = iptc_commit(&handle); + } else { + DEBUGP("Not calling commit, testing\n"); + ret = 1; + } in_table = 0; } else if ((buffer[0] == '*') && (!in_table)) { /* New table */ |