netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] evaluate: error reporting for missing statements in set/map declaration
Date: Mon, 26 Jul 2021 18:38:21 +0200	[thread overview]
Message-ID: <20210726163821.10869-1-pablo@netfilter.org> (raw)

Assuming this map:

        map y {
                type ipv4_addr : verdict
        }

This patch slightly improves error reporting to refer to the missing
'counter' statement in the map declaration.

 # nft 'add element x y { 1.2.3.4 counter packets 1 bytes 1 : accept, * counter : drop }'
 Error: missing statement in map declaration
 add element x y { 1.2.3.4 counter packets 10 bytes 640 : accept, * counter : drop }
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/evaluate.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/evaluate.c b/src/evaluate.c
index 98309ea83ac0..4609576b2a61 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1351,10 +1351,12 @@ static int __expr_evaluate_set_elem(struct eval_ctx *ctx, struct expr *elem)
 					  "but element has %d", num_set_exprs,
 					  num_elem_exprs);
 		} else if (num_set_exprs == 0) {
-			if (!(set->flags & NFT_SET_EVAL))
-				return expr_error(ctx->msgs, elem,
-						  "missing statements in %s definition",
+			if (!(set->flags & NFT_SET_EVAL)) {
+				elem_stmt = list_first_entry(&elem->stmt_list, struct stmt, list);
+				return stmt_error(ctx, elem_stmt,
+						  "missing statement in %s declaration",
 						  set_is_map(set->flags) ? "map" : "set");
+			}
 			return 0;
 		}
 
-- 
2.20.1


                 reply	other threads:[~2021-07-26 16:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210726163821.10869-1-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).