From a8658ca43fba82f7761f774f4daeb29b3e335053 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 5 Mar 2003 07:46:15 +0000 Subject: port 'line number on error in iptables-restore' from ipv4 --- include/ip6tables.h | 2 ++ ip6tables-restore.c | 15 +++++++++------ ip6tables.c | 8 ++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/ip6tables.h b/include/ip6tables.h index ca388f7c..b098f81c 100644 --- a/include/ip6tables.h +++ b/include/ip6tables.h @@ -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); diff --git a/ip6tables-restore.c b/ip6tables-restore.c index 66801133..82e1d2b0 100644 --- a/ip6tables-restore.c +++ b/ip6tables-restore.c @@ -7,7 +7,7 @@ * Rusty Russell * 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 @@ -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; diff --git a/ip6tables.c b/ip6tables.c index 6ee460b2..17bdb4e5 100644 --- a/ip6tables.c +++ b/ip6tables.c @@ -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); -- cgit v1.2.3