introduce support for enabled option in zones, forwards, rules, redirects, ipsets...
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 2 Mar 2013 17:02:58 +0000 (18:02 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 2 Mar 2013 17:02:58 +0000 (18:02 +0100)
forwards.c
includes.c
ipsets.c
options.h
redirects.c
rules.c
zones.c

index e01f1266ed721baca25678c772d5f42b9ec06202..158ccbffdcabce7b0522adf594576b22c28802c3 100644 (file)
@@ -20,6 +20,8 @@
 
 
 const struct fw3_option fw3_forward_opts[] = {
+       FW3_OPT("enabled",             bool,     forward,     enabled),
+
        FW3_OPT("name",                string,   forward,     name),
        FW3_OPT("family",              family,   forward,     family),
 
@@ -53,8 +55,16 @@ fw3_load_forwards(struct fw3_state *state, struct uci_package *p)
 
                memset(forward, 0, sizeof(*forward));
 
+               forward->enabled = true;
+
                fw3_parse_options(forward, fw3_forward_opts, s);
 
+               if (!forward->enabled)
+               {
+                       fw3_free_forward(forward);
+                       continue;
+               }
+
                if (forward->src.invert || forward->dest.invert)
                {
                        warn_elem(e, "must not have inverted 'src' or 'dest' options");
index 40995ca49c5e4738f2c6be733da019068b84b1b3..4221def04407e57feda25111417b39b2cb7b9106 100644 (file)
@@ -20,6 +20,8 @@
 
 
 const struct fw3_option fw3_include_opts[] = {
+       FW3_OPT("enabled",             bool,           include,     enabled),
+
        FW3_OPT("path",                string,         include,     path),
        FW3_OPT("type",                include_type,   include,     type),
        FW3_OPT("family",              family,         include,     family),
@@ -50,10 +52,18 @@ fw3_load_includes(struct fw3_state *state, struct uci_package *p)
                        continue;
 
                memset(include, 0, sizeof(*include));
+
                include->name = e->name;
+               include->enabled = true;
 
                fw3_parse_options(include, fw3_include_opts, s);
 
+               if (!include->enabled)
+               {
+                       fw3_free_include(include);
+                       continue;
+               }
+
                if (!include->path)
                {
                        warn_elem(e, "must specify a path");
index a720172652bda0404b4e5bf647ba84313ff01d3a..62877c8456622a2e9e8b615cd29d9d13a872e5ea 100644 (file)
--- a/ipsets.c
+++ b/ipsets.c
@@ -20,6 +20,8 @@
 
 
 const struct fw3_option fw3_ipset_opts[] = {
+       FW3_OPT("enabled",       bool,           ipset,     enabled),
+
        FW3_OPT("name",          string,         ipset,     name),
        FW3_OPT("family",        family,         ipset,     family),
 
index 96afcd2dda4730051d0ec272e9d6c4b420621683..2af443b6fbf03d5ae26e76da801b73e0f917d11e 100644 (file)
--- a/options.h
+++ b/options.h
@@ -245,6 +245,7 @@ struct fw3_zone
        struct list_head list;
        struct list_head running_list;
 
+       bool enabled;
        const char *name;
 
        enum fw3_family family;
@@ -280,6 +281,7 @@ struct fw3_rule
 {
        struct list_head list;
 
+       bool enabled;
        const char *name;
 
        enum fw3_family family;
@@ -316,6 +318,7 @@ struct fw3_redirect
 {
        struct list_head list;
 
+       bool enabled;
        const char *name;
 
        enum fw3_family family;
@@ -354,6 +357,7 @@ struct fw3_forward
 {
        struct list_head list;
 
+       bool enabled;
        const char *name;
 
        enum fw3_family family;
@@ -370,6 +374,7 @@ struct fw3_ipset
        struct list_head list;
        struct list_head running_list;
 
+       bool enabled;
        const char *name;
        enum fw3_family family;
 
@@ -395,6 +400,7 @@ struct fw3_include
        struct list_head list;
        struct list_head running_list;
 
+       bool enabled;
        const char *name;
        enum fw3_family family;
 
index 2aa666486b580569120013e93af0fd481b58a9b2..2acfabc34cedad23a90a93450b896ac6aca83351 100644 (file)
@@ -20,6 +20,8 @@
 
 
 const struct fw3_option fw3_redirect_opts[] = {
+       FW3_OPT("enabled",             bool,      redirect,     enabled),
+
        FW3_OPT("name",                string,    redirect,     name),
        FW3_OPT("family",              family,    redirect,     family),
 
@@ -131,10 +133,17 @@ fw3_load_redirects(struct fw3_state *state, struct uci_package *p)
                INIT_LIST_HEAD(&redir->proto);
                INIT_LIST_HEAD(&redir->mac_src);
 
+               redir->enabled = true;
                redir->reflection = true;
 
                fw3_parse_options(redir, fw3_redirect_opts, s);
 
+               if (!redir->enabled)
+               {
+                       fw3_free_redirect(redir);
+                       continue;
+               }
+
                if (redir->src.invert)
                {
                        warn_elem(e, "must not have an inverted source");
diff --git a/rules.c b/rules.c
index e733cd9848944ccd45a6aa349e662b4b7f5b9005..c3f03cf76377eba22235cf3fa873734ed3bcb965 100644 (file)
--- a/rules.c
+++ b/rules.c
@@ -20,6 +20,8 @@
 
 
 const struct fw3_option fw3_rule_opts[] = {
+       FW3_OPT("enabled",             bool,      rule,     enabled),
+
        FW3_OPT("name",                string,    rule,     name),
        FW3_OPT("family",              family,    rule,     family),
 
@@ -91,8 +93,16 @@ fw3_load_rules(struct fw3_state *state, struct uci_package *p)
 
                INIT_LIST_HEAD(&rule->icmp_type);
 
+               rule->enabled = true;
+
                fw3_parse_options(rule, fw3_rule_opts, s);
 
+               if (!rule->enabled)
+               {
+                       fw3_free_rule(rule);
+                       continue;
+               }
+
                if (rule->src.invert || rule->dest.invert)
                {
                        warn_elem(e, "must not have inverted 'src' or 'dest' options");
diff --git a/zones.c b/zones.c
index e6c88db7945e77db00dc459ff69507c47470d576..82b76b4ea6c1834e459a3a17d20415120332de3d 100644 (file)
--- a/zones.c
+++ b/zones.c
@@ -50,6 +50,8 @@ static const struct chain dst_chains[] = {
 };
 
 const struct fw3_option fw3_zone_opts[] = {
+       FW3_OPT("enabled",             bool,     zone,     enabled),
+
        FW3_OPT("name",                string,   zone,     name),
        FW3_OPT("family",              family,   zone,     family),
 
@@ -162,6 +164,7 @@ fw3_alloc_zone(void)
        INIT_LIST_HEAD(&zone->masq_src);
        INIT_LIST_HEAD(&zone->masq_dest);
 
+       zone->enabled = true;
        zone->log_limit.rate = 10;
 
        return zone;
@@ -191,6 +194,12 @@ fw3_load_zones(struct fw3_state *state, struct uci_package *p)
 
                fw3_parse_options(zone, fw3_zone_opts, s);
 
+               if (!zone->enabled)
+               {
+                       fw3_free_zone(zone);
+                       continue;
+               }
+
                if (!zone->extra_dest)
                        zone->extra_dest = zone->extra_src;