static int nft_parse_bison_buffer(struct nft_ctx *nft, const char *buf,
struct list_head *msgs, struct list_head *cmds)
{
- struct cmd *cmd;
int ret;
parser_init(nft, nft->state, msgs, cmds);
if (ret != 0 || nft->state->nerrs > 0)
return -1;
- list_for_each_entry(cmd, cmds, list)
- nft_cmd_expand(cmd);
-
return 0;
}
static int nft_parse_bison_filename(struct nft_ctx *nft, const char *filename,
struct list_head *msgs, struct list_head *cmds)
{
- struct cmd *cmd;
int ret;
parser_init(nft, nft->state, msgs, cmds);
if (ret != 0 || nft->state->nerrs > 0)
return -1;
+ return 0;
+}
+
+static int nft_evaluate(struct nft_ctx *nft, struct list_head *msgs,
+ struct list_head *cmds)
+{
+ struct cmd *cmd;
+
+ list_for_each_entry(cmd, cmds, list) {
+ struct eval_ctx ectx = {
+ .nft = nft,
+ .msgs = msgs,
+ };
+ if (cmd_evaluate(&ectx, cmd) < 0)
+ return -1;
+ }
+
list_for_each_entry(cmd, cmds, list)
nft_cmd_expand(cmd);
if (rc)
goto err;
+ rc = nft_evaluate(nft, &msgs, &cmds);
+ if (rc < 0)
+ goto err;
+
if (nft_netlink(nft, &cmds, &msgs, nft->nf_sock) != 0)
rc = -1;
err:
if (rc)
goto err;
+ rc = nft_evaluate(nft, &msgs, &cmds);
+ if (rc < 0)
+ goto err;
+
if (nft_netlink(nft, &cmds, &msgs, nft->nf_sock) != 0)
rc = -1;
err:
state->msgs = msgs;
state->cmds = cmds;
state->scopes[0] = scope_init(&state->top_scope, NULL);
- state->ectx.nft = nft;
- state->ectx.msgs = msgs;
init_list_head(&state->indesc_list);
}
| input line
{
if ($2 != NULL) {
- LIST_HEAD(list);
-
$2->location = @2;
-
- list_add_tail(&$2->list, &list);
- if (cmd_evaluate(&state->ectx, $2) < 0) {
- cmd_free($2);
- if (++state->nerrs == nft->parser_max_errors)
- YYABORT;
- } else
- list_splice_tail(&list, state->cmds);
+ list_add_tail(&$2->list, state->cmds);
}
}
;
* work.
*/
if ($1 != NULL) {
- LIST_HEAD(list);
-
$1->location = @1;
-
- list_add_tail(&$1->list, &list);
- if (cmd_evaluate(&state->ectx, $1) < 0) {
- cmd_free($1);
- if (++state->nerrs == nft->parser_max_errors)
- YYABORT;
- } else
- list_splice_tail(&list, state->cmds);
+ list_add_tail(&$1->list, state->cmds);
}
- if (state->nerrs)
- YYABORT;
$$ = NULL;
-
YYACCEPT;
}
;