iptables: Clear global parser flags
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 12 Feb 2013 09:19:39 +0000 (10:19 +0100)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 12 Feb 2013 10:27:45 +0000 (12:27 +0200)
That allows the parser to be reentrantable.

src/iptables.c

index 2f9844f..3e4513f 100644 (file)
@@ -1617,6 +1617,24 @@ static struct connman_iptables *pre_load_table(const char *table_name,
        return iptables_init(table_name);
 }
 
+static void clear_tables_flags(void)
+{
+       struct xtables_match *xt_m;
+       struct xtables_target *xt_t;
+
+       /*
+        * Clear all flags because the flags are only valid
+        * for one rule.
+        */
+       for (xt_m = xtables_matches; xt_m != NULL; xt_m = xt_m->next)
+               xt_m->mflags = 0;
+
+       for (xt_t = xtables_targets; xt_t != NULL; xt_t = xt_t->next) {
+               xt_t->tflags = 0;
+               xt_t->used = 0;
+       }
+}
+
 static int iptables_command(int argc, char *argv[])
 {
        struct connman_iptables *table;
@@ -1647,6 +1665,8 @@ static int iptables_command(int argc, char *argv[])
        /* Default code for options parsing */
        ret = -EINVAL;
 
+       clear_tables_flags();
+
        /* extension's options will generate false-positives errors */
        opterr = 0;