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

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