[PATCH nft 4/5] evaluate: honor NFT_SET_OBJECT flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
---
 src/evaluate.c | 6 +++---
 src/json.c     | 5 ++---
 src/rule.c     | 5 ++---
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/evaluate.c b/src/evaluate.c
index e35291d28b6a..f95f42e1067a 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -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);
 
diff --git a/src/json.c b/src/json.c
index b21677efea91..215de65a114a 100644
--- a/src/json.c
+++ b/src/json.c
@@ -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));
 		}
diff --git a/src/rule.c b/src/rule.c
index 52d8181f0d92..4e07871a1f65 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -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);
-- 
2.11.0




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux