Skip to contentSkip to conversation

src: error if listing nonexistent table

PATCH In review Arturo Borrero Gonzalez 2 participants 3 messages Oct 10, 2013 – Oct 11, 2013 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src: error if listing nonexistent table

Here examples (foo table doesn't exist).

Before this patch:

# nft list table foo
table ip foo {
}

After:

# nft list table foo
<cmdline>:1:1-14: Error: Could not receive table from kernel: No such file or directory
list table foo
^^^^^^^^^^^^^^

BTW, netlink_get_table() seemed unused.

---
 src/mnl.c  |    2 ++
 src/rule.c |    2 ++
 2 files changed, 4 insertions(+)
src/mnl.c +2 -0
index 27b181a..4490411 100644
@@ -563,6 +563,8 @@ int mnl_nft_table_get(struct mnl_socket *nf_sock, struct nft_table *nlt,
 	nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE,
 					nft_table_attr_get_u32(nlt, NFT_TABLE_ATTR_FAMILY),
 					NLM_F_ACK, seq);
+	nft_table_nlmsg_build_payload(nlh, nlt);
+
 	return mnl_talk(nf_sock, nlh, nlh->nlmsg_len, table_get_cb, nlt);
 }
 
src/rule.c +2 -0
index 39a66d7..ff1193a 100644
@@ -610,6 +610,8 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 			return 0;
 		}
 		/* List content of this table */
+		if (netlink_get_table(ctx, &cmd->handle, &cmd->location) < 0)
+			return -1;
 		if (do_list_sets(ctx, &cmd->location, table) < 0)
 			return -1;
 		if (netlink_list_chains(ctx, &cmd->handle, &cmd->location) < 0)
#1 lore raw

Hi Arturo,

Quoted 7 lines · Arturo Borrero Gonzalez

Here examples (foo table doesn't exist).

Before this patch:

# nft list table foo
table ip foo {
}

I cannot reproduce this here:

<cmdline>:1:1-14: Error: Could not receive sets from kernel: No such file or directory
list table foo
^^^^^^^^^^^^^^

Quoted 8 lines

After:

# nft list table foo
<cmdline>:1:1-14: Error: Could not receive table from kernel: No such file or directory
list table foo
^^^^^^^^^^^^^^

BTW, netlink_get_table() seemed unused.

Yes, the original nftables code included it already, I guess expecting some usage at some point.

Quoted 37 lines
---
 src/mnl.c  |    2 ++
 src/rule.c |    2 ++
 2 files changed, 4 insertions(+)
src/mnl.c +2 -0
index 27b181a..4490411 100644
@@ -563,6 +563,8 @@ int mnl_nft_table_get(struct mnl_socket *nf_sock, struct nft_table *nlt,
 	nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE,
 					nft_table_attr_get_u32(nlt, NFT_TABLE_ATTR_FAMILY),
 					NLM_F_ACK, seq);
+	nft_table_nlmsg_build_payload(nlh, nlt);
+
 	return mnl_talk(nf_sock, nlh, nlh->nlmsg_len, table_get_cb, nlt);
 }
 
src/rule.c +2 -1
index 39a66d7..ff1193a 100644
@@ -610,6 +610,8 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 			return 0;
 		}
 		/* List content of this table */
+		if (netlink_get_table(ctx, &cmd->handle, &cmd->location) < 0)
+			return -1;
 		if (do_list_sets(ctx, &cmd->location, table) < 0)
 			return -1;
 		if (netlink_list_chains(ctx, &cmd->handle, &cmd->location) < 0)
 
--

To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 5 lines · Pablo Neira Ayuso

Hi Arturo,

Quoted 2 lines · Arturo Borrero Gonzalez

Here examples (foo table doesn't exist).

Quoted 7 lines
Quoted 5 lines

Before this patch:

# nft list table foo
table ip foo {
}

I cannot reproduce this here:

Right. I guess this only happen with the patch I sent the other day for the kernel to dump sets with NFPROTO_UNSPEC.

I will investigate and come back.

Signature · 5 lines
Arturo Borrero González
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html