int nft_run_cmd_from_buffer(struct nft_ctx *nft, const char *buf)
{
+ int rc = -EINVAL, parser_rc;
struct cmd *cmd, *next;
LIST_HEAD(msgs);
LIST_HEAD(cmds);
char *nlbuf;
- int rc = -EINVAL;
nlbuf = xzalloc(strlen(buf) + 2);
sprintf(nlbuf, "%s\n", buf);
rc = nft_parse_json_buffer(nft, nlbuf, &msgs, &cmds);
if (rc == -EINVAL)
rc = nft_parse_bison_buffer(nft, nlbuf, &msgs, &cmds);
- if (rc)
- goto err;
+
+ parser_rc = rc;
rc = nft_evaluate(nft, &msgs, &cmds);
if (rc < 0)
goto err;
+ if (parser_rc) {
+ rc = parser_rc;
+ goto err;
+ }
+
if (nft_netlink(nft, &cmds, &msgs, nft->nf_sock) != 0)
rc = -1;
err:
int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename)
{
struct cmd *cmd, *next;
+ int rc, parser_rc;
LIST_HEAD(msgs);
LIST_HEAD(cmds);
- int rc;
rc = cache_update(nft, CMD_INVALID, &msgs);
if (rc < 0)
rc = nft_parse_json_filename(nft, filename, &msgs, &cmds);
if (rc == -EINVAL)
rc = nft_parse_bison_filename(nft, filename, &msgs, &cmds);
- if (rc)
- goto err;
+
+ parser_rc = rc;
rc = nft_evaluate(nft, &msgs, &cmds);
if (rc < 0)
goto err;
+ if (parser_rc) {
+ rc = parser_rc;
+ goto err;
+ }
+
if (nft_netlink(nft, &cmds, &msgs, nft->nf_sock) != 0)
rc = -1;
err:
static int __json_parse(struct json_ctx *ctx)
{
- struct eval_ctx ectx = {
- .nft = ctx->nft,
- .msgs = ctx->msgs,
- };
json_t *tmp, *value;
size_t index;
list_add_tail(&cmd->list, &list);
- if (cmd_evaluate(&ectx, cmd) < 0) {
- cmd_free(cmd);
- json_error(ctx, "Evaluating command at index %zd failed.", index);
- return -1;
- }
list_splice_tail(&list, ctx->cmds);
if (nft_output_echo(&ctx->nft->output))