From: Phil Sutter Date: Tue, 7 Jul 2020 16:35:26 +0000 (+0200) Subject: nft: Use nft_chain_find() in two more places X-Git-Tag: v1.8.6~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b906191d4b5d2606df892855e53b0b62e53e7728;p=thirdparty%2Fiptables.git nft: Use nft_chain_find() in two more places This doesn't really increase functions' readability but prepares for later changes. Signed-off-by: Phil Sutter --- diff --git a/iptables/nft.c b/iptables/nft.c index c6cfecda..cc1260dc 100644 --- a/iptables/nft.c +++ b/iptables/nft.c @@ -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;