]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
port 'line number on error in iptables-restore' from ipv4
authorHarald Welte <laforge@gnumonks.org>
Wed, 5 Mar 2003 07:46:15 +0000 (07:46 +0000)
committerHarald Welte <laforge@gnumonks.org>
Wed, 5 Mar 2003 07:46:15 +0000 (07:46 +0000)
include/ip6tables.h
ip6tables-restore.c
ip6tables.c

index ca388f7c0d2a7630a5b659a865e567cfb9bc2c1d..b098f81c306f65c10ee1bc23d29574d3e9fc053e 100644 (file)
@@ -106,6 +106,8 @@ struct ip6tables_target
 #endif
 };
 
+extern int line;
+
 /* Your shared library should call one of these. */
 extern void register_match6(struct ip6tables_match *me);
 extern void register_target6(struct ip6tables_target *me);
index 668011334bcb6561e7be9bc6fe0a1a6e5417d233..82e1d2b0ded698048d859588693aaebeda472c3a 100644 (file)
@@ -7,7 +7,7 @@
  *     Rusty Russell <rusty@linuxcare.com.au>
  * This code is distributed under the terms of GNU GPL v2
  *
- * $Id: ip6tables-restore.c,v 1.9 2002/05/29 13:08:15 laforge Exp $
+ * $Id: ip6tables-restore.c,v 1.10 2002/08/14 11:40:41 laforge Exp $
  */
 
 #include <getopt.h>
@@ -104,14 +104,15 @@ int main(int argc, char *argv[])
 {
        ip6tc_handle_t handle;
        char buffer[10240];
-       unsigned int line = 0;
        int c;
        char curtable[IP6T_TABLE_MAXNAMELEN + 1];
        FILE *in;
        const char *modprobe = 0;
+       int in_table = 0;
 
        program_name = "ip6tables-restore";
        program_version = IPTABLES_VERSION;
+       line = 0;
 
 #ifdef NO_SHARED_LIBS
        init_extensions();
@@ -164,10 +165,11 @@ int main(int argc, char *argv[])
                else if (buffer[0] == '#') {
                        if (verbose) fputs(buffer, stdout);
                        continue;
-               } else if (strcmp(buffer, "COMMIT\n") == 0) {
+               } else if ((strcmp(buffer, "COMMIT\n") == 0) && (in_table)) {
                        DEBUGP("Calling commit\n");
                        ret = ip6tc_commit(&handle);
-               } else if (buffer[0] == '*') {
+                       in_table = 0;
+               } else if ((buffer[0] == '*') && (!in_table)) {
                        /* New table */
                        char *table;
 
@@ -195,8 +197,9 @@ int main(int argc, char *argv[])
                        }
 
                        ret = 1;
+                       in_table = 1;
 
-               } else if (buffer[0] == ':') {
+               } else if ((buffer[0] == ':') && (in_table)) {
                        /* New chain. */
                        char *policy, *chain;
 
@@ -255,7 +258,7 @@ int main(int argc, char *argv[])
 
                        ret = 1;
 
-               } else {
+               } else if (in_table) {
                        int a;
                        char *ptr = buffer;
                        char *pcnt = NULL;
index 6ee460b2134e3465c7a4c3e2810694a5cf126cea..17bdb4e517d8127bef371e1b8f28a42374f541cb 100644 (file)
@@ -142,6 +142,12 @@ static struct option original_opts[] = {
        { 0 }
 };
 
+/* we need this for ip6tables-restore. ip6tables-restore.c sets line to the
+ * current line of the input file, in order to give a more precise error
+ * message. ip6tables itself doesn't need this, so it is initialized to the
+ * magic number of -1 */
+int line = -1;
+
 #ifndef __OPTIMIZE__
 struct ip6t_entry_target *
 ip6t_get_target(struct ip6t_entry *e)
@@ -278,6 +284,8 @@ exit_error(enum exittype status, char *msg, ...)
 void
 exit_tryhelp(int status)
 {
+       if (line != -1)
+               fprintf(stderr, "Error occurred at line: %d\n", line);
        fprintf(stderr, "Try `%s -h' or '%s --help' for more information.\n",
                        program_name, program_name );
        exit(status);