Simplify ipset external checks and optionally initialize ispet name from external...
authorJo-Philipp Wich <jow@openwrt.org>
Thu, 2 May 2013 15:43:32 +0000 (17:43 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Thu, 2 May 2013 15:43:32 +0000 (17:43 +0200)
ipsets.c
options.c
redirects.c
rules.c
utils.c

index 9f4352346944f45acbd0c4db502d39142c221a9e..b63db218aead1ea0761a2c2756eb737af619ba8c 100644 (file)
--- a/ipsets.c
+++ b/ipsets.c
@@ -126,7 +126,7 @@ check_types(struct uci_element *e, struct fw3_ipset *ipset)
                if (ipset_types[i].method == ipset->method &&
                    ipset_types[i].types == typelist)
                {
-                       if (!ipset->external || !*ipset->external)
+                       if (!ipset->external)
                        {
                                if ((ipset_types[i].required & OPT_IPRANGE) &&
                                        !ipset->iprange.set)
@@ -238,6 +238,14 @@ fw3_load_ipsets(struct fw3_state *state, struct uci_package *p)
 
                fw3_parse_options(ipset, fw3_ipset_opts, s);
 
+               if (ipset->external)
+               {
+                       if (!*ipset->external)
+                               ipset->external = NULL;
+                       else if (!ipset->name)
+                               ipset->name = ipset->external;
+               }
+
                if (!ipset->name || !*ipset->name)
                {
                        warn_elem(e, "must have a name assigned");
@@ -268,7 +276,7 @@ create_ipset(struct fw3_ipset *ipset, struct fw3_state *state)
 
        struct fw3_ipset_datatype *type;
 
-       if (ipset->external && *ipset->external)
+       if (ipset->external)
                return;
 
        info(" * Creating ipset %s", ipset->name);
@@ -382,7 +390,7 @@ fw3_check_ipset(struct fw3_ipset *set)
        req_name.op = IP_SET_OP_GET_BYNAME;
        req_name.version = req_ver.version;
        snprintf(req_name.set.name, IPSET_MAXNAMELEN - 1, "%s",
-                (set->external && *set->external) ? set->external : set->name);
+                set->external ? set->external : set->name);
 
        if (getsockopt(s, SOL_IP, SO_IP_SET, &req_name, &sz))
                goto out;
index 26aeefe630014a4bce14f6faa75987e944113772..3d30c57c5f86ae736d64c3490ef141971cdc7c6f 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1057,10 +1057,7 @@ fw3_format_ipset(struct fw3_ipset *ipset, bool invert)
        if (!ipset)
                return;
 
-       if (ipset->external && *ipset->external)
-               name = ipset->external;
-       else
-               name = ipset->name;
+       name = ipset->external ? ipset->external : ipset->name;
 
        fw3_pr(" -m set %s--match-set %s", invert ? "! " : "", name);
 
index 24d13569b4d1a4b94c6dd58732af046137e99c96..3c0ffada64fc8978a3aa7ff90766db652f9b295f 100644 (file)
@@ -375,7 +375,7 @@ print_redirect(struct fw3_state *state, enum fw3_family family,
                if (!fw3_check_ipset(redir->_ipset))
                {
                        info("     ! Skipping due to missing ipset '%s'",
-                            (redir->_ipset->external && *redir->_ipset->external) ?
+                            redir->_ipset->external ?
                                        redir->_ipset->external : redir->_ipset->name);
                        return;
                }
diff --git a/rules.c b/rules.c
index 785621fedb735059b00acc3e64d2bb21a5426be6..7f748ebb043fb96028d3598fc5f93c94ace3d137 100644 (file)
--- a/rules.c
+++ b/rules.c
@@ -368,8 +368,8 @@ expand_rule(struct fw3_state *state, enum fw3_family family,
                if (!fw3_check_ipset(rule->_ipset))
                {
                        info("     ! Skipping due to missing ipset '%s'",
-                            (rule->_ipset->external && *rule->_ipset->external) ?
-                                       rule->_ipset->external : rule->_ipset->name);
+                            rule->_ipset->external
+                                       rule->_ipset->external : rule->_ipset->name);
                        return;
                }
 
diff --git a/utils.c b/utils.c
index f08443ea8177dc07f4a96f59d3903f96710199bd..5ba5d9e3c9c51edf321325b836f8d842048a3674 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -514,7 +514,7 @@ write_ipset_uci(struct uci_context *ctx, struct fw3_ipset *s,
 
        struct uci_ptr ptr = { .p = dest };
 
-       if (!s->enabled || (s->external && *s->external))
+       if (!s->enabled || s->external)
                return;
 
        uci_add_section(ctx, dest, "ipset", &ptr.s);