]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: Fold nftnl_rule_list_chain_save() into caller
authorPhil Sutter <phil@nwl.cc>
Wed, 8 Jul 2020 21:03:12 +0000 (23:03 +0200)
committerPhil Sutter <phil@nwl.cc>
Fri, 21 Aug 2020 17:01:00 +0000 (19:01 +0200)
Existence of this function was mostly code-duplication: Caller already
branches depending on whether 'chain' is NULL or not and even does the
chain list lookup.

While being at it, simplify __nftnl_rule_list_chain_save function name a
bit now that the non-prefixed name is gone.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/nft.c

index 8d53d43770f818e8448772b74da394ff3654050c..dd66b98e5004c98ad8f95c47de682390e224ec1f 100644 (file)
@@ -2423,7 +2423,7 @@ list_save(struct nft_handle *h, struct nftnl_rule *r,
        nft_rule_print_save(h, r, NFT_RULE_APPEND, format);
 }
 
-static int __nftnl_rule_list_chain_save(struct nftnl_chain *c, void *data)
+static int nft_rule_list_chain_save(struct nftnl_chain *c, void *data)
 {
        const char *chain_name = nftnl_chain_get_str(c, NFTNL_CHAIN_NAME);
        uint32_t policy = nftnl_chain_get_u32(c, NFTNL_CHAIN_POLICY);
@@ -2445,25 +2445,6 @@ static int __nftnl_rule_list_chain_save(struct nftnl_chain *c, void *data)
        return 0;
 }
 
-static int
-nftnl_rule_list_chain_save(struct nft_handle *h, const char *chain,
-                          struct nftnl_chain_list *list, int counters)
-{
-       struct nftnl_chain *c;
-
-       if (chain) {
-               c = nftnl_chain_list_lookup_byname(list, chain);
-               if (!c)
-                       return 0;
-
-               __nftnl_rule_list_chain_save(c, &counters);
-               return 1;
-       }
-
-       nftnl_chain_list_foreach(list, __nftnl_rule_list_chain_save, &counters);
-       return 1;
-}
-
 int nft_rule_list_save(struct nft_handle *h, const char *chain,
                       const char *table, int rulenum, int counters)
 {
@@ -2484,10 +2465,6 @@ int nft_rule_list_save(struct nft_handle *h, const char *chain,
        if (!list)
                return 0;
 
-       /* Dump policies and custom chains first */
-       if (!rulenum)
-               nftnl_rule_list_chain_save(h, chain, list, counters);
-
        if (counters < 0)
                d.format = FMT_C_COUNTS;
        else if (counters == 0)
@@ -2498,9 +2475,15 @@ int nft_rule_list_save(struct nft_handle *h, const char *chain,
                if (!c)
                        return 0;
 
+               if (!rulenum)
+                       nft_rule_list_chain_save(c, &counters);
+
                return nft_rule_list_cb(c, &d);
        }
 
+       /* Dump policies and custom chains first */
+       nftnl_chain_list_foreach(list, nft_rule_list_chain_save, &counters);
+
        /* Now dump out rules in this table */
        ret = nftnl_chain_list_foreach(list, nft_rule_list_cb, &d);
        return ret == 0 ? 1 : 0;