make enum values unique to allow using them in bitfields directly, increase flag...
authorJo-Philipp Wich <jow@openwrt.org>
Tue, 19 Feb 2013 18:29:04 +0000 (19:29 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Tue, 19 Feb 2013 21:29:21 +0000 (22:29 +0100)
defaults.c
main.c
options.h
utils.c
zones.c

index d59c5bffb2a094aa19796a98e39f86e9f8c6991e..3e8ea40f164404fb6e2ccaabd2a80239c1e2959c 100644 (file)
@@ -87,7 +87,7 @@ static struct fw3_option default_opts[] = {
 
 static bool
 print_chains(enum fw3_table table, enum fw3_family family,
-             const char *fmt, uint8_t flags,
+             const char *fmt, uint16_t flags,
              const struct chain *chains, int n)
 {
        bool rv = false;
@@ -142,7 +142,7 @@ fw3_load_defaults(struct fw3_state *state, struct uci_package *p)
        defs->tcp_window_scaling   = true;
        defs->custom_chains        = true;
 
-       setbit(defs->flags, FW3_DEFAULT_IPV4_LOADED);
+       setbit(defs->flags, FW3_FAMILY_V4);
 
        uci_foreach_element(&p->sections, e)
        {
@@ -165,7 +165,7 @@ fw3_load_defaults(struct fw3_state *state, struct uci_package *p)
                check_policy(e, &defs->policy_forward, "forward");
 
                if (!defs->disable_ipv6)
-                       setbit(defs->flags, FW3_DEFAULT_IPV6_LOADED);
+                       setbit(defs->flags, FW3_FAMILY_V6);
 
                if (defs->custom_chains)
                        setbit(defs->flags, FW3_DEFAULT_CUSTOM_CHAINS);
diff --git a/main.c b/main.c
index 65afacd161f2d55b7520f6dc5dbfbe5d7a7c4775..2dd1f86f02c13d52c001734ddbcd70926e6e1389 100644 (file)
--- a/main.c
+++ b/main.c
@@ -131,9 +131,6 @@ restore_pipe(enum fw3_family family, bool silent)
        return true;
 }
 
-#define family_flag(f) \
-       (f == FW3_FAMILY_V4 ? FW3_DEFAULT_IPV4_LOADED : FW3_DEFAULT_IPV6_LOADED)
-
 static bool
 family_running(struct list_head *statefile, enum fw3_family family)
 {
@@ -146,7 +143,7 @@ family_running(struct list_head *statefile, enum fw3_family family)
                        if (e->type != FW3_TYPE_DEFAULTS)
                                continue;
 
-                       return hasbit(e->flags[0], family_flag(family));
+                       return hasbit(e->flags[0], family);
                }
        }
 
@@ -162,16 +159,16 @@ family_used(enum fw3_family family)
 static bool
 family_loaded(struct fw3_state *state, enum fw3_family family)
 {
-       return hasbit(state->defaults.flags, family_flag(family));
+       return hasbit(state->defaults.flags, family);
 }
 
 static void
 family_set(struct fw3_state *state, enum fw3_family family, bool set)
 {
        if (set)
-               setbit(state->defaults.flags, family_flag(family));
+               setbit(state->defaults.flags, family);
        else
-               delbit(state->defaults.flags, family_flag(family));
+               delbit(state->defaults.flags, family);
 }
 
 static int
index ced138ad2c0ab1ebf6d13b90edebff4506326b98..ea5082dcdf1b19ae69464fe76128a6447540d1e8 100644 (file)
--- a/options.h
+++ b/options.h
@@ -55,30 +55,28 @@ enum fw3_table
 enum fw3_family
 {
        FW3_FAMILY_ANY = 0,
-       FW3_FAMILY_V4  = 1,
-       FW3_FAMILY_V6  = 2,
+       FW3_FAMILY_V4  = 4,
+       FW3_FAMILY_V6  = 5,
 };
 
 enum fw3_target
 {
        FW3_TARGET_UNSPEC  = 0,
-       FW3_TARGET_ACCEPT  = 1,
-       FW3_TARGET_REJECT  = 2,
-       FW3_TARGET_DROP    = 3,
-       FW3_TARGET_NOTRACK = 4,
-       FW3_TARGET_DNAT    = 5,
-       FW3_TARGET_SNAT    = 6,
+       FW3_TARGET_ACCEPT  = 6,
+       FW3_TARGET_REJECT  = 7,
+       FW3_TARGET_DROP    = 8,
+       FW3_TARGET_NOTRACK = 9,
+       FW3_TARGET_DNAT    = 10,
+       FW3_TARGET_SNAT    = 11,
 };
 
 enum fw3_default
 {
        FW3_DEFAULT_UNSPEC        = 0,
-       FW3_DEFAULT_CUSTOM_CHAINS = 1,
-       FW3_DEFAULT_SYN_FLOOD     = 2,
-       FW3_DEFAULT_MTU_FIX       = 3,
-       FW3_DEFAULT_DROP_INVALID  = 4,
-       FW3_DEFAULT_IPV4_LOADED   = 5,
-       FW3_DEFAULT_IPV6_LOADED   = 6,
+       FW3_DEFAULT_CUSTOM_CHAINS = 12,
+       FW3_DEFAULT_SYN_FLOOD     = 13,
+       FW3_DEFAULT_MTU_FIX       = 14,
+       FW3_DEFAULT_DROP_INVALID  = 15,
 };
 
 enum fw3_limit_unit
@@ -212,7 +210,7 @@ struct fw3_defaults
 
        bool disable_ipv6;
 
-       uint8_t flags;
+       uint16_t flags;
 };
 
 struct fw3_zone
@@ -246,8 +244,8 @@ struct fw3_zone
 
        bool custom_chains;
 
-       uint8_t src_flags;
-       uint8_t dst_flags;
+       uint16_t src_flags;
+       uint16_t dst_flags;
 };
 
 struct fw3_rule
@@ -356,6 +354,8 @@ struct fw3_ipset
        int timeout;
 
        const char *external;
+
+       uint16_t flags;
 };
 
 struct fw3_state
diff --git a/utils.c b/utils.c
index f43a859bbb038b86cce8839552281531c5e1dbf8..9b62789a3dcc7f902c329fed6c46cadf1fc6d138 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -403,7 +403,7 @@ fw3_write_statefile(void *state)
        struct fw3_zone *z;
        struct fw3_ipset *i;
 
-       int mask = (1 << FW3_DEFAULT_IPV4_LOADED) | (1 << FW3_DEFAULT_IPV6_LOADED);
+       int mask = (1 << FW3_FAMILY_V4) | (1 << FW3_FAMILY_V6);
 
        if (!(d->flags & mask))
        {
@@ -435,7 +435,7 @@ fw3_write_statefile(void *state)
                if (i->external && *i->external)
                        continue;
 
-               fprintf(sf, "%u %s\n", FW3_TYPE_IPSET, i->name);
+               fprintf(sf, "%u %s %u\n", FW3_TYPE_IPSET, i->name, i->flags);
        }
 
        fclose(sf);
diff --git a/zones.c b/zones.c
index 3195a32d4c90433134e1aed3b9b9b4022b2078b9..fbde74ef63de70a72c227338bd5157482f9853f9 100644 (file)
--- a/zones.c
+++ b/zones.c
@@ -81,7 +81,7 @@ static struct fw3_option zone_opts[] = {
 
 static bool
 print_chains(enum fw3_table table, enum fw3_family family,
-             const char *fmt, const char *name, uint8_t targets,
+             const char *fmt, const char *name, uint16_t targets,
              const struct chain *chains, int n)
 {
        bool rv = false;