]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: Use nft_chain_find() in two more places
authorPhil Sutter <phil@nwl.cc>
Tue, 7 Jul 2020 16:35:26 +0000 (18:35 +0200)
committerPhil Sutter <phil@nwl.cc>
Fri, 24 Jul 2020 17:16:15 +0000 (19:16 +0200)
This doesn't really increase functions' readability but prepares for
later changes.

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

index c6cfecda1846aade0a39f161451266e9e16314f9..cc1260dc627d03444baca36ad442d81a66a63c09 100644 (file)
@@ -1678,20 +1678,13 @@ int nft_rule_flush(struct nft_handle *h, const char *chain, const char *table,
 
        nft_fn = nft_rule_flush;
 
-       if (chain || verbose) {
+       if (chain || verbose)
                nft_xt_builtin_init(h, table);
-
-               list = nft_chain_list_get(h, table, chain);
-               if (list == NULL) {
-                       ret = 1;
-                       goto err;
-               }
-       } else if (!nft_table_find(h, table)) {
+       else if (!nft_table_find(h, table))
                return 1;
-       }
 
        if (chain) {
-               c = nftnl_chain_list_lookup_byname(list, chain);
+               c = nft_chain_find(h, table, chain);
                if (!c) {
                        errno = ENOENT;
                        return 0;
@@ -1705,6 +1698,12 @@ int nft_rule_flush(struct nft_handle *h, const char *chain, const char *table,
                return 1;
        }
 
+       list = nft_chain_list_get(h, table, chain);
+       if (list == NULL) {
+               ret = 1;
+               goto err;
+       }
+
        iter = nftnl_chain_list_iter_create(list);
        if (iter == NULL) {
                ret = 1;
@@ -2437,12 +2436,8 @@ int nft_rule_list(struct nft_handle *h, const char *chain, const char *table,
        nft_xt_builtin_init(h, table);
        nft_assert_table_compatible(h, table, chain);
 
-       list = nft_chain_list_get(h, table, chain);
-       if (!list)
-               return 0;
-
        if (chain) {
-               c = nftnl_chain_list_lookup_byname(list, chain);
+               c = nft_chain_find(h, table, chain);
                if (!c)
                        return 0;
 
@@ -2455,6 +2450,10 @@ int nft_rule_list(struct nft_handle *h, const char *chain, const char *table,
                return 1;
        }
 
+       list = nft_chain_list_get(h, table, chain);
+       if (!list)
+               return 0;
+
        iter = nftnl_chain_list_iter_create(list);
        if (iter == NULL)
                return 0;