From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft 3/4] netlink_delinearize: also consider exthdr type when trimming binops
Date: Thu, 27 Feb 2025 15:52:09 +0100 [thread overview]
Message-ID: <20250227145214.27730-4-fw@strlen.de> (raw)
In-Reply-To: <20250227145214.27730-1-fw@strlen.de>
This allows trimming the binop for exthdrs, this will make nft render
(tcp option mptcp unknown & 240) >> 4 . ip saddr @s1
as
tcp option mptcp subtype . ip saddr @s1
Also extend the typeof set tests with a set concatenating a
sub-byte-sized exthdr expression with a payload one.
The additional call to expr_postprocess() is needed, without this,
typeof_sets_0.nft fails because
frag frag-off @s4 accept
is shown as
meta nfproto ipv6 frag frag-off @s4 accept
Previouly, EXPR_EXTHDR would cause payload_binop_postprocess()
to return false which will then make the caller invoke
expr_postprocess(), but after handling EXPR_EXTHDR this doesn't happen
anymore.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
src/netlink_delinearize.c | 10 +++++++++-
.../testcases/sets/dumps/typeof_sets_0.nft | 10 ++++++++++
tests/shell/testcases/sets/typeof_sets_0 | 19 +++++++++++++++++++
3 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index b629916ebff8..698bae85c8cc 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -2655,8 +2655,16 @@ static bool payload_binop_postprocess(struct rule_pp_ctx *ctx,
if (expr->left->etype != EXPR_BINOP || expr->left->op != OP_AND)
return false;
- if (expr->left->left->etype != EXPR_PAYLOAD)
+ switch (expr->left->left->etype) {
+ case EXPR_EXTHDR:
+ break;
+ case EXPR_PAYLOAD:
+ break;
+ default:
return false;
+ }
+
+ expr_postprocess(ctx, &expr->left->left);
expr_set_type(expr->right, &integer_type,
BYTEORDER_HOST_ENDIAN);
diff --git a/tests/shell/testcases/sets/dumps/typeof_sets_0.nft b/tests/shell/testcases/sets/dumps/typeof_sets_0.nft
index ed45d84a0eff..34aaab601cda 100644
--- a/tests/shell/testcases/sets/dumps/typeof_sets_0.nft
+++ b/tests/shell/testcases/sets/dumps/typeof_sets_0.nft
@@ -65,6 +65,12 @@ table inet t {
elements = { mp-join, dss }
}
+ set s14 {
+ typeof tcp option mptcp subtype . ip daddr
+ elements = { remove-addr . 10.1.1.1,
+ mp-join . 10.1.1.2 }
+ }
+
chain c1 {
osf name @s1 accept
}
@@ -112,4 +118,8 @@ table inet t {
chain c13 {
tcp option mptcp subtype @s13 accept
}
+
+ chain c14 {
+ tcp option mptcp subtype . ip saddr @s14 accept
+ }
}
diff --git a/tests/shell/testcases/sets/typeof_sets_0 b/tests/shell/testcases/sets/typeof_sets_0
index 5ba7fc76ce15..ef2726db3b30 100755
--- a/tests/shell/testcases/sets/typeof_sets_0
+++ b/tests/shell/testcases/sets/typeof_sets_0
@@ -124,6 +124,11 @@ INPUT="table inet t {$INPUT_OSF_SET
typeof tcp option mptcp subtype
elements = { mp-join, dss }
}
+
+ set s14 {
+ typeof tcp option mptcp subtype . ip daddr
+ elements = { remove-addr . 10.1.1.1, mp-join . 10.1.1.2 }
+ }
$INPUT_OSF_CHAIN
chain c2 {
ether type vlan vlan id @s2 accept
@@ -157,6 +162,10 @@ $INPUT_VERSION_CHAIN
chain c13 {
tcp option mptcp subtype @s13 accept
}
+
+ chain c14 {
+ tcp option mptcp subtype . ip saddr @s14 accept
+ }
}"
EXPECTED="table inet t {$INPUT_OSF_SET
@@ -210,6 +219,12 @@ $INPUT_VERSION_SET
typeof tcp option mptcp subtype
elements = { mp-join, dss }
}
+
+ set s14 {
+ typeof tcp option mptcp subtype . ip daddr
+ elements = { remove-addr . 10.1.1.1,
+ mp-join . 10.1.1.2 }
+ }
$INPUT_OSF_CHAIN
chain c2 {
vlan id @s2 accept
@@ -242,6 +257,10 @@ $INPUT_SCTP_CHAIN$INPUT_VERSION_CHAIN
chain c13 {
tcp option mptcp subtype @s13 accept
}
+
+ chain c14 {
+ tcp option mptcp subtype . ip saddr @s14 accept
+ }
}"
--
2.45.3
next prev parent reply other threads:[~2025-02-27 14:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 14:52 [PATCH nft 0/4] add mptcp suboption mnemonics Florian Westphal
2025-02-27 14:52 ` [PATCH nft 1/4] tcpopt: add symbol table for mptcp suboptions Florian Westphal
2025-02-27 14:52 ` [PATCH nft 2/4] expression: propagate key datatype for anonymous sets Florian Westphal
2025-02-27 14:52 ` Florian Westphal [this message]
2025-02-27 14:52 ` [PATCH nft 4/4] expression: expr_build_udata_recurse should recurse Florian Westphal
2025-03-05 21:03 ` [PATCH nft 0/4] add mptcp suboption mnemonics Pablo Neira Ayuso
2025-03-05 22:40 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250227145214.27730-4-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.