From 6e6afb0c7d4d69e4a48122664645c8de67f34c96 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 19 Feb 2013 19:29:04 +0100 Subject: [PATCH] make enum values unique to allow using them in bitfields directly, increase flag members to 16 bit --- defaults.c | 6 +++--- main.c | 11 ++++------- options.h | 34 +++++++++++++++++----------------- utils.c | 4 ++-- zones.c | 2 +- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/defaults.c b/defaults.c index d59c5bf..3e8ea40 100644 --- a/defaults.c +++ b/defaults.c @@ -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 65afacd..2dd1f86 100644 --- 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 diff --git a/options.h b/options.h index ced138a..ea5082d 100644 --- 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 f43a859..9b62789 100644 --- 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 3195a32..fbde74e 100644 --- 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; -- 2.25.1