Send quit comment in fw3_destroy_ipsets() and initialize ipset objects with enabled...
[project/firewall3.git] / ipsets.c
index 430cf74..eb37d0a 100644 (file)
--- a/ipsets.c
+++ b/ipsets.c
@@ -216,6 +216,8 @@ fw3_alloc_ipset(void)
 
        INIT_LIST_HEAD(&ipset->datatypes);
 
+       ipset->enabled = true;
+
        return ipset;
 }
 
@@ -272,10 +274,8 @@ static void
 create_ipset(struct fw3_ipset *ipset, struct fw3_state *state)
 {
        bool first = true;
-       char s[INET6_ADDRSTRLEN];
 
        struct fw3_ipset_datatype *type;
-       struct fw3_address *a;
 
        const char *methods[] = {
                "(bug)",
@@ -309,27 +309,7 @@ create_ipset(struct fw3_ipset *ipset, struct fw3_state *state)
 
        if (ipset->iprange.set)
        {
-               a = &ipset->iprange;
-
-               if (!a->range)
-               {
-                       inet_ntop(a->family == FW3_FAMILY_V4 ? AF_INET : AF_INET6,
-                                 &a->address.v6, s, sizeof(s));
-
-                       fw3_pr(" range %s/%u", s, a->mask);
-               }
-               else
-               {
-                       inet_ntop(a->family == FW3_FAMILY_V4 ? AF_INET : AF_INET6,
-                                 &a->address.v6, s, sizeof(s));
-
-                       fw3_pr(" range %s", s);
-
-                       inet_ntop(a->family == FW3_FAMILY_V4 ? AF_INET : AF_INET6,
-                                 &a->address2.v6, s, sizeof(s));
-
-                       fw3_pr("-%s", s);
-               }
+               fw3_pr(" range %s", fw3_address_to_string(&ipset->iprange, false));
        }
        else if (ipset->portrange.set)
        {
@@ -370,22 +350,19 @@ fw3_create_ipsets(struct fw3_state *state)
 }
 
 void
-fw3_destroy_ipsets(struct fw3_state *state, enum fw3_family family)
+fw3_destroy_ipsets(struct fw3_state *state)
 {
-       struct fw3_ipset *s, *tmp;
+       struct fw3_ipset *s;
 
-       list_for_each_entry_safe(s, tmp, &state->ipsets, list)
+       list_for_each_entry(s, &state->ipsets, list)
        {
-               del(s->flags, family, family);
-
-               if (fw3_no_family(s->flags[family == FW3_FAMILY_V6]))
-               {
-                       info(" * Deleting ipset %s", s->name);
+               info(" * Deleting ipset %s", s->name);
 
-                       fw3_pr("flush %s\n", s->name);
-                       fw3_pr("destroy %s\n", s->name);
-               }
+               fw3_pr("flush %s\n", s->name);
+               fw3_pr("destroy %s\n", s->name);
        }
+
+       fw3_pr("quit\n");
 }
 
 struct fw3_ipset *