summaryrefslogtreecommitdiffstats
path: root/iptables/nft-cmd.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2020-04-27 12:08:59 +0200
committerPhil Sutter <phil@nwl.cc>2020-05-11 14:28:29 +0200
commitea8bb5100a69d1fd39cf737e3bf3acd6631a10f3 (patch)
tree05eb1696f028d446f498635c24d8c7a21e24b810 /iptables/nft-cmd.c
parentf806ee67b5178342d18c8cd3e9201190d8a82c41 (diff)
nft: cache: Optimize caching for flush command
When flushing all chains and verbose mode is not enabled, nft_rule_flush() uses a shortcut: It doesn't specify a chain name for NFT_MSG_DELRULE, so the kernel will flush all existing chains without user space needing to know which they are. The above allows to avoid a chain cache, but there's a caveat: nft_xt_builtin_init() will create base chains as it assumes they are missing and thereby possibly overrides any non-default chain policies. Solve this by making nft_xt_builtin_init() cache-aware: If a command doesn't need a chain cache, there's no need to bother with creating any non-existing builtin chains, either. For the sake of completeness, also do nothing if cache is not initialized (although that shouldn't happen). Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables/nft-cmd.c')
-rw-r--r--iptables/nft-cmd.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/iptables/nft-cmd.c b/iptables/nft-cmd.c
index 23f2761f..9c0901e7 100644
--- a/iptables/nft-cmd.c
+++ b/iptables/nft-cmd.c
@@ -167,7 +167,10 @@ int nft_cmd_rule_flush(struct nft_handle *h, const char *chain,
if (!cmd)
return 0;
- nft_cache_level_set(h, NFT_CL_CHAINS, cmd);
+ if (chain || verbose)
+ nft_cache_level_set(h, NFT_CL_CHAINS, cmd);
+ else
+ nft_cache_level_set(h, NFT_CL_TABLES, cmd);
return 1;
}