]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: honor NFT_SET_OBJECT flag
authorPablo Neira Ayuso <pablo@netfilter.org>
Thu, 11 Jul 2019 13:50:13 +0000 (15:50 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 16 Jul 2019 17:53:43 +0000 (19:53 +0200)
This is noticeable when displaying mispelling errors, however, there are
also few spots not checking for the object map flag.

Before:

 # nft flush set inet filter countermxx
 Error: No such file or directory; did you mean set ‘countermap’ in table inet ‘filter’?
 flush set inet filter countermxx
                       ^^^^^^^^^^
After:

 # nft flush set inet filter countermxx
 Error: No such file or directory; did you mean map ‘countermap’ in table inet ‘filter’?
 flush set inet filter countermxx
                       ^^^^^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/evaluate.c
src/json.c
src/rule.c

index e35291d28b6a972e5421cc401d0c28912d664c9f..f95f42e1067a728eb9767fb50f7996d78d1dea66 100644 (file)
@@ -211,7 +211,7 @@ static int set_not_found(struct eval_ctx *ctx, const struct location *loc,
        return cmd_error(ctx, loc,
                         "%s; did you mean %s ‘%s’ in table %s ‘%s’?",
                         strerror(ENOENT),
-                        set->flags & NFT_SET_MAP ? "map" : "set",
+                        set_is_map(set->flags) ? "map" : "set",
                         set->handle.set.name,
                         family2str(set->handle.family),
                         table->handle.table.name);
@@ -3129,7 +3129,7 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
        if (!(set->flags & NFT_SET_INTERVAL) && set->automerge)
                return set_error(ctx, set, "auto-merge only works with interval sets");
 
-       type = set->flags & NFT_SET_MAP ? "map" : "set";
+       type = set_is_map(set->flags) ? "map" : "set";
 
        if (set->key == NULL)
                return set_error(ctx, set, "%s definition does not specify key",
@@ -3560,7 +3560,7 @@ static int cmd_evaluate_get(struct eval_ctx *ctx, struct cmd *cmd)
                        return table_not_found(ctx);
 
                set = set_lookup(table, cmd->handle.set.name);
-               if (set == NULL || set->flags & NFT_SET_MAP)
+               if (set == NULL || set_is_map(set->flags))
                        return set_not_found(ctx, &ctx->cmd->handle.set.location,
                                             ctx->cmd->handle.set.name);
 
index b21677efea9184152bad0ef99cba207764261669..215de65a114a72094247b54d2083b684b4a3eb66 100644 (file)
@@ -1605,14 +1605,13 @@ static json_t *do_list_sets_json(struct netlink_ctx *ctx, struct cmd *cmd)
 
                list_for_each_entry(set, &table->sets, list) {
                        if (cmd->obj == CMD_OBJ_SETS &&
-                           (set->flags & NFT_SET_ANONYMOUS ||
-                           set->flags & NFT_SET_MAP))
+                           !set_is_literal(set->flags))
                                continue;
                        if (cmd->obj == CMD_OBJ_METERS &&
                            !(set->flags & NFT_SET_EVAL))
                                continue;
                        if (cmd->obj == CMD_OBJ_MAPS &&
-                           !(set->flags & NFT_SET_MAP))
+                           !map_is_literal(set->flags))
                                continue;
                        json_array_append_new(root, set_print_json(octx, set));
                }
index 52d8181f0d9238aa17f57a85c92df76a5c01ed25..4e07871a1f65e3d246ecf25680a8b4136206a631 100644 (file)
@@ -1652,14 +1652,13 @@ static int do_list_sets(struct netlink_ctx *ctx, struct cmd *cmd)
 
                list_for_each_entry(set, &table->sets, list) {
                        if (cmd->obj == CMD_OBJ_SETS &&
-                           (set->flags & NFT_SET_ANONYMOUS ||
-                           set->flags & NFT_SET_MAP))
+                           !set_is_literal(set->flags))
                                continue;
                        if (cmd->obj == CMD_OBJ_METERS &&
                            !(set->flags & NFT_SET_EVAL))
                                continue;
                        if (cmd->obj == CMD_OBJ_MAPS &&
-                           !(set->flags & NFT_SET_MAP))
+                           !map_is_literal(set->flags))
                                continue;
                        set_print_declaration(set, &opts, &ctx->nft->output);
                        nft_print(&ctx->nft->output, "%s}%s", opts.tab, opts.nl);