]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: Cache looked up set for list commands
authorPhil Sutter <phil@nwl.cc>
Wed, 14 Jun 2023 15:40:02 +0000 (17:40 +0200)
committerPhil Sutter <phil@nwl.cc>
Thu, 13 Jul 2023 14:57:54 +0000 (16:57 +0200)
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
src/json.c
src/rule.c

index d4942e2b58d9702ec21fdfa9f62ace5b5d6d6019..3dc2be0d0df5451249663a254eaadd5348be194a 100644 (file)
@@ -5374,6 +5374,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,
index 21199ca467d606f35b4329072bc5949cb3a63978..a119dfc4f1eb41b6e6b91b885e19f6e650c96f44 100644 (file)
@@ -1799,10 +1799,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));
 }
index 19d681bb74b3a1b984894a7fee2a8f3128c5a546..18a566f9fc62e0994589ad96395547d7fc0203e1 100644 (file)
@@ -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;
@@ -2283,11 +2285,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);