]> granicus.if.org Git - ipset/commitdiff
Show correct line numbers in restore output for parser errors
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 18 Jan 2011 16:17:46 +0000 (17:17 +0100)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 18 Jan 2011 16:17:46 +0000 (17:17 +0100)
Parser errors are reported by a wrong lineno at restore, bug reported
by Holger Eitzenberger:

  create foo6 hash:ip hashsize 64 family inet6
  add foo6 20a1:1234:5678::/64
  add foo6 20a1:1234:5679::/64

you get:

  ipset v5.2: Error in line 1: Syntax error: plain IP address must be supplied: 20a1:1234:5678::/64

Should be line 2 though.

The solution is to set the session lineno before parsing.

include/libipset/session.h
lib/session.c
src/ipset.c

index 02e8b36de974c12c85675a3ca0b932d76ab1c81f..a06c79f20fbda1eeb20e567bfb4de2f3019c1ffc 100644 (file)
@@ -24,6 +24,7 @@ struct ipset_handle;
 extern struct ipset_data * ipset_session_data(const struct ipset_session *session);
 extern struct ipset_handle * ipset_session_handle(const struct ipset_session *session);
 extern const struct ipset_type * ipset_saved_type(const struct ipset_session *session);
+extern void ipset_session_lineno(struct ipset_session *session, uint32_t lineno);
 
 enum ipset_err_type {
        IPSET_ERROR,
index 311e5df40216c2d2b855709ed37029d17ac07c53..a1931431b19d8f55addbfe52a5cd440c3f170039 100644 (file)
@@ -98,6 +98,19 @@ ipset_saved_type(const struct ipset_session *session)
        return session->saved_type;
 }
 
+/**
+ * ipset_session_lineno - set session lineno
+ * @session: session structure
+ *
+ * Set session lineno to report parser errors correctly.
+ */
+void
+ipset_session_lineno(struct ipset_session *session, uint32_t lineno)
+{
+       assert(session);
+       session->lineno = lineno;
+}
+
 /*
  * Environment options
  */
index 89dbe8fa7a56c6dd95402ed30607fcc042f72104..d4cf7b86ce9d2f3dc6c05c14c81c4cb0971d2dd8 100644 (file)
@@ -439,6 +439,9 @@ parse_commandline(int argc, char *argv[])
                                "Cannot initialize ipset session, aborting.");
        }
 
+       /* Set session lineno to report parser errors correctly */
+       ipset_session_lineno(session, restore_line);
+
        /* Commandline parsing, somewhat similar to that of 'ip' */
 
        /* First: parse core options */