All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft 1/3] rule: missing family when listing of tables
@ 2015-07-06 17:06 Pablo Neira Ayuso
  2015-07-06 17:06 ` [PATCH nft 2/3] src: set chain->hookstr from delinearization Pablo Neira Ayuso
  2015-07-06 17:06 ` [PATCH nft 3/3] rule: add do_list_tables() Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2015-07-06 17:06 UTC (permalink / raw)
  To: netfilter-devel; +Cc: kaber

 # nft list tables
 table ip nat

instead of:

 # nft list tables
 table nat

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/rule.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/rule.c b/src/rule.c
index b2090dd..39b4d9a 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -928,7 +928,9 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 				return -1;
 
 			list_for_each_entry(table, &ctx->list, list) {
-				printf("table %s\n", table->handle.table);
+				printf("table %s %s\n",
+				       family2str(table->handle.family),
+				       table->handle.table);
 			}
 			return 0;
 		}
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH nft 2/3] src: set chain->hookstr from delinearization
  2015-07-06 17:06 [PATCH nft 1/3] rule: missing family when listing of tables Pablo Neira Ayuso
@ 2015-07-06 17:06 ` Pablo Neira Ayuso
  2015-07-06 17:06 ` [PATCH nft 3/3] rule: add do_list_tables() Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2015-07-06 17:06 UTC (permalink / raw)
  To: netfilter-devel; +Cc: kaber

Set human readable hookname chain->hookstr field from delinearize.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/rule.h |    1 +
 src/netlink.c  |    2 ++
 src/rule.c     |    8 +++-----
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/rule.h b/include/rule.h
index 5d44599..8ec7f91 100644
--- a/include/rule.h
+++ b/include/rule.h
@@ -138,6 +138,7 @@ extern struct chain *chain_lookup(const struct table *table,
 				  const struct handle *h);
 
 extern const char *family2str(unsigned int family);
+extern const char *hooknum2str(unsigned int family, unsigned int hooknum);
 extern void chain_print_plain(const struct chain *chain);
 
 /**
diff --git a/src/netlink.c b/src/netlink.c
index 429eed4..d11d82f 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -691,6 +691,8 @@ static struct chain *netlink_delinearize_chain(struct netlink_ctx *ctx,
 	    nft_chain_attr_is_set(nlc, NFT_CHAIN_ATTR_POLICY)) {
 		chain->hooknum       =
 			nft_chain_attr_get_u32(nlc, NFT_CHAIN_ATTR_HOOKNUM);
+		chain->hookstr       =
+			hooknum2str(chain->handle.family, chain->hooknum);
 		chain->priority      =
 			nft_chain_attr_get_s32(nlc, NFT_CHAIN_ATTR_PRIO);
 		chain->type          =
diff --git a/src/rule.c b/src/rule.c
index 39b4d9a..993f970 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -408,7 +408,7 @@ const char *family2str(unsigned int family)
 	return "unknown";
 }
 
-static const char *hooknum2str(unsigned int family, unsigned int hooknum)
+const char *hooknum2str(unsigned int family, unsigned int hooknum)
 {
 	switch (family) {
 	case NFPROTO_IPV4:
@@ -466,8 +466,7 @@ static void chain_print(const struct chain *chain)
 	printf("\tchain %s {\n", chain->handle.chain);
 	if (chain->flags & CHAIN_F_BASECHAIN) {
 		printf("\t\ttype %s hook %s priority %d; policy %s;\n",
-		       chain->type,
-		       hooknum2str(chain->handle.family, chain->hooknum),
+		       chain->type, chain->hookstr,
 		       chain->priority, chain_policy2str(chain->policy));
 	}
 	list_for_each_entry(rule, &chain->rules, list) {
@@ -488,8 +487,7 @@ void chain_print_plain(const struct chain *chain)
 
 	if (chain->flags & CHAIN_F_BASECHAIN) {
 		printf(" { type %s hook %s priority %d; policy %s; }",
-		       chain->type,
-		       hooknum2str(chain->handle.family, chain->hooknum),
+		       chain->type, chain->hookstr,
 		       chain->priority, chain_policy2str(chain->policy));
 	}
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH nft 3/3] rule: add do_list_tables()
  2015-07-06 17:06 [PATCH nft 1/3] rule: missing family when listing of tables Pablo Neira Ayuso
  2015-07-06 17:06 ` [PATCH nft 2/3] src: set chain->hookstr from delinearization Pablo Neira Ayuso
@ 2015-07-06 17:06 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2015-07-06 17:06 UTC (permalink / raw)
  To: netfilter-devel; +Cc: kaber

Wrap code to list existing tables in a function.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/rule.c |   29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/rule.c b/src/rule.c
index 993f970..c7a4ef8 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -900,6 +900,18 @@ static int do_list_ruleset(struct netlink_ctx *ctx, struct cmd *cmd)
 	return 0;
 }
 
+static int do_list_tables(void)
+{
+	struct table *table;
+
+	list_for_each_entry(table, &table_list, list)
+		printf("table %s %s\n",
+		       family2str(table->handle.family),
+		       table->handle.table);
+
+	return 0;
+}
+
 static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 {
 	struct table *table = NULL;
@@ -917,21 +929,8 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 
 	switch (cmd->obj) {
 	case CMD_OBJ_TABLE:
-		if (!cmd->handle.table) {
-			/* List all existing tables */
-			struct table *table;
-
-			if (netlink_list_tables(ctx, &cmd->handle,
-						&cmd->location) < 0)
-				return -1;
-
-			list_for_each_entry(table, &ctx->list, list) {
-				printf("table %s %s\n",
-				       family2str(table->handle.family),
-				       table->handle.table);
-			}
-			return 0;
-		}
+		if (!cmd->handle.table)
+			return do_list_tables();
 		return do_list_table(ctx, cmd, table);
 	case CMD_OBJ_CHAIN:
 		return do_list_table(ctx, cmd, table);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-06 17:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-06 17:06 [PATCH nft 1/3] rule: missing family when listing of tables Pablo Neira Ayuso
2015-07-06 17:06 ` [PATCH nft 2/3] src: set chain->hookstr from delinearization Pablo Neira Ayuso
2015-07-06 17:06 ` [PATCH nft 3/3] rule: add do_list_tables() Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.