summaryrefslogtreecommitdiffstats
path: root/iptables/nft.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2020-07-08 23:03:12 +0200
committerPhil Sutter <phil@nwl.cc>2020-08-21 19:01:00 +0200
commitc330a2198e86d757e1d553f7e1d64baa2f10d7a9 (patch)
treed3fc64a38fad497549fc632ac7ff349e11c66a76 /iptables/nft.c
parent79ada320d0cca026f199ae8f39737c1e95991615 (diff)
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 <phil@nwl.cc>
Diffstat (limited to 'iptables/nft.c')
-rw-r--r--iptables/nft.c31
1 files 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;