]> git.ipfire.org Git - thirdparty/nftables.git/commit
src: Display parser and evaluate errors in one shot
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 4 Jun 2019 09:03:06 +0000 (11:03 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 5 Jun 2019 16:00:31 +0000 (18:00 +0200)
commit89bae935180a50f4ea827f5facc41459557380ef
tree86680b2f7ebf21e54bd3acc3711bd0200b6e383d
parentf211921e25e683eb0cbfac08fd0289a07b6d67d1
src: Display parser and evaluate errors in one shot

This patch restores 61236968b7a1 ("parser: evaluate commands immediately
after parsing") following a different approach.

In this patch, the evaluation phase is done if the parsing phase fails,
hence the user gets parsing and evaluation errors in one shot, which is
the purpose of 61236968b7a1.

Note that evaluation errors are now shown after parser errors, the example
available in 61236968b7a1 displays with this patch the following error:

 # nft -f /tmp/bad.nft
 /tmp/bad.nft:3:32-32: Error: syntax error, unexpected newline
 add rule filter input tcp dport
                                ^
 /tmp/bad.nft:5:37-41: Error: syntax error, unexpected dport, expecting end of file or newline or semicolon
 add rule filter input tcp dport tcp dport
                                     ^^^^^
 /tmp/bad.nft:4:33-35: Error: datatype mismatch, expected internet network service, expression has type Internet protocol
 add rule filter input tcp dport tcp
                       ~~~~~~~~~ ^^^

So evaluation pointing to line 4 happens after line error reporting
generated by the parser that points to line 3, while 61236968b7a1 was
showing errors per line in order. As a future work, we can sort the
error reporting list to restore exactly the same behaviour.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/libnftables.c
src/parser_json.c