Blob Blame History Raw
From 3e28756a6f0730abac937d9fb10b7ee9c3569a15 Mon Sep 17 00:00:00 2001
From: Florian Westphal <fw@strlen.de>
Date: Wed, 2 Jan 2019 17:10:36 +0100
Subject: [PATCH] rule: fix object listing when no table is given

'nft list quotas' would not print anything at all anymore.

Fixes: 88456a7ef01172 ("rule: list only the table containing object")
Signed-off-by: Florian Westphal <fw@strlen.de>
(cherry picked from commit dafac7d528de0890b82f943fc818ccb7a82fca7d)
Signed-off-by: Phil Sutter <psutter@redhat.com>
---
 src/rule.c                                  | 13 ++++++++-----
 tests/shell/testcases/listing/0014objects_0 |  7 +++++++
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/rule.c b/src/rule.c
index 47b0d30cbed18..c3a2e7cc464bb 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -1585,13 +1585,16 @@ static int do_list_obj(struct netlink_ctx *ctx, struct cmd *cmd, uint32_t type)
 			continue;
 
 		if (cmd->handle.table.name != NULL &&
-		    !strcmp(cmd->handle.table.name, table->handle.table.name)) {
-			nft_print(&ctx->nft->output, "table %s %s {\n",
-				  family2str(table->handle.family),
-				  cmd->handle.table.name);
-		} else
+		    strcmp(cmd->handle.table.name, table->handle.table.name))
 			continue;
 
+		if (list_empty(&table->objs))
+			continue;
+
+		nft_print(&ctx->nft->output, "table %s %s {\n",
+			  family2str(table->handle.family),
+			  table->handle.table.name);
+
 		list_for_each_entry(obj, &table->objs, list) {
 			if (obj->type != type ||
 			    (cmd->handle.obj.name != NULL &&
diff --git a/tests/shell/testcases/listing/0014objects_0 b/tests/shell/testcases/listing/0014objects_0
index dcfe2e6f80947..20f68406e58fa 100755
--- a/tests/shell/testcases/listing/0014objects_0
+++ b/tests/shell/testcases/listing/0014objects_0
@@ -15,6 +15,13 @@ $NFT add quota test https-quota 25 mbytes
 $NFT add ct helper test cthelp { type \"sip\" protocol tcp \; }
 $NFT add table test-ip
 
+GET="$($NFT list quotas)"
+if [ "$EXPECTED" != "$GET" ] ; then
+	DIFF="$(which diff)"
+	[ -x $DIFF ] && $DIFF -u <(echo "$EXPECTED") <(echo "$GET")
+	exit 1
+fi
+
 GET="$($NFT list quota test https-quota)"
 if [ "$EXPECTED" != "$GET" ] ; then
 	DIFF="$(which diff)"
-- 
2.21.0