summaryrefslogtreecommitdiffstats
path: root/src/cmd.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2024-08-15 12:34:11 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2024-08-19 17:24:31 +0200
commitbabc6ee8773cfeed78167f78827b35e3141e04c6 (patch)
tree9470ec2b5cc0d0a7b11f37408f579bf3fbb307fe /src/cmd.c
parent161beaeacd2e5218d66febc3db825bf6a27119c5 (diff)
cache: populate chains on demand from error path
Updates on verdict maps that require many non-base chains are slowed down due to fetching existing non-base chains into the cache. Chains are only required for error reporting hints if kernel reports ENOENT. Populate the cache from this error path only. Similar approach already exists from rule ENOENT error path since: deb7c5927fad ("cmd: add misspelling suggestions for rule commands") however, NFT_CACHE_CHAIN was toggled inconditionally for rule commands, rendering this on-demand cache population useless. before this patch, running Neels' nft_slew benchmark (peak values): created idx 4992 in 52587950 ns (128 in 7122 ms) ... deleted idx 128 in 43542500 ns (127 in 6187 ms) after this patch: created idx 4992 in 11361299 ns (128 in 1612 ms) ... deleted idx 1664 in 5239633 ns (128 in 733 ms) Tested-by: Eric Garver <eric@garver.life> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/cmd.c')
-rw-r--r--src/cmd.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/cmd.c b/src/cmd.c
index 37d93abc..381f4042 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -75,6 +75,10 @@ static int nft_cmd_enoent_chain(struct netlink_ctx *ctx, const struct cmd *cmd,
if (!cmd->handle.chain.name)
return 0;
+ if (nft_cache_update(ctx->nft, NFT_CACHE_TABLE | NFT_CACHE_CHAIN,
+ ctx->msgs, NULL) < 0)
+ return 0;
+
chain = chain_lookup_fuzzy(&cmd->handle, &ctx->nft->cache, &table);
/* check table first. */
if (!table)
@@ -271,6 +275,13 @@ static int nft_cmd_chain_error(struct netlink_ctx *ctx, struct cmd *cmd,
return netlink_io_error(ctx, &chain->priority.loc,
"Chains of type \"nat\" must have a priority value above -200");
+ if (nft_cache_update(ctx->nft, NFT_CACHE_TABLE | NFT_CACHE_CHAIN,
+ ctx->msgs, NULL) < 0) {
+ return netlink_io_error(ctx, &chain->loc,
+ "Chain of type \"%s\" is not supported, perhaps kernel support is missing?",
+ chain->type.str);
+ }
+
table = table_cache_find(&ctx->nft->cache.table_cache,
cmd->handle.table.name, cmd->handle.family);
if (table) {