]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: error reporting for missing statements in set/map declaration
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 26 Jul 2021 16:00:09 +0000 (18:00 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 26 Jul 2021 16:21:19 +0000 (18:21 +0200)
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

index 98309ea83ac05ef9e0ba0a10299c40e30f679d31..4609576b2a6188f93917eb55d6e001b1ec4470de 100644 (file)
@@ -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;
                }