From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nft PATCH 2/3] evaluate: Cache looked up set for list commands
Date: Thu, 15 Jun 2023 16:44:13 +0200 [thread overview]
Message-ID: <20230615144414.1393-3-phil@nwl.cc> (raw)
In-Reply-To: <20230615144414.1393-1-phil@nwl.cc>
Evaluation phase checks the given table and set exist in cache. Relieve
execution phase from having to perform the lookup again by storing the
set reference in cmd->set. Just have to increase the ref counter so
cmd_free() does the right thing (which lacked handling of MAP and METER
objects for some reason).
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
src/evaluate.c | 1 +
src/json.c | 9 ++++++---
src/rule.c | 12 ++++++++----
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index 3983fcaa35880..af7c273c3a0b2 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -5355,6 +5355,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
return cmd_error(ctx, &ctx->cmd->handle.set.location,
"%s", strerror(ENOENT));
+ cmd->set = set_get(set);
return 0;
case CMD_OBJ_CHAIN:
table = table_cache_find(&ctx->nft->cache.table_cache,
diff --git a/src/json.c b/src/json.c
index 981d177b75d4f..12eac36edba93 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1783,10 +1783,13 @@ static json_t *do_list_chains_json(struct netlink_ctx *ctx, struct cmd *cmd)
static json_t *do_list_set_json(struct netlink_ctx *ctx,
struct cmd *cmd, struct table *table)
{
- struct set *set = set_cache_find(table, cmd->handle.set.name);
+ struct set *set = cmd->set;
- if (set == NULL)
- return json_null();
+ if (!set) {
+ set = set_cache_find(table, cmd->handle.set.name);
+ if (set == NULL)
+ return json_null();
+ }
return json_pack("[o]", set_print_json(&ctx->nft->output, set));
}
diff --git a/src/rule.c b/src/rule.c
index 633a5a12486d0..900352d25d6d4 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -1356,6 +1356,8 @@ void cmd_free(struct cmd *cmd)
set_free(cmd->elem.set);
break;
case CMD_OBJ_SET:
+ case CMD_OBJ_MAP:
+ case CMD_OBJ_METER:
case CMD_OBJ_SETELEMS:
set_free(cmd->set);
break;
@@ -2289,11 +2291,13 @@ static void __do_list_set(struct netlink_ctx *ctx, struct cmd *cmd,
static int do_list_set(struct netlink_ctx *ctx, struct cmd *cmd,
struct table *table)
{
- struct set *set;
+ struct set *set = cmd->set;
- set = set_cache_find(table, cmd->handle.set.name);
- if (set == NULL)
- return -1;
+ if (!set) {
+ set = set_cache_find(table, cmd->handle.set.name);
+ if (set == NULL)
+ return -1;
+ }
__do_list_set(ctx, cmd, set);
--
2.40.0
next prev parent reply other threads:[~2023-06-15 14:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-15 14:44 [nft PATCH 0/3] Implement 'reset {set,map,element}' commands Phil Sutter
2023-06-15 14:44 ` [nft PATCH 1/3] evaluate: Merge some cases in cmd_evaluate_list() Phil Sutter
2023-06-15 14:44 ` Phil Sutter [this message]
2023-06-15 14:44 ` [nft PATCH 3/3] Implement 'reset {set,map,element}' commands Phil Sutter
2023-07-13 15:12 ` [nft PATCH 0/3] " Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230615144414.1393-3-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).