|
|
34625f |
From b5fd560fa6b1aa1e112273d9f04281b58eb06dae Mon Sep 17 00:00:00 2001
|
|
|
34625f |
From: Phil Sutter <phil@nwl.cc>
|
|
|
34625f |
Date: Mon, 17 Dec 2018 16:29:56 +0100
|
|
|
34625f |
Subject: [PATCH] src: Reject 'export vm json' command
|
|
|
34625f |
|
|
|
34625f |
Since libnftnl recently dropped JSON output support, this form of JSON
|
|
|
34625f |
export is not available anymore. Point at 'nft -j list ruleset' command
|
|
|
34625f |
for a replacement in error message.
|
|
|
34625f |
|
|
|
34625f |
Since 'export' command is not useable anymore, remove it from
|
|
|
34625f |
documentation. Instead point out that 'list ruleset' command serves well
|
|
|
34625f |
for dumping and later restoring.
|
|
|
34625f |
|
|
|
34625f |
To not cause pointless inconvenience for users wishing to store their
|
|
|
34625f |
ruleset in JSON format, make JSON parser fallback to CMD_ADD if no
|
|
|
34625f |
recognized command property was found. This allows to feed the output of
|
|
|
34625f |
'nft -j list ruleset' into 'nft -f' without any modification.
|
|
|
34625f |
|
|
|
34625f |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
34625f |
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
|
|
|
34625f |
(cherry picked from commit 8d51f169e0e832a41d2ed278be903c08bd4fa473)
|
|
|
34625f |
|
|
|
34625f |
Conflicts:
|
|
|
34625f |
-> Documentation changes applied manually due to missing conversion to
|
|
|
34625f |
asciidoc.
|
|
|
34625f |
-> Dropped references to libnftables-json man page from documentation.
|
|
|
34625f |
(This file has not been backported and doing so is non-trivial due to
|
|
|
34625f |
asciidoc conversion.)
|
|
|
34625f |
-> Include libnftnl/common.h in src/evaluate.c to make symbol
|
|
|
34625f |
NFTNL_OUTPUT_JSON known.
|
|
|
34625f |
|
|
|
34625f |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
34625f |
---
|
|
|
34625f |
doc/nft.xml | 34 +++++++++++++---------------------
|
|
|
34625f |
src/evaluate.c | 5 +++++
|
|
|
34625f |
src/parser_json.c | 4 ++--
|
|
|
34625f |
3 files changed, 20 insertions(+), 23 deletions(-)
|
|
|
34625f |
|
|
|
34625f |
diff --git a/doc/nft.xml b/doc/nft.xml
|
|
|
34625f |
index 512724ed8f9a7..1a97d7a169776 100644
|
|
|
34625f |
--- a/doc/nft.xml
|
|
|
34625f |
+++ b/doc/nft.xml
|
|
|
34625f |
@@ -46,7 +46,7 @@ vi:ts=4 sw=4
|
|
|
34625f |
<cmdsynopsis>
|
|
|
34625f |
<command>nft</command>
|
|
|
34625f |
<group>
|
|
|
34625f |
- <arg><option> -nNscae </option></arg>
|
|
|
34625f |
+ <arg><option> -nNscaej </option></arg>
|
|
|
34625f |
</group>
|
|
|
34625f |
<arg> -I
|
|
|
34625f |
<replaceable>directory</replaceable>
|
|
|
34625f |
@@ -155,6 +155,14 @@ vi:ts=4 sw=4
|
|
|
34625f |
</para>
|
|
|
34625f |
</listitem>
|
|
|
34625f |
</varlistentry>
|
|
|
34625f |
+ <varlistentry>
|
|
|
34625f |
+ <term><option>-j, --json</option></term>
|
|
|
34625f |
+ <listitem>
|
|
|
34625f |
+ <para>
|
|
|
34625f |
+ Format output in JSON.
|
|
|
34625f |
+ </para>
|
|
|
34625f |
+ </listitem>
|
|
|
34625f |
+ </varlistentry>
|
|
|
34625f |
<varlistentry>
|
|
|
34625f |
<term><option>-I, --includepath <replaceable>directory</replaceable></option></term>
|
|
|
34625f |
<listitem>
|
|
|
34625f |
@@ -480,11 +488,6 @@ filter input iif $int_ifs accept
|
|
|
34625f |
<command>ruleset</command>
|
|
|
34625f |
<arg choice="opt"><replaceable>family</replaceable></arg>
|
|
|
34625f |
</cmdsynopsis>
|
|
|
34625f |
- <cmdsynopsis>
|
|
|
34625f |
- <arg choice="plain">export</arg>
|
|
|
34625f |
- <arg choice="opt"><command>ruleset</command></arg>
|
|
|
34625f |
- <arg choice="plain"><replaceable>format</replaceable></arg>
|
|
|
34625f |
- </cmdsynopsis>
|
|
|
34625f |
</para>
|
|
|
34625f |
|
|
|
34625f |
<para>
|
|
|
34625f |
@@ -514,17 +517,6 @@ filter input iif $int_ifs accept
|
|
|
34625f |
</para>
|
|
|
34625f |
</listitem>
|
|
|
34625f |
</varlistentry>
|
|
|
34625f |
- <varlistentry>
|
|
|
34625f |
- <term><option>export</option></term>
|
|
|
34625f |
- <listitem>
|
|
|
34625f |
- <para>
|
|
|
34625f |
- Print the ruleset in machine readable format. The
|
|
|
34625f |
- mandatory <replaceable>format</replaceable> parameter
|
|
|
34625f |
- may be either <literal>xml</literal> or
|
|
|
34625f |
- <literal>json</literal>.
|
|
|
34625f |
- </para>
|
|
|
34625f |
- </listitem>
|
|
|
34625f |
- </varlistentry>
|
|
|
34625f |
</variablelist>
|
|
|
34625f |
|
|
|
34625f |
<para>
|
|
|
34625f |
@@ -534,10 +526,10 @@ filter input iif $int_ifs accept
|
|
|
34625f |
</para>
|
|
|
34625f |
|
|
|
34625f |
<para>
|
|
|
34625f |
- Note that contrary to what one might assume, the output generated
|
|
|
34625f |
- by <command>export</command> is not parseable by
|
|
|
34625f |
- <command>nft -f</command>. Instead, the output of
|
|
|
34625f |
- <command>list</command> command serves well for that purpose.
|
|
|
34625f |
+ By design, <command>list ruleset</command> command output may be
|
|
|
34625f |
+ used as input to <command>nft -f</command>.
|
|
|
34625f |
+ Effectively, this is the nft-equivalent of <command>iptables-save</command> and
|
|
|
34625f |
+ <command>iptables-restore</command>.
|
|
|
34625f |
</para>
|
|
|
34625f |
</refsect1>
|
|
|
34625f |
|
|
|
34625f |
diff --git a/src/evaluate.c b/src/evaluate.c
|
|
|
34625f |
index 809920748c0a9..4656c7566db39 100644
|
|
|
34625f |
--- a/src/evaluate.c
|
|
|
34625f |
+++ b/src/evaluate.c
|
|
|
34625f |
@@ -31,6 +31,8 @@
|
|
|
34625f |
#include <utils.h>
|
|
|
34625f |
#include <xt.h>
|
|
|
34625f |
|
|
|
34625f |
+#include <libnftnl/common.h>
|
|
|
34625f |
+
|
|
|
34625f |
static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr);
|
|
|
34625f |
|
|
|
34625f |
static const char * const byteorder_names[] = {
|
|
|
34625f |
@@ -3526,6 +3528,9 @@ static int cmd_evaluate_export(struct eval_ctx *ctx, struct cmd *cmd)
|
|
|
34625f |
if (cmd->markup->format == __NFT_OUTPUT_NOTSUPP)
|
|
|
34625f |
return cmd_error(ctx, &cmd->location,
|
|
|
34625f |
"this output type is not supported");
|
|
|
34625f |
+ else if (cmd->markup->format == NFTNL_OUTPUT_JSON)
|
|
|
34625f |
+ return cmd_error(ctx, &cmd->location,
|
|
|
34625f |
+ "JSON export is no longer supported, use 'nft -j list ruleset' instead");
|
|
|
34625f |
|
|
|
34625f |
return cache_update(ctx->nft, cmd->op, ctx->msgs);
|
|
|
34625f |
}
|
|
|
34625f |
diff --git a/src/parser_json.c b/src/parser_json.c
|
|
|
34625f |
index 817415c15fb89..1e3688b2dc1cd 100644
|
|
|
34625f |
--- a/src/parser_json.c
|
|
|
34625f |
+++ b/src/parser_json.c
|
|
|
34625f |
@@ -3018,8 +3018,8 @@ static struct cmd *json_parse_cmd(struct json_ctx *ctx, json_t *root)
|
|
|
34625f |
|
|
|
34625f |
return parse_cb_table[i].cb(ctx, tmp, parse_cb_table[i].op);
|
|
|
34625f |
}
|
|
|
34625f |
- json_error(ctx, "Unknown command object.");
|
|
|
34625f |
- return NULL;
|
|
|
34625f |
+ /* to accept 'list ruleset' output 1:1, try add command */
|
|
|
34625f |
+ return json_parse_cmd_add(ctx, root, CMD_ADD);
|
|
|
34625f |
}
|
|
|
34625f |
|
|
|
34625f |
static int __json_parse(struct json_ctx *ctx, json_t *root)
|
|
|
34625f |
--
|
|
|
34625f |
2.19.0
|
|
|
34625f |
|