Introduce fw3_no_family() helper macro and use it
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 10 Mar 2013 19:29:48 +0000 (20:29 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 10 Mar 2013 19:31:34 +0000 (20:31 +0100)
ipsets.c
utils.c
utils.h
zones.c

index d6ff9bd272a7dc3d5b96773be473a34e9664cd1a..a987790e4b5bede54321743f7660f4063cb9c2da 100644 (file)
--- a/ipsets.c
+++ b/ipsets.c
@@ -376,14 +376,13 @@ void
 fw3_destroy_ipsets(struct fw3_state *state, enum fw3_family family)
 {
        struct fw3_ipset *s, *tmp;
-       uint32_t family_mask = (1 << FW3_FAMILY_V4) | (1 << FW3_FAMILY_V6);
 
        list_for_each_entry_safe(s, tmp, &state->running_ipsets, running_list)
        {
                if (hasbit(s->running_flags, family))
                        delbit(s->flags, family);
 
-               if (!(s->flags & family_mask))
+               if (fw3_no_family(s))
                {
                        info("Deleting ipset %s", s->name);
 
diff --git a/utils.c b/utils.c
index ce9049ee289948b2044fa0765938b89086108402..2747a853a8b99f9b4e021b2c867092f8fd4d3156 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -441,9 +441,7 @@ fw3_write_statefile(void *state)
        struct fw3_zone *z;
        struct fw3_ipset *i;
 
-       int mask = (1 << FW3_FAMILY_V4) | (1 << FW3_FAMILY_V6);
-
-       if (!(d->flags & mask))
+       if (fw3_no_family(d))
        {
                if (unlink(FW3_STATEFILE))
                        warn("Unable to remove state %s: %s",
diff --git a/utils.h b/utils.h
index 43f30f46480de0a8ab546b98798813fdeed47c8f..79bf394677e0faa6a2750039c89f8f8658129c91 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -55,6 +55,9 @@ void info(const char *format, ...);
 #define fw3_is_family(p, f)                                                \
        (!p || (p)->family == FW3_FAMILY_ANY || (p)->family == f)
 
+#define fw3_no_family(p)                                                   \
+       (!p || !((p)->flags & ((1 << FW3_FAMILY_V4) | (1 << FW3_FAMILY_V6))))
+
 const char * fw3_find_command(const char *cmd);
 
 bool fw3_stdout_pipe(void);
diff --git a/zones.c b/zones.c
index c47391ca6b8cd7a9a64d29898d7afa86858e3daa..ab656ef75381e82d8dec10b04a9593250547099b 100644 (file)
--- a/zones.c
+++ b/zones.c
@@ -540,7 +540,6 @@ fw3_flush_zones(enum fw3_table table, enum fw3_family family,
 {
        struct fw3_zone *z, *tmp;
        uint32_t custom_mask = ~0;
-       uint32_t family_mask = (1 << FW3_FAMILY_V4) | (1 << FW3_FAMILY_V6);
 
        /* don't touch user chains on selective stop */
        if (reload)
@@ -566,7 +565,7 @@ fw3_flush_zones(enum fw3_table table, enum fw3_family family,
                {
                        delbit(z->flags, family);
 
-                       if (!(z->flags & family_mask))
+                       if (fw3_no_family(z))
                                fw3_set_running(z, NULL);
                }
        }