Blame SOURCES/0004-monitor-Fix-printing-of-ct-objects.patch

9ff721
From 892ec2ca97263ccfffb52f2943c2ab2ac34f476d Mon Sep 17 00:00:00 2001
9ff721
From: Phil Sutter <phil@nwl.cc>
9ff721
Date: Thu, 11 Oct 2018 17:48:59 +0200
9ff721
Subject: [PATCH] monitor: Fix printing of ct objects
9ff721
9ff721
Monitor output is supposed to be single lined without tabs, but ct
9ff721
object were printed with newlines and tabs hard-coded. Fixing this
9ff721
wasn't too hard given that there is 'stmt_separator' to also include
9ff721
semi-colons where required if newline was removed.
9ff721
9ff721
A more obvious mistake was position of object type in monitor output:
9ff721
Like with other object types, it has to occur between command and table
9ff721
spec. As a positive side-effect, this aligns ct objects better with
9ff721
others (see obj_type_name_array for instance).
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 90ed4fb3855f0d9d881b812c75e338e5e93081ba)
9ff721
9ff721
Conflicts:
9ff721
	src/rule.c
9ff721
	tests/shell/testcases/listing/0013objects_0
9ff721
	tests/shell/testcases/nft-f/0017ct_timeout_obj_0
9ff721
	tests/shell/testcases/nft-f/dumps/0017ct_timeout_obj_0.nft
9ff721
-> missing ct timeout support
9ff721
9ff721
Signed-off-by: Phil Sutter <psutter@redhat.com>
9ff721
---
9ff721
 src/json.c                       |  1 -
9ff721
 src/rule.c                       | 26 ++++++++++++++++----------
9ff721
 tests/monitor/testcases/object.t | 27 +++++++++++++++++++++++++++
9ff721
 3 files changed, 43 insertions(+), 11 deletions(-)
9ff721
 create mode 100644 tests/monitor/testcases/object.t
9ff721
9ff721
diff --git a/src/json.c b/src/json.c
9ff721
index b6e6ca9c6c383..af157212c081e 100644
9ff721
--- a/src/json.c
9ff721
+++ b/src/json.c
9ff721
@@ -264,7 +264,6 @@ static json_t *obj_print_json(struct output_ctx *octx, const struct obj *obj)
9ff721
 		json_decref(tmp);
9ff721
 		break;
9ff721
 	case NFT_OBJECT_CT_HELPER:
9ff721
-		type = "ct helper";
9ff721
 		tmp = json_pack("{s:s, s:o, s:s}",
9ff721
 				"type", obj->ct_helper.name, "protocol",
9ff721
 				proto_name_json(obj->ct_helper.l4proto),
9ff721
diff --git a/src/rule.c b/src/rule.c
9ff721
index 56b956a4f8fec..eb06302d4f223 100644
9ff721
--- a/src/rule.c
9ff721
+++ b/src/rule.c
9ff721
@@ -1432,8 +1432,8 @@ static void obj_print_data(const struct obj *obj,
9ff721
 			nft_print(octx, "packets 0 bytes 0");
9ff721
 			break;
9ff721
 		}
9ff721
-		nft_print(octx, "packets %" PRIu64 " bytes %" PRIu64 "",
9ff721
-			  obj->counter.packets, obj->counter.bytes);
9ff721
+		nft_print(octx, "packets %" PRIu64 " bytes %" PRIu64 "%s",
9ff721
+			  obj->counter.packets, obj->counter.bytes, opts->nl);
9ff721
 		break;
9ff721
 	case NFT_OBJECT_QUOTA: {
9ff721
 		const char *data_unit;
9ff721
@@ -1452,18 +1452,22 @@ static void obj_print_data(const struct obj *obj,
9ff721
 			nft_print(octx, " used %" PRIu64 " %s",
9ff721
 				  bytes, data_unit);
9ff721
 		}
9ff721
+		nft_print(octx, "%s", opts->nl);
9ff721
 		}
9ff721
 		break;
9ff721
 	case NFT_OBJECT_CT_HELPER:
9ff721
-		nft_print(octx, "ct helper %s {", obj->handle.obj.name);
9ff721
+		nft_print(octx, " %s {", obj->handle.obj.name);
9ff721
 		if (octx->handle > 0)
9ff721
 			nft_print(octx, " # handle %" PRIu64, obj->handle.handle.id);
9ff721
 		nft_print(octx, "%s", opts->nl);
9ff721
-		nft_print(octx, "\t\ttype \"%s\" protocol ",
9ff721
-			  obj->ct_helper.name);
9ff721
+		nft_print(octx, "%s%stype \"%s\" protocol ",
9ff721
+			  opts->tab, opts->tab, obj->ct_helper.name);
9ff721
 		print_proto_name_proto(obj->ct_helper.l4proto, octx);
9ff721
-		nft_print(octx, "\t\tl3proto %s",
9ff721
-			  family2str(obj->ct_helper.l3proto));
9ff721
+		nft_print(octx, "%s", opts->stmt_separator);
9ff721
+		nft_print(octx, "%s%sl3proto %s%s",
9ff721
+			  opts->tab, opts->tab,
9ff721
+			  family2str(obj->ct_helper.l3proto),
9ff721
+			  opts->stmt_separator);
9ff721
 		break;
9ff721
 	case NFT_OBJECT_LIMIT: {
9ff721
 		bool inv = obj->limit.flags & NFT_LIMIT_F_INV;
9ff721
@@ -1498,10 +1502,11 @@ static void obj_print_data(const struct obj *obj,
9ff721
 			}
9ff721
 			break;
9ff721
 		}
9ff721
+		nft_print(octx, "%s", opts->nl);
9ff721
 		}
9ff721
 		break;
9ff721
 	default:
9ff721
-		nft_print(octx, "unknown {%s", opts->nl);
9ff721
+		nft_print(octx, " unknown {%s", opts->nl);
9ff721
 		break;
9ff721
 	}
9ff721
 }
9ff721
@@ -1509,7 +1514,7 @@ static void obj_print_data(const struct obj *obj,
9ff721
 static const char * const obj_type_name_array[] = {
9ff721
 	[NFT_OBJECT_COUNTER]	= "counter",
9ff721
 	[NFT_OBJECT_QUOTA]	= "quota",
9ff721
-	[NFT_OBJECT_CT_HELPER]	= "",
9ff721
+	[NFT_OBJECT_CT_HELPER]	= "ct helper",
9ff721
 	[NFT_OBJECT_LIMIT]	= "limit",
9ff721
 };
9ff721
 
9ff721
@@ -1548,7 +1553,7 @@ static void obj_print_declaration(const struct obj *obj,
9ff721
 
9ff721
 	obj_print_data(obj, opts, octx);
9ff721
 
9ff721
-	nft_print(octx, "%s%s}%s", opts->nl, opts->tab, opts->nl);
9ff721
+	nft_print(octx, "%s}%s", opts->tab, opts->nl);
9ff721
 }
9ff721
 
9ff721
 void obj_print(const struct obj *obj, struct output_ctx *octx)
9ff721
@@ -1569,6 +1574,7 @@ void obj_print_plain(const struct obj *obj, struct output_ctx *octx)
9ff721
 		.nl		= " ",
9ff721
 		.table		= obj->handle.table.name,
9ff721
 		.family		= family2str(obj->handle.family),
9ff721
+		.stmt_separator = "; ",
9ff721
 	};
9ff721
 
9ff721
 	obj_print_declaration(obj, &opts, octx);
9ff721
diff --git a/tests/monitor/testcases/object.t b/tests/monitor/testcases/object.t
9ff721
new file mode 100644
9ff721
index 0000000000000..7b88409775796
9ff721
--- /dev/null
9ff721
+++ b/tests/monitor/testcases/object.t
9ff721
@@ -0,0 +1,27 @@
9ff721
+# first the setup
9ff721
+I add table ip t
9ff721
+O -
9ff721
+
9ff721
+I add counter ip t c
9ff721
+O add counter ip t c { packets 0 bytes 0 }
9ff721
+
9ff721
+I delete counter ip t c
9ff721
+O -
9ff721
+
9ff721
+I add quota ip t q 25 mbytes
9ff721
+O add quota ip t q { 25 mbytes }
9ff721
+
9ff721
+I delete quota ip t q
9ff721
+O -
9ff721
+
9ff721
+I add limit ip t l rate 1/second
9ff721
+O add limit ip t l { rate 1/second }
9ff721
+
9ff721
+I delete limit ip t l
9ff721
+O -
9ff721
+
9ff721
+I add ct helper ip t cth { type "sip" protocol tcp; l3proto ip; }
9ff721
+O -
9ff721
+
9ff721
+I delete ct helper ip t cth
9ff721
+O -
9ff721
-- 
bacbc8
2.21.0
9ff721