summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2018-02-15 17:22:16 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2018-02-15 18:39:09 +0100
commita340aa6ca6cd08ae173fbb95cd3e65807264df07 (patch)
treee763cfd5e5fe1d0f952fefc7c91e318be0fb8353 /src
parentd9428e67fca288e4f34dbb6c0dfe42ebc48c9ad1 (diff)
src: bail out when exporting ruleset with unsupported output
Display error message and propagate error to shell when running command with unsupported output: # nft export ruleset json Error: this output type is not supported export ruleset json ^^^^^^^^^^^^^^^^^^^^ # echo $? 1 When displaying the output in json using the low-level VM representation, it shows: # nft export ruleset vm json ... low-level VM json output # echo $? 0 While at it, do the same with obsoleted XML output. Fixes: https://bugzilla.netfilter.org/show_bug.cgi?id=1224 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/evaluate.c13
-rw-r--r--src/parser_bison.y6
2 files changed, 14 insertions, 5 deletions
diff --git a/src/evaluate.c b/src/evaluate.c
index 8107df83..e5ad1044 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -3423,10 +3423,21 @@ static int cmd_evaluate_monitor(struct eval_ctx *ctx, struct cmd *cmd)
static int cmd_evaluate_export(struct eval_ctx *ctx, struct cmd *cmd)
{
+ if (cmd->markup->format == __NFT_OUTPUT_NOTSUPP)
+ return cmd_error(ctx, "this output type is not supported");
+
return cache_update(ctx->nf_sock, ctx->cache, cmd->op, ctx->msgs,
ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
}
+static int cmd_evaluate_import(struct eval_ctx *ctx, struct cmd *cmd)
+{
+ if (cmd->markup->format == __NFT_OUTPUT_NOTSUPP)
+ return cmd_error(ctx, "this output type not supported");
+
+ return 0;
+}
+
static const char * const cmd_op_name[] = {
[CMD_INVALID] = "invalid",
[CMD_ADD] = "add",
@@ -3486,7 +3497,7 @@ int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd)
case CMD_MONITOR:
return cmd_evaluate_monitor(ctx, cmd);
case CMD_IMPORT:
- return 0;
+ return cmd_evaluate_import(ctx, cmd);
default:
BUG("invalid command operation %u\n", cmd->op);
};
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 578bfdc1..56341115 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -1198,7 +1198,6 @@ import_cmd : RULESET markup_format
struct markup *markup = markup_alloc($1);
$$ = cmd_alloc(CMD_IMPORT, CMD_OBJ_MARKUP, &h, &@$, markup);
}
- | JSON { $$ = NULL; }
;
export_cmd : RULESET markup_format
@@ -1213,7 +1212,6 @@ export_cmd : RULESET markup_format
struct markup *markup = markup_alloc($1);
$$ = cmd_alloc(CMD_EXPORT, CMD_OBJ_MARKUP, &h, &@$, markup);
}
- | JSON { $$ = NULL; }
;
monitor_cmd : monitor_event monitor_object monitor_format
@@ -1241,10 +1239,10 @@ monitor_object : /* empty */ { $$ = CMD_MONITOR_OBJ_ANY; }
monitor_format : /* empty */ { $$ = NFTNL_OUTPUT_DEFAULT; }
| markup_format
- | JSON { $$ = NFTNL_OUTPUT_JSON; }
;
-markup_format : XML { $$ = NFTNL_OUTPUT_XML; }
+markup_format : XML { $$ = __NFT_OUTPUT_NOTSUPP; }
+ | JSON { $$ = __NFT_OUTPUT_NOTSUPP; }
| VM JSON { $$ = NFTNL_OUTPUT_JSON; }
;