From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft,v2 1/8] netlink_delinearize: correct type and byte-order of shifts
Date: Wed, 22 Mar 2023 22:52:56 +0100 [thread overview]
Message-ID: <20230322215303.239763-2-pablo@netfilter.org> (raw)
In-Reply-To: <20230322215303.239763-1-pablo@netfilter.org>
From: Jeremy Sowden <jeremy@azazel.net>
Downgrade to base type integer instead of the specific type from the
expression that is used in the shift operation.
Without this, listing a rule like:
ct mark set ip dscp lshift 2 or 0x10
will return:
ct mark set ip dscp << 2 | cs2
because the type of the OR's right operand will be transitively derived
from `ip dscp`. However, this is not valid syntax:
# nft add rule t c ct mark set ip dscp '<<' 2 '|' cs2
Error: Could not parse integer
add rule t c ct mark set ip dscp << 2 | cs2
^^^
Use xinteger_type to print the output in hexadecimal.
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/netlink_delinearize.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index 60350cd6cd96..c1b4c1148d33 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -2810,8 +2810,17 @@ static void expr_postprocess(struct rule_pp_ctx *ctx, struct expr **exprp)
}
expr_postprocess(ctx, &expr->right);
- expr_set_type(expr, expr->left->dtype,
- expr->left->byteorder);
+ switch (expr->op) {
+ case OP_LSHIFT:
+ case OP_RSHIFT:
+ expr_set_type(expr, &xinteger_type,
+ BYTEORDER_HOST_ENDIAN);
+ break;
+ default:
+ expr_set_type(expr, expr->left->dtype,
+ expr->left->byteorder);
+ }
+
break;
case EXPR_RELATIONAL:
switch (expr->left->etype) {
--
2.30.2
next prev parent reply other threads:[~2023-03-22 21:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-22 21:52 [PATCH nft,v2 0/8] mark statement support for non-constant expression Pablo Neira Ayuso
2023-03-22 21:52 ` Pablo Neira Ayuso [this message]
2023-03-22 21:52 ` [PATCH nft,v2 2/8] evaluate: support shifts larger than the width of the left operand Pablo Neira Ayuso
2023-03-22 21:52 ` [PATCH nft,v2 3/8] evaluate: don't eval unary arguments Pablo Neira Ayuso
2023-03-22 21:52 ` [PATCH nft,v2 4/8] evaluate: get length from statement instead of lhs expression Pablo Neira Ayuso
2023-03-22 21:53 ` [PATCH nft,v2 5/8] evaluate: relax type-checking for integer arguments in mark statements Pablo Neira Ayuso
2023-03-22 21:53 ` [PATCH nft,v2 6/8] tests: py: add test-cases for ct and packet mark payload expressions Pablo Neira Ayuso
2023-03-22 21:53 ` [PATCH nft,v2 7/8] tests: shell: rename and move bitwise test-cases Pablo Neira Ayuso
2023-03-22 21:53 ` [PATCH nft,v2 8/8] tests: shell: add test-cases for ct and packet mark payload expressions 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=20230322215303.239763-2-pablo@netfilter.org \
--to=pablo@netfilter.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox