From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: fw@strlen.de, arturo@netfilter.org, phil@nwl.cc
Subject: [PATCH nft] evaluate: disallow anonymous set with empty elements
Date: Tue, 9 Apr 2019 12:59:36 +0200 [thread overview]
Message-ID: <20190409105936.23422-1-pablo@netfilter.org> (raw)
Restrict this, the brackets have explicit semantics since they tell the
kernel to represent this value as a set, which is too costly. Set for
one single element are overkill.
# nft add rule x y ct state { established } counter
Error: anonymous set with single element makes no sense, remove brackets wrapping this value
add rule x y ct state { established } counter
^^^^^^^^^^^^^^^
Instead, the preferred way to express this is:
# nft add rule x y ct state established counter
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
I know this may break stuff outthere, but probably it's still early to
fix this. If we keep allowing this and transparently turn this into a
value, people will likely never understand the bracket semantics.
Brackets are not just syntaxic sugar.
src/evaluate.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/evaluate.c b/src/evaluate.c
index 3a3f2468c826..aa42c69127a2 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1253,8 +1253,11 @@ static int expr_evaluate_set_elem(struct eval_ctx *ctx, struct expr **expr)
static int expr_evaluate_set(struct eval_ctx *ctx, struct expr **expr)
{
struct expr *set = *expr, *i, *next;
+ unsigned int count = 0;
list_for_each_entry_safe(i, next, &set->expressions, list) {
+ count++;
+
if (list_member_evaluate(ctx, &i) < 0)
return -1;
@@ -1288,6 +1291,11 @@ static int expr_evaluate_set(struct eval_ctx *ctx, struct expr **expr)
set->set_flags |= NFT_SET_INTERVAL;
}
+ if (set->flags & NFT_SET_ANONYMOUS &&
+ count == 1)
+ return expr_error(ctx->msgs, set,
+ "anonymous set with one single element makes no sense, remove brackets wrapping this value");
+
set->set_flags |= NFT_SET_CONSTANT;
set->dtype = ctx->ectx.dtype;
--
2.11.0
next reply other threads:[~2019-04-09 10:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-09 10:59 Pablo Neira Ayuso [this message]
2019-04-09 13:02 ` [PATCH nft] evaluate: disallow anonymous set with empty elements Pablo Neira Ayuso
2019-04-09 13:59 ` Phil Sutter
2019-04-09 14:03 ` Florian Westphal
2019-04-09 23:19 ` Pablo Neira Ayuso
2019-04-10 13:37 ` Phil Sutter
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=20190409105936.23422-1-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=arturo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=phil@nwl.cc \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.