add time match support
[project/firewall3.git] / defaults.c
index 2d64695..e1710c2 100644 (file)
@@ -60,7 +60,7 @@ static const struct chain toplevel_rules[] = {
        C(ANY, RAW,    UNSPEC,        "PREROUTING -j notrack"),
 };
 
-static struct fw3_option default_opts[] = {
+const struct fw3_option fw3_default_opts[] = {
        FW3_OPT("input",               target,   defaults, policy_input),
        FW3_OPT("forward",             target,   defaults, policy_forward),
        FW3_OPT("output",              target,   defaults, policy_output),
@@ -82,6 +82,8 @@ static struct fw3_option default_opts[] = {
 
        FW3_OPT("custom_chains",       bool,     defaults, custom_chains),
        FW3_OPT("disable_ipv6",        bool,     defaults, disable_ipv6),
+
+       { }
 };
 
 
@@ -157,8 +159,7 @@ fw3_load_defaults(struct fw3_state *state, struct uci_package *p)
                        continue;
                }
 
-               fw3_parse_options(&state->defaults,
-                                 default_opts, ARRAY_SIZE(default_opts), s);
+               fw3_parse_options(&state->defaults, fw3_default_opts, s);
 
                check_policy(e, &defs->policy_input, "input");
                check_policy(e, &defs->policy_output, "output");
@@ -295,30 +296,29 @@ reset_policy(enum fw3_table table)
 
 void
 fw3_flush_rules(enum fw3_table table, enum fw3_family family,
-                bool pass2, struct list_head *statefile)
+                bool pass2, struct fw3_state *state)
 {
-       struct fw3_statefile_entry *e;
+       struct fw3_defaults *d = &state->running_defaults;
+
+       if (!hasbit(d->flags, family))
+               return;
 
-       list_for_each_entry(e, statefile, list)
+       if (!pass2)
        {
-               if (e->type != FW3_TYPE_DEFAULTS)
-                       continue;
+               reset_policy(table);
 
-               if (!pass2)
-               {
-                       reset_policy(table);
+               print_chains(table, family, "-D %s\n", state->running_defaults.flags,
+                                        toplevel_rules, ARRAY_SIZE(toplevel_rules));
 
-                       print_chains(table, family, "-D %s\n", e->flags[0],
-                                    toplevel_rules, ARRAY_SIZE(toplevel_rules));
+               print_chains(table, family, "-F %s\n", state->running_defaults.flags,
+                                        default_chains, ARRAY_SIZE(default_chains));
+       }
+       else
+       {
+               print_chains(table, family, "-X %s\n", state->running_defaults.flags,
+                                        default_chains, ARRAY_SIZE(default_chains));
 
-                       print_chains(table, family, "-F %s\n", e->flags[0],
-                                    default_chains, ARRAY_SIZE(default_chains));
-               }
-               else
-               {
-                       print_chains(table, family, "-X %s\n", e->flags[0],
-                                    default_chains, ARRAY_SIZE(default_chains));
-               }
+               delbit(d->flags, family);
        }
 }