From c330a2198e86d757e1d553f7e1d64baa2f10d7a9 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Wed, 8 Jul 2020 23:03:12 +0200 Subject: nft: Fold nftnl_rule_list_chain_save() into caller 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 --- iptables/nft.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/iptables/nft.c b/iptables/nft.c index 8d53d437..dd66b98e 100644 --- a/iptables/nft.c +++ b/iptables/nft.c @@ -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; -- cgit v1.2.3