All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft] exthdr: fix type number saved in udata
@ 2021-11-29 23:50 Florian Westphal
  2021-11-30 12:27 ` Phil Sutter
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Westphal @ 2021-11-29 23:50 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

This should store the index of the protocol template, but
x[i] - x[0] is always i, so remove the divide.  Also add test case.

Fixes: 01fbc1574b9e ("exthdr: add parse and build userdata interface")
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/exthdr.c                                       | 4 +---
 tests/shell/testcases/sets/dumps/typeof_sets_0.nft | 5 +++++
 tests/shell/testcases/sets/typeof_sets_0           | 5 +++++
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/exthdr.c b/src/exthdr.c
index 22a08b0c9c2b..00d338f07302 100644
--- a/src/exthdr.c
+++ b/src/exthdr.c
@@ -165,9 +165,7 @@ static struct expr *exthdr_expr_parse_udata(const struct nftnl_udata *attr)
 static unsigned int expr_exthdr_type(const struct exthdr_desc *desc,
 				     const struct proto_hdr_template *tmpl)
 {
-	unsigned int offset = (unsigned int)(tmpl - &desc->templates[0]);
-
-	return offset / sizeof(*tmpl);
+	return (unsigned int)(tmpl - &desc->templates[0]);
 }
 
 static int exthdr_expr_build_udata(struct nftnl_udata_buf *udbuf,
diff --git a/tests/shell/testcases/sets/dumps/typeof_sets_0.nft b/tests/shell/testcases/sets/dumps/typeof_sets_0.nft
index 565369fb7be5..06d891e682b7 100644
--- a/tests/shell/testcases/sets/dumps/typeof_sets_0.nft
+++ b/tests/shell/testcases/sets/dumps/typeof_sets_0.nft
@@ -14,6 +14,11 @@ table inet t {
 		elements = { 2, 3, 103 }
 	}
 
+	set s4 {
+		typeof frag frag-off
+		elements = { 1, 1024 }
+	}
+
 	chain c1 {
 		osf name @s1 accept
 	}
diff --git a/tests/shell/testcases/sets/typeof_sets_0 b/tests/shell/testcases/sets/typeof_sets_0
index 9b2712e56177..a6ff8ca772e2 100755
--- a/tests/shell/testcases/sets/typeof_sets_0
+++ b/tests/shell/testcases/sets/typeof_sets_0
@@ -20,6 +20,11 @@ EXPECTED="table inet t {
 		elements = { 2, 3, 103 }
 	}
 
+	set s4 {
+		typeof frag frag-off
+		elements = { 1, 1024 }
+	}
+
 	chain c1 {
 		osf name @s1 accept
 	}
-- 
2.32.0


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

* Re: [PATCH nft] exthdr: fix type number saved in udata
  2021-11-29 23:50 [PATCH nft] exthdr: fix type number saved in udata Florian Westphal
@ 2021-11-30 12:27 ` Phil Sutter
  0 siblings, 0 replies; 2+ messages in thread
From: Phil Sutter @ 2021-11-30 12:27 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

On Tue, Nov 30, 2021 at 12:50:53AM +0100, Florian Westphal wrote:
> This should store the index of the protocol template, but
> x[i] - x[0] is always i, so remove the divide.  Also add test case.

This should read '&x[i] - &x[0]'.

> Fixes: 01fbc1574b9e ("exthdr: add parse and build userdata interface")
> Signed-off-by: Florian Westphal <fw@strlen.de>

Acked-by: Phil Sutter <phil@nwl.cc>


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

end of thread, other threads:[~2021-11-30 12:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-29 23:50 [PATCH nft] exthdr: fix type number saved in udata Florian Westphal
2021-11-30 12:27 ` Phil Sutter

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.