]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
rule: fix object listing when no table is given
authorFlorian Westphal <fw@strlen.de>
Wed, 2 Jan 2019 16:10:36 +0000 (17:10 +0100)
committerFlorian Westphal <fw@strlen.de>
Wed, 2 Jan 2019 22:22:44 +0000 (23:22 +0100)
'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>
src/rule.c
tests/shell/testcases/listing/0014objects_0

index a815850d6eaeb5607252ad894cac387e3df14d69..e15a20b30bbd6ff6b7687958412279847a11cca2 100644 (file)
@@ -1946,13 +1946,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 &&
index dcfe2e6f809478d7a864e9a5245972aef5233a46..20f68406e58fa48a99295a3d298366978c65e50d 100755 (executable)
@@ -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)"