Blame SOURCES/0031-src-Reject-export-vm-json-command.patch

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