Netfilter-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [nft PATCH] mnl: Replace use of untyped nftnl data setters
@ 2019-10-29 12:54 Phil Sutter
  2019-10-30 12:45 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Sutter @ 2019-10-29 12:54 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

Setting strings won't make a difference, but passing data length to
*_set_data() functions allows for catching accidental changes on either
side.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/mnl.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/mnl.c b/src/mnl.c
index 75ab07b045aa5..5b0569f37b27e 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -695,7 +695,7 @@ int mnl_nft_table_add(struct netlink_ctx *ctx, const struct cmd *cmd,
 		memory_allocation_error();
 
 	nftnl_table_set_u32(nlt, NFTNL_TABLE_FAMILY, cmd->handle.family);
-	nftnl_table_set(nlt, NFTNL_TABLE_NAME, cmd->handle.table.name);
+	nftnl_table_set_str(nlt, NFTNL_TABLE_NAME, cmd->handle.table.name);
 	if (cmd->table)
 		nftnl_table_set_u32(nlt, NFTNL_TABLE_FLAGS, cmd->table->flags);
 	else
@@ -724,7 +724,8 @@ int mnl_nft_table_del(struct netlink_ctx *ctx, const struct cmd *cmd)
 
 	nftnl_table_set_u32(nlt, NFTNL_TABLE_FAMILY, cmd->handle.family);
 	if (cmd->handle.table.name)
-		nftnl_table_set(nlt, NFTNL_TABLE_NAME, cmd->handle.table.name);
+		nftnl_table_set_str(nlt, NFTNL_TABLE_NAME,
+				    cmd->handle.table.name);
 	else if (cmd->handle.handle.id)
 		nftnl_table_set_u64(nlt, NFTNL_TABLE_HANDLE,
 				    cmd->handle.handle.id);
@@ -1016,8 +1017,9 @@ int mnl_nft_obj_add(struct netlink_ctx *ctx, const struct cmd *cmd,
 		if (obj->ct_timeout.l3proto)
 			nftnl_obj_set_u16(nlo, NFTNL_OBJ_CT_TIMEOUT_L3PROTO,
 					  obj->ct_timeout.l3proto);
-		nftnl_obj_set(nlo, NFTNL_OBJ_CT_TIMEOUT_ARRAY,
-			      obj->ct_timeout.timeout);
+		nftnl_obj_set_data(nlo, NFTNL_OBJ_CT_TIMEOUT_ARRAY,
+				   obj->ct_timeout.timeout,
+				   sizeof(obj->ct_timeout.timeout));
 		break;
 	case NFT_OBJECT_CT_EXPECT:
 		if (obj->ct_expect.l3proto)
@@ -1418,7 +1420,8 @@ int mnl_nft_flowtable_add(struct netlink_ctx *ctx, const struct cmd *cmd,
 		dev_array[i++] = expr->identifier;
 
 	dev_array[i] = NULL;
-	nftnl_flowtable_set(flo, NFTNL_FLOWTABLE_DEVICES, dev_array);
+	nftnl_flowtable_set_data(flo, NFTNL_FLOWTABLE_DEVICES,
+				 dev_array, sizeof(dev_array));
 
 	netlink_dump_flowtable(flo, ctx);
 
-- 
2.23.0


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

* Re: [nft PATCH] mnl: Replace use of untyped nftnl data setters
  2019-10-29 12:54 [nft PATCH] mnl: Replace use of untyped nftnl data setters Phil Sutter
@ 2019-10-30 12:45 ` Pablo Neira Ayuso
  2019-10-30 14:26   ` Phil Sutter
  0 siblings, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2019-10-30 12:45 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel

On Tue, Oct 29, 2019 at 01:54:20PM +0100, Phil Sutter wrote:
> Setting strings won't make a difference, but passing data length to
> *_set_data() functions allows for catching accidental changes on either
> side.
> 
> Signed-off-by: Phil Sutter <phil@nwl.cc>

Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>

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

* Re: [nft PATCH] mnl: Replace use of untyped nftnl data setters
  2019-10-30 12:45 ` Pablo Neira Ayuso
@ 2019-10-30 14:26   ` Phil Sutter
  0 siblings, 0 replies; 4+ messages in thread
From: Phil Sutter @ 2019-10-30 14:26 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

On Wed, Oct 30, 2019 at 01:45:20PM +0100, Pablo Neira Ayuso wrote:
> On Tue, Oct 29, 2019 at 01:54:20PM +0100, Phil Sutter wrote:
> > Setting strings won't make a difference, but passing data length to
> > *_set_data() functions allows for catching accidental changes on either
> > side.
> > 
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> 
> Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>

Applied after resolving merge conflict with previous commits. Apart from
a context change, data_len argument passed to *_data() functions needed
an update as well since data is no longer an array on stack but
dynamically allocated.

I made sure code compiles without warnings and both shell and py
testsuites pass (apart from unrelated warnings the latter yields).

Thanks, Phil

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

* [nft PATCH] mnl: Replace use of untyped nftnl data setters
@ 2019-10-28 22:38 Phil Sutter
  0 siblings, 0 replies; 4+ messages in thread
From: Phil Sutter @ 2019-10-28 22:38 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

Setting strings won't make a difference, but passing data length to
*_set_data() functions catches accidental changes on either side.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/mnl.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/mnl.c b/src/mnl.c
index 75ab07b045aa5..5b0569f37b27e 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -695,7 +695,7 @@ int mnl_nft_table_add(struct netlink_ctx *ctx, const struct cmd *cmd,
 		memory_allocation_error();
 
 	nftnl_table_set_u32(nlt, NFTNL_TABLE_FAMILY, cmd->handle.family);
-	nftnl_table_set(nlt, NFTNL_TABLE_NAME, cmd->handle.table.name);
+	nftnl_table_set_str(nlt, NFTNL_TABLE_NAME, cmd->handle.table.name);
 	if (cmd->table)
 		nftnl_table_set_u32(nlt, NFTNL_TABLE_FLAGS, cmd->table->flags);
 	else
@@ -724,7 +724,8 @@ int mnl_nft_table_del(struct netlink_ctx *ctx, const struct cmd *cmd)
 
 	nftnl_table_set_u32(nlt, NFTNL_TABLE_FAMILY, cmd->handle.family);
 	if (cmd->handle.table.name)
-		nftnl_table_set(nlt, NFTNL_TABLE_NAME, cmd->handle.table.name);
+		nftnl_table_set_str(nlt, NFTNL_TABLE_NAME,
+				    cmd->handle.table.name);
 	else if (cmd->handle.handle.id)
 		nftnl_table_set_u64(nlt, NFTNL_TABLE_HANDLE,
 				    cmd->handle.handle.id);
@@ -1016,8 +1017,9 @@ int mnl_nft_obj_add(struct netlink_ctx *ctx, const struct cmd *cmd,
 		if (obj->ct_timeout.l3proto)
 			nftnl_obj_set_u16(nlo, NFTNL_OBJ_CT_TIMEOUT_L3PROTO,
 					  obj->ct_timeout.l3proto);
-		nftnl_obj_set(nlo, NFTNL_OBJ_CT_TIMEOUT_ARRAY,
-			      obj->ct_timeout.timeout);
+		nftnl_obj_set_data(nlo, NFTNL_OBJ_CT_TIMEOUT_ARRAY,
+				   obj->ct_timeout.timeout,
+				   sizeof(obj->ct_timeout.timeout));
 		break;
 	case NFT_OBJECT_CT_EXPECT:
 		if (obj->ct_expect.l3proto)
@@ -1418,7 +1420,8 @@ int mnl_nft_flowtable_add(struct netlink_ctx *ctx, const struct cmd *cmd,
 		dev_array[i++] = expr->identifier;
 
 	dev_array[i] = NULL;
-	nftnl_flowtable_set(flo, NFTNL_FLOWTABLE_DEVICES, dev_array);
+	nftnl_flowtable_set_data(flo, NFTNL_FLOWTABLE_DEVICES,
+				 dev_array, sizeof(dev_array));
 
 	netlink_dump_flowtable(flo, ctx);
 
-- 
2.23.0


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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-29 12:54 [nft PATCH] mnl: Replace use of untyped nftnl data setters Phil Sutter
2019-10-30 12:45 ` Pablo Neira Ayuso
2019-10-30 14:26   ` Phil Sutter
  -- strict thread matches above, loose matches on Subject: below --
2019-10-28 22:38 Phil Sutter

Netfilter-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netfilter-devel/0 netfilter-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netfilter-devel netfilter-devel/ https://lore.kernel.org/netfilter-devel \
		netfilter-devel@vger.kernel.org
	public-inbox-index netfilter-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netfilter-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git