Skip to contentSkip to conversation

exthdr: fix type number saved in udata

PATCH In review Florian Westphal 2 participants 2 messages Nov 29, 2021 – Nov 30, 2021 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 exthdr: fix type number saved in udata

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")
---
 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(-)
src/exthdr.c +1 -3
index 22a08b0c9c2b..00d338f07302 100644
@@ -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,
tests/shell/testcases/sets/dumps/typeof_sets_0.nft +5 -0
index 565369fb7be5..06d891e682b7 100644
@@ -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
 	}
tests/shell/testcases/sets/typeof_sets_0 +5 -0
index 9b2712e56177..a6ff8ca772e2 100755
@@ -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
 	}
Signature · 1 line
2.32.0