Only run includes and set sysctls if either v4 or v6 firewall was actually started
[project/firewall3.git] / main.c
diff --git a/main.c b/main.c
index 1135c50..3654c15 100644 (file)
--- a/main.c
+++ b/main.c
@@ -135,7 +135,7 @@ restore_pipe(enum fw3_family family, bool silent)
 static bool
 family_running(struct fw3_state *state, enum fw3_family family)
 {
-       return hasbit(state->running_defaults.flags, family);
+       return hasbit(state->defaults.running_flags, family);
 }
 
 static bool
@@ -162,6 +162,8 @@ family_set(struct fw3_state *state, enum fw3_family family, bool set)
 static int
 stop(struct fw3_state *state, bool complete, bool reload)
 {
+       FILE *ct;
+
        int rv = 1;
        enum fw3_family family;
        enum fw3_table table;
@@ -204,11 +206,11 @@ stop(struct fw3_state *state, bool complete, bool reload)
                        {
                                /* pass 1 */
                                fw3_flush_rules(table, family, false, state, policy);
-                               fw3_flush_zones(table, family, false, state);
+                               fw3_flush_zones(table, family, false, reload, state);
 
                                /* pass 2 */
                                fw3_flush_rules(table, family, true, state, policy);
-                               fw3_flush_zones(table, family, true, state);
+                               fw3_flush_zones(table, family, true, reload, state);
                        }
 
                        fw3_pr("COMMIT\n");
@@ -217,15 +219,25 @@ stop(struct fw3_state *state, bool complete, bool reload)
                fw3_command_close();
 
                if (!reload)
+               {
+                       if (fw3_command_pipe(false, "ipset", "-exist", "-"))
+                       {
+                               fw3_destroy_ipsets(state, family);
+                               fw3_command_close();
+                       }
+
                        family_set(state, family, false);
+               }
 
                rv = 0;
        }
 
-       if (!reload && fw3_command_pipe(false, "ipset", "-exist", "-"))
+       if (complete && (ct = fopen("/proc/net/nf_conntrack", "w")) != NULL)
        {
-               fw3_destroy_ipsets(state);
-               fw3_command_close();
+               info("Flushing conntrack table ...");
+
+               fwrite("f\n", 2, 1, ct);
+               fclose(ct);
        }
 
        if (!rv)
@@ -243,8 +255,6 @@ start(struct fw3_state *state, bool reload)
 
        if (!print_rules && !reload)
        {
-               fw3_set_defaults(state);
-
                if (fw3_command_pipe(false, "ipset", "-exist", "-"))
                {
                        fw3_create_ipsets(state);
@@ -299,11 +309,16 @@ start(struct fw3_state *state, bool reload)
                rv = 0;
        }
 
-       if (!reload && !print_rules)
-               fw3_run_includes(state);
+       if (!rv)
+       {
+               fw3_set_defaults(state);
+
+               if (!reload && !print_rules)
+                       fw3_run_includes(state);
 
-       if (!rv && !print_rules)
-               fw3_write_statefile(state);
+               if (!print_rules)
+                       fw3_write_statefile(state);
+       }
 
        return rv;
 }