From: Jeremy Sowden <jeremy@azazel.net>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Netfilter Devel <netfilter-devel@vger.kernel.org>
Subject: Re: [nft PATCH v4 09/32] netlink_delinearize: add postprocessing for payload binops
Date: Tue, 1 Nov 2022 18:46:50 +0000 [thread overview]
Message-ID: <Y2FpmnPVGzUNFeIc@azazel.net> (raw)
In-Reply-To: <YovCDObeM32n8uvT@salvia>
[-- Attachment #1: Type: text/plain, Size: 3456 bytes --]
On 2022-05-23, at 19:19:08 +0200, Pablo Neira Ayuso wrote:
> On Mon, Apr 04, 2022 at 01:13:47PM +0100, Jeremy Sowden wrote:
> > If a user uses a payload expression as a statement argument:
> >
> > nft add rule t c meta mark set ip dscp lshift 2 or 0x10
> >
> > we may need to undo munging during delinearization.
> >
> > Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> > ---
> > src/netlink_delinearize.c | 39 +++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 39 insertions(+)
> >
> > diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
> > index 733977bc526d..12624db4c3a5 100644
> > --- a/src/netlink_delinearize.c
> > +++ b/src/netlink_delinearize.c
> > @@ -2454,6 +2454,42 @@ static void relational_binop_postprocess(struct rule_pp_ctx *ctx,
> > }
> > }
> >
> > +static bool payload_binop_postprocess(struct rule_pp_ctx *ctx,
> > + struct expr **exprp)
> > +{
> > + struct expr *expr = *exprp;
> > +
> > + if (expr->op != OP_RSHIFT)
> > + return false;
> > +
> > + if (expr->left->etype == EXPR_UNARY) {
> > + /*
> > + * If the payload value was originally in a different byte-order
> > + * from the payload expression, there will be a byte-order
> > + * conversion to remove.
> > + */
>
> The comment assumes this is a payload expression, the unary is
> stripped off here...
>
> > + struct expr *left = expr_get(expr->left->arg);
> > + expr_free(expr->left);
> > + expr->left = left;
> > + }
> > +
> > + if (expr->left->etype != EXPR_BINOP || expr->left->op != OP_AND)
> > + return false;
> > +
> > + if (expr->left->left->etype != EXPR_PAYLOAD)
>
> ... but the check for payload is coming here.
Will fix.
> I assume this postprocessing is to undo the switch from network
> byteorder to host byteorder for the ip dscp of the example above?
>
> Could you describe an example expression tree to depict this
> delinearize scenario?
Currently, demunging is only done for payload statement expressions, in
`stmt_payload_postprocess`. However, this patch-set will lead to the
appearance of munged payload expressions in other contexts, such as the
example given above in the commit message:
nft add rule t c meta mark set ip dscp lshift 2 or 0x10
The expression tree for the value assigned to `meta mark` is:
OR
/ \
LSHIFT 0x10
/ \
RSHIFT 2
/ \
AND 2
/ \
@nh(8,8) 0xfc
and the `@nh(8,8) & 0xfc >> 2` expression needs to be demunged to `ip dscp`.
> > + return false;
> > +
> > + expr_set_type(expr->right, &integer_type,
> > + BYTEORDER_HOST_ENDIAN);
> > + expr_postprocess(ctx, &expr->right);
> > +
> > + binop_postprocess(ctx, expr, &expr->left);
> > + *exprp = expr_get(expr->left);
> > + expr_free(expr);
> > +
> > + return true;
> > +}
> > +
> > static struct expr *string_wildcard_expr_alloc(struct location *loc,
> > const struct expr *mask,
> > const struct expr *expr)
> > @@ -2566,6 +2602,9 @@ static void expr_postprocess(struct rule_pp_ctx *ctx, struct expr **exprp)
> > expr_set_type(expr, expr->arg->dtype, !expr->arg->byteorder);
> > break;
> > case EXPR_BINOP:
> > + if (payload_binop_postprocess(ctx, exprp))
> > + break;
> > +
> > expr_postprocess(ctx, &expr->left);
> > switch (expr->op) {
> > case OP_LSHIFT:
> > --
> > 2.35.1
> >
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2022-11-01 18:46 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-04 12:13 [nft PATCH v4 00/32] Extend values assignable to packet marks and payload fields Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 01/32] examples: add .gitignore file Jeremy Sowden
2022-04-05 11:26 ` Florian Westphal
2022-04-04 12:13 ` [nft PATCH v4 02/32] include: add missing `#include` Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 03/32] src: move `byteorder_names` array Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 04/32] datatype: support `NULL` symbol-tables when printing constants Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 05/32] ct: support `NULL` symbol-tables when looking up labels Jeremy Sowden
2022-04-05 11:15 ` Florian Westphal
2022-04-05 15:29 ` Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 06/32] include: update nf_tables.h Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 07/32] include: add new bitwise bit-length attribute to nf_tables.h Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 08/32] netlink: send bit-length of bitwise binops to kernel Jeremy Sowden
2022-05-23 17:03 ` Pablo Neira Ayuso
2022-11-01 18:46 ` Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 09/32] netlink_delinearize: add postprocessing for payload binops Jeremy Sowden
2022-05-23 17:19 ` Pablo Neira Ayuso
2022-11-01 18:46 ` Jeremy Sowden [this message]
2022-04-04 12:13 ` [nft PATCH v4 10/32] netlink_delinearize: correct type and byte-order of shifts Jeremy Sowden
2022-05-23 17:19 ` Pablo Neira Ayuso
2022-11-01 18:47 ` Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 11/32] netlink_delinearize: correct length of right bitwise operand Jeremy Sowden
2022-05-23 17:22 ` Pablo Neira Ayuso
2022-11-01 18:47 ` Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 12/32] payload: set byte-order when completing expression Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 13/32] evaluate: support shifts larger than the width of the left operand Jeremy Sowden
2022-05-23 17:42 ` Pablo Neira Ayuso
2022-11-01 18:47 ` Jeremy Sowden
2023-02-07 12:05 ` Pablo Neira Ayuso
2023-03-04 12:00 ` Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 14/32] evaluate: relax type-checking for integer arguments in mark statements Jeremy Sowden
2022-05-23 17:33 ` Pablo Neira Ayuso
2022-04-04 12:13 ` [nft PATCH v4 15/32] tests: shell: rename some test-cases Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 16/32] tests: shell: add test-cases for ct and packet mark payload expressions Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 17/32] tests: py: " Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 18/32] include: add new bitwise boolean attributes to nf_tables.h Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 19/32] evaluate: don't eval unary arguments Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 20/32] evaluate: prevent nested byte-order conversions Jeremy Sowden
2022-04-04 12:13 ` [nft PATCH v4 21/32] evaluate: don't clobber binop lengths Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 22/32] evaluate: insert byte-order conversions for expressions between 9 and 15 bits Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 23/32] evaluate: set eval context to leftmost bitwise operand Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 24/32] netlink_delinearize: fix typo Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 25/32] netlink_delinearize: refactor stmt_payload_binop_postprocess Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 26/32] netlink_delinearize: add support for processing variable payload statement arguments Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 27/32] netlink: rename bitwise operation functions Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 28/32] netlink: support (de)linearization of new bitwise boolean operations Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 29/32] parser_json: allow RHS ct, meta and payload expressions Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 30/32] evaluate: allow binop expressions with variable right-hand operands Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 31/32] tests: shell: add tests for binops with variable RHS operands Jeremy Sowden
2022-04-04 12:14 ` [nft PATCH v4 32/32] tests: py: " Jeremy Sowden
2022-04-09 8:30 ` [nft PATCH v4 00/32] Extend values assignable to packet marks and payload fields Kevin 'ldir' Darbyshire-Bryant
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=Y2FpmnPVGzUNFeIc@azazel.net \
--to=jeremy@azazel.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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;
as well as URLs for NNTP newsgroup(s).