netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: kaber@trash.net
Subject: [PATCH 2/3 nft] src: fix do_list_tables() with family filtering
Date: Wed,  8 Jul 2015 11:18:07 +0200	[thread overview]
Message-ID: <1436347088-9687-2-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1436347088-9687-1-git-send-email-pablo@netfilter.org>

Use the ruleset_spec production so default is NFPROTO_UNSPEC as in 'list
ruleset'.

 # nft list tables
 table ip nat
 table ip test
 table inet filter

 # nft list tables ip
 table ip nat
 table ip test

 # nft list tables inet
 table inet filter

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/parser_bison.y |    2 +-
 src/rule.c         |   11 ++++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/parser_bison.y b/src/parser_bison.y
index 5c4e272..772cd65 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -764,7 +764,7 @@ list_cmd		:	TABLE		table_spec
 			{
 				$$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, &@$, NULL);
 			}
-			|	TABLES		tables_spec
+			|	TABLES		ruleset_spec
 			{
 				$$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, &@$, NULL);
 			}
diff --git a/src/rule.c b/src/rule.c
index f806db6..65b31e7 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -953,14 +953,19 @@ static int do_list_ruleset(struct netlink_ctx *ctx, struct cmd *cmd)
 	return 0;
 }
 
-static int do_list_tables(void)
+static int do_list_tables(struct netlink_ctx *ctx, struct cmd *cmd)
 {
 	struct table *table;
 
-	list_for_each_entry(table, &table_list, list)
+	list_for_each_entry(table, &table_list, list) {
+		if (cmd->handle.family != NFPROTO_UNSPEC &&
+		    table->handle.family != cmd->handle.family)
+			continue;
+
 		printf("table %s %s\n",
 		       family2str(table->handle.family),
 		       table->handle.table);
+	}
 
 	return 0;
 }
@@ -988,7 +993,7 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 	switch (cmd->obj) {
 	case CMD_OBJ_TABLE:
 		if (!cmd->handle.table)
-			return do_list_tables();
+			return do_list_tables(ctx, cmd);
 		return do_list_table(ctx, cmd, table);
 	case CMD_OBJ_CHAIN:
 		return do_list_table(ctx, cmd, table);
-- 
1.7.10.4


  reply	other threads:[~2015-07-08  9:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08  9:18 [PATCH 1/3 nft] src: get rid of EINTR handling in nft_netlink() Pablo Neira Ayuso
2015-07-08  9:18 ` Pablo Neira Ayuso [this message]
2015-07-08  9:18 ` [PATCH 3/3 nft] configure: fix --enable-debug Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436347088-9687-2-git-send-email-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).