From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft,v2 2/2] evaluate: do not allow to list/flush anonymous sets via list command
Date: Tue, 18 Jun 2019 16:44:00 +0200 [thread overview]
Message-ID: <20190618144400.31411-2-pablo@netfilter.org> (raw)
In-Reply-To: <20190618144400.31411-1-pablo@netfilter.org>
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 <pablo@netfilter.org>
---
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
diff --git a/src/evaluate.c b/src/evaluate.c
index 07617a7c94cb..5b1946a1fd09 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -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);
diff --git a/tests/shell/testcases/listing/0016anonymous_0 b/tests/shell/testcases/listing/0016anonymous_0
new file mode 100755
index 000000000000..83acbccae7db
--- /dev/null
+++ b/tests/shell/testcases/listing/0016anonymous_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
--
2.11.0
prev parent reply other threads:[~2019-06-18 14:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-18 14:43 [PATCH nft,v2 1/2] evaluate: allow get/list/flush dynamic sets and maps via list command Pablo Neira Ayuso
2019-06-18 14:44 ` Pablo Neira Ayuso [this message]
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=20190618144400.31411-2-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.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).