unsigned int scope;
struct list_head cmds;
+ struct eval_ctx ectx;
};
extern void parser_init(struct parser_state *state, struct list_head *msgs);
struct proto_ctx pctx;
};
-extern int evaluate(struct eval_ctx *ctx, struct list_head *commands);
+extern int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd);
extern struct error_record *rule_postprocess(struct rule *rule);
}
}
-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) {
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;
-}
int nft_run(void *scanner, struct parser_state *state, struct list_head *msgs)
{
- struct eval_ctx ctx;
- int ret = 0;
+ int ret;
ret = nft_parse(scanner, state);
if (ret != 0 || state->nerrs > 0)
return -1;
- memset(&ctx, 0, sizeof(ctx));
- ctx.msgs = msgs;
- if (evaluate(&ctx, &state->cmds) < 0)
- return -1;
-
return nft_netlink(state, msgs);
}
init_list_head(&state->top_scope.symbols);
state->msgs = msgs;
state->scopes[0] = scope_init(&state->top_scope, NULL);
+ state->ectx.msgs = msgs;
}
static void yyerror(struct location *loc, void *scanner,
{
if ($2 != NULL) {
$2->location = @2;
- list_add_tail(&$2->list, &state->cmds);
+ if (cmd_evaluate(&state->ectx, $2) < 0) {
+ if (++state->nerrs == max_errors)
+ YYABORT;
+ } else
+ list_add_tail(&$2->list, &state->cmds);
}
}
;
*/
if ($1 != NULL) {
$1->location = @1;
- list_add_tail(&$1->list, &state->cmds);
+
+ if (cmd_evaluate(&state->ectx, $1) < 0) {
+ if (++state->nerrs == max_errors)
+ YYABORT;
+ } else
+ list_add_tail(&$1->list, &state->cmds);
}
$$ = NULL;