From 61236968b7a1b4a4986f9a5c9a5e46d3eb70b799 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Tue, 4 Feb 2014 08:09:27 +0000 Subject: parser: evaluate commands immediately after parsing We currently do parsing and evaluation in two seperate stages. This means that if any error occurs during parsing, we won't evaluate the syntactical correct commands and detect possible evaluation errors in them. In order to improve error reporting, change this to evaluate every command as soon as it is fully parsed. With this in place, the ruleset can be fully validated and all errors reported in one step: tests/error.1:6:23-23: Error: syntax error, unexpected newline filter input tcp dport ^ tests/error.1:7:24-26: Error: datatype mismatch, expected internet network service, expression has type Internet protocol filter input tcp dport tcp ~~~~~~~~~ ^^^ tests/error.1:8:24-32: Error: Right hand side of relational expression (==) must be constant filter input tcp dport tcp dport ~~~~~~~~~~^^^^^^^^^ Signed-off-by: Patrick McHardy --- src/evaluate.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'src/evaluate.c') diff --git a/src/evaluate.c b/src/evaluate.c index a01d2a53..8e51a63b 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -1384,7 +1384,7 @@ static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd) } } -static int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd) +int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd) { #ifdef DEBUG if (debug_level & DEBUG_EVALUATION) { @@ -1411,14 +1411,3 @@ static int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd) BUG("invalid command operation %u\n", cmd->op); }; } - -int evaluate(struct eval_ctx *ctx, struct list_head *commands) -{ - struct cmd *cmd; - - list_for_each_entry(cmd, commands, list) { - if (cmd_evaluate(ctx, cmd) < 0) - return -1; - } - return 0; -} -- cgit v1.2.3