]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
exthdr: fix type number saved in udata
authorFlorian Westphal <fw@strlen.de>
Mon, 29 Nov 2021 23:50:53 +0000 (00:50 +0100)
committerFlorian Westphal <fw@strlen.de>
Tue, 30 Nov 2021 12:51:24 +0000 (13:51 +0100)
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>
Acked-by: Phil Sutter <phil@nwl.cc>
src/exthdr.c
tests/shell/testcases/sets/dumps/typeof_sets_0.nft
tests/shell/testcases/sets/typeof_sets_0

index 22a08b0c9c2bfd485d820fbaeed2bc71de6704e7..00d338f07302b59fef06ced47c5019f8dcd45426 100644 (file)
@@ -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,
index 565369fb7be5b65ea8ff28b7d3cb55abb518fad2..06d891e682b743941375f86597c4f137234d839b 100644 (file)
@@ -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
        }
index 9b2712e5617777d5f93088f26123910600cea0e7..a6ff8ca772e255fd7dfd6c875b6f4d48f668f450 100755 (executable)
@@ -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
        }