7c837d
commit 3a25ae2361da048f24524d8e63d70f4cd40444f3
7c837d
Author: Sanket Shah <sanket.shah@cyberoam.com>
7c837d
Date:   Wed Jul 31 21:40:08 2013 +0200
7c837d
7c837d
    Add --noflush command line support for ebtables-restore
7c837d
7c837d
diff --git a/ebtables-restore.c b/ebtables-restore.c
7c837d
index ea02960..bb4d0cf 100644
7c837d
--- a/ebtables-restore.c
7c837d
+++ b/ebtables-restore.c
7c837d
@@ -22,13 +22,25 @@
7c837d
 #include <string.h>
7c837d
 #include <errno.h>
7c837d
 #include <unistd.h>
7c837d
+#include <getopt.h>
7c837d
 #include "include/ebtables_u.h"
7c837d
 
7c837d
+static const struct option options[] = {
7c837d
+	{.name = "noflush", .has_arg = 0, .val = 'n'},
7c837d
+	{ 0 }
7c837d
+};
7c837d
+
7c837d
 static struct ebt_u_replace replace[3];
7c837d
 void ebt_early_init_once();
7c837d
 
7c837d
 #define OPT_KERNELDATA  0x800 /* Also defined in ebtables.c */
7c837d
 
7c837d
+static void print_usage()
7c837d
+{
7c837d
+	fprintf(stderr, "Usage: ebtables-restore [ --noflush ]\n");
7c837d
+	exit(1);
7c837d
+}
7c837d
+
7c837d
 static void copy_table_names()
7c837d
 {
7c837d
 	strcpy(replace[0].name, "filter");
7c837d
@@ -41,11 +53,20 @@ static void copy_table_names()
7c837d
 int main(int argc_, char *argv_[])
7c837d
 {
7c837d
 	char *argv[EBTD_ARGC_MAX], cmdline[EBTD_CMDLINE_MAXLN];
7c837d
-	int i, offset, quotemode = 0, argc, table_nr = -1, line = 0, whitespace;
7c837d
+	int i, offset, quotemode = 0, argc, table_nr = -1, line = 0, whitespace, c, flush = 1;
7c837d
 	char ebtables_str[] = "ebtables";
7c837d
 
7c837d
-	if (argc_ != 1)
7c837d
-		ebtrest_print_error("options are not supported");
7c837d
+	while ((c = getopt_long(argc_, argv_, "n", options, NULL)) != -1) {
7c837d
+		switch(c) {
7c837d
+			case 'n':
7c837d
+				flush = 0;
7c837d
+				break;
7c837d
+			default:
7c837d
+				print_usage();
7c837d
+				break;
7c837d
+		}
7c837d
+	}
7c837d
+
7c837d
 	ebt_silent = 0;
7c837d
 	copy_table_names();
7c837d
 	ebt_early_init_once();
7c837d
@@ -68,7 +89,7 @@ int main(int argc_, char *argv_[])
7c837d
 				ebtrest_print_error("table '%s' was not recognized", cmdline+1);
7c837d
 			table_nr = i;
7c837d
 			replace[table_nr].command = 11;
7c837d
-			ebt_get_kernel_table(&replace[table_nr], 1);
7c837d
+			ebt_get_kernel_table(&replace[table_nr], flush);
7c837d
 			replace[table_nr].command = 0;
7c837d
 			replace[table_nr].flags = OPT_KERNELDATA; /* Prevent do_command from initialising replace */
7c837d
 			continue;