evaluate: allow get/list/flush dynamic sets and maps via list command
Pablo Neira Ayuso
maintainerPATCH v2 1/2 evaluate: allow get/list/flush dynamic sets and maps via list command
Before:
# nft list set ip filter untracked_unknown
Error: No such file or directory; did you mean set ‘untracked_unknown’ in table ip ‘filter’?
list set ip filter untracked_unknown
^^^^^^^^^^^^^^^^^After:
# nft list set ip filter untracked_unknown
table ip filter {
set untracked_unknown {
type ipv4_addr . inet_service . ipv4_addr . inet_service . inet_proto
size 100000
flags dynamic,timeout
}
}Add a testcase for this too.
Reported-by Václav Zindulka <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v2: add testcase.
src/evaluate.c | 6 +++--- tests/shell/testcases/listing/0015dynamic_0 | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100755 tests/shell/testcases/listing/0015dynamic_0
src/evaluate.c +3 -3
@@ -3520,7 +3520,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 |NFT_SET_EVAL )) +if (set ==NULL || set->flags &NFT_SET_MAP )return set_not_found (ctx, &ctx->cmd->handle.set.location, ctx->cmd->handle.set.name);
@@ -3587,7 +3587,7 @@ static int cmd_evaluate_list(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 |NFT_SET_EVAL )) +if (set ==NULL || set->flags &NFT_SET_MAP )return set_not_found (ctx, &ctx->cmd->handle.set.location, ctx->cmd->handle.set.name);
@@ -3698,7 +3698,7 @@ static int cmd_evaluate_flush(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 |NFT_SET_EVAL )) +if (set ==NULL || set->flags &NFT_SET_MAP )return set_not_found (ctx, &ctx->cmd->handle.set.location, ctx->cmd->handle.set.name);
tests/shell/testcases/listing/0015dynamic_0 new file +24 -0
@@ -0,0 +1,24 @@ +#!/bin/bash + +# list only the object asked for with table + +EXPECTED="table ip filter { + set test_set { + type ipv4_addr . inet_service . ipv4_addr . inet_service . inet_proto + size 100000 + flags dynamic,timeout + } +}" + +set -e + +$NFT -f - <<< $EXPECTED + +GET="$($NFT list set ip filter test_set)" +if [ "$EXPECTED" != "$GET" ] ; then + DIFF="$(which diff)" + [ -x $DIFF ] && $DIFF -u <(echo "$EXPECTED") <(echo "$GET") + exit 1 +fi + +$NFT flush set ip filter test_set
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v2 2/2 evaluate: do not allow to list/flush anonymous sets via list command
Don't allow this:
# nft list set x __set0
table ip x {
set __set0 {
type ipv4_addr
flags constant
elements = { 1.1.1.1 }
}
}Anonymous sets never change and they are attached to a rule, do not list their content.
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v2: extend testcase to cover maps. Extend it to cover flush command too.
src/evaluate.c | 19 +++++++++------ tests/shell/testcases/listing/0016anonymous_0 | 33 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) create mode 100755 tests/shell/testcases/listing/0016anonymous_0
src/evaluate.c +12 -7
@@ -3587,7 +3587,8 @@ static int cmd_evaluate_list(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->flags & (NFT_SET_MAP |NFT_SET_ANONYMOUS ))return set_not_found (ctx, &ctx->cmd->handle.set.location, ctx->cmd->handle.set.name);
@@ -3598,7 +3599,8 @@ static int cmd_evaluate_list(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_EVAL )) +if (set ==NULL || !(set->flags &NFT_SET_EVAL ) || + !(set->flags &NFT_SET_ANONYMOUS ))return set_not_found (ctx, &ctx->cmd->handle.set.location, ctx->cmd->handle.set.name);
@@ -3609,7 +3611,8 @@ static int cmd_evaluate_list(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->flags &NFT_SET_MAP ) || + set->flags &NFT_SET_ANONYMOUS )return set_not_found (ctx, &ctx->cmd->handle.set.location, ctx->cmd->handle.set.name);
@@ -3698,10 +3701,10 @@ static int cmd_evaluate_flush(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->flags & (NFT_SET_MAP |NFT_SET_ANONYMOUS )))return set_not_found (ctx, &ctx->cmd->handle.set.location, ctx->cmd->handle.set.name); -return 0 ;case CMD_OBJ_MAP : table =table_lookup (&cmd->handle, &ctx->nft->cache);
@@ -3709,7 +3712,8 @@ static int cmd_evaluate_flush(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->flags &NFT_SET_MAP ) || + set->flags &NFT_SET_ANONYMOUS )return set_not_found (ctx, &ctx->cmd->handle.set.location, ctx->cmd->handle.set.name);
@@ -3720,7 +3724,8 @@ static int cmd_evaluate_flush(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_EVAL )) +if (set ==NULL || !(set->flags &NFT_SET_EVAL ) || + !(set->flags &NFT_SET_ANONYMOUS ))return set_not_found (ctx, &ctx->cmd->handle.set.location, ctx->cmd->handle.set.name);
tests/shell/testcases/listing/0016anonymous_0 new file +33 -0
@@ -0,0 +1,33 @@ +#!/bin/bash + +$NFT add table x +$NFT add chain x y +$NFT add rule x y ip saddr { 1.1.1.1 } +$NFT add rule x y meta mark set ip saddr map { 1.1.1.1 : 2 } + +$NFT list set x __set0 &>/dev/null +ret=$? +if [ $ret -eq 0 ] +then + exit 1 +fi + +$NFT flush set x __set0 &>/dev/null +ret=$? +if [ $ret -eq 0 ] +then + exit 1 +fi + +$NFT list map x __map0 &>/dev/null +if [ $ret -eq 0 ] +then + exit 1 +fi + +$NFT flush map x __map0 &>/dev/null +ret=$? +if [ $ret -eq 0 ] +then + exit 1 +fi
Signature · 1 line
2.11.0