Blame SOURCES/0038-rule-fix-object-listing-when-no-table-is-given.patch

bacbc8
From 3e28756a6f0730abac937d9fb10b7ee9c3569a15 Mon Sep 17 00:00:00 2001
bacbc8
From: Florian Westphal <fw@strlen.de>
bacbc8
Date: Wed, 2 Jan 2019 17:10:36 +0100
bacbc8
Subject: [PATCH] rule: fix object listing when no table is given
bacbc8
bacbc8
'nft list quotas' would not print anything at all anymore.
bacbc8
bacbc8
Fixes: 88456a7ef01172 ("rule: list only the table containing object")
bacbc8
Signed-off-by: Florian Westphal <fw@strlen.de>
bacbc8
(cherry picked from commit dafac7d528de0890b82f943fc818ccb7a82fca7d)
bacbc8
Signed-off-by: Phil Sutter <psutter@redhat.com>
bacbc8
---
bacbc8
 src/rule.c                                  | 13 ++++++++-----
bacbc8
 tests/shell/testcases/listing/0014objects_0 |  7 +++++++
bacbc8
 2 files changed, 15 insertions(+), 5 deletions(-)
bacbc8
bacbc8
diff --git a/src/rule.c b/src/rule.c
bacbc8
index 47b0d30cbed18..c3a2e7cc464bb 100644
bacbc8
--- a/src/rule.c
bacbc8
+++ b/src/rule.c
bacbc8
@@ -1585,13 +1585,16 @@ static int do_list_obj(struct netlink_ctx *ctx, struct cmd *cmd, uint32_t type)
bacbc8
 			continue;
bacbc8
 
bacbc8
 		if (cmd->handle.table.name != NULL &&
bacbc8
-		    !strcmp(cmd->handle.table.name, table->handle.table.name)) {
bacbc8
-			nft_print(&ctx->nft->output, "table %s %s {\n",
bacbc8
-				  family2str(table->handle.family),
bacbc8
-				  cmd->handle.table.name);
bacbc8
-		} else
bacbc8
+		    strcmp(cmd->handle.table.name, table->handle.table.name))
bacbc8
 			continue;
bacbc8
 
bacbc8
+		if (list_empty(&table->objs))
bacbc8
+			continue;
bacbc8
+
bacbc8
+		nft_print(&ctx->nft->output, "table %s %s {\n",
bacbc8
+			  family2str(table->handle.family),
bacbc8
+			  table->handle.table.name);
bacbc8
+
bacbc8
 		list_for_each_entry(obj, &table->objs, list) {
bacbc8
 			if (obj->type != type ||
bacbc8
 			    (cmd->handle.obj.name != NULL &&
bacbc8
diff --git a/tests/shell/testcases/listing/0014objects_0 b/tests/shell/testcases/listing/0014objects_0
bacbc8
index dcfe2e6f80947..20f68406e58fa 100755
bacbc8
--- a/tests/shell/testcases/listing/0014objects_0
bacbc8
+++ b/tests/shell/testcases/listing/0014objects_0
bacbc8
@@ -15,6 +15,13 @@ $NFT add quota test https-quota 25 mbytes
bacbc8
 $NFT add ct helper test cthelp { type \"sip\" protocol tcp \; }
bacbc8
 $NFT add table test-ip
bacbc8
 
bacbc8
+GET="$($NFT list quotas)"
bacbc8
+if [ "$EXPECTED" != "$GET" ] ; then
bacbc8
+	DIFF="$(which diff)"
bacbc8
+	[ -x $DIFF ] && $DIFF -u <(echo "$EXPECTED") <(echo "$GET")
bacbc8
+	exit 1
bacbc8
+fi
bacbc8
+
bacbc8
 GET="$($NFT list quota test https-quota)"
bacbc8
 if [ "$EXPECTED" != "$GET" ] ; then
bacbc8
 	DIFF="$(which diff)"
bacbc8
-- 
bacbc8
2.21.0
bacbc8