From: Jo-Philipp Wich Date: Thu, 2 May 2013 15:43:32 +0000 (+0200) Subject: Simplify ipset external checks and optionally initialize ispet name from external... X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=78e134ba7cdc473e7cdf0422b863579ac700ac13;p=oweals%2Ffirewall3.git Simplify ipset external checks and optionally initialize ispet name from external value --- diff --git a/ipsets.c b/ipsets.c index 9f43523..b63db21 100644 --- 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; diff --git a/options.c b/options.c index 26aeefe..3d30c57 100644 --- 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); diff --git a/redirects.c b/redirects.c index 24d1356..3c0ffad 100644 --- a/redirects.c +++ b/redirects.c @@ -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 785621f..7f748eb 100644 --- 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 f08443e..5ba5d9e 100644 --- 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);