netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>, netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft 3/3] netlink_linearize: skip set element expression in map statement key
Date: Tue, 26 Sep 2023 17:58:31 +0200	[thread overview]
Message-ID: <ZRL/p+d/rIGhLCLh@calendula> (raw)
In-Reply-To: <ZRL9dlPZbt9pVir5@orbyte.nwl.cc>

On Tue, Sep 26, 2023 at 05:49:10PM +0200, Phil Sutter wrote:
> On Tue, Sep 26, 2023 at 05:25:00PM +0200, Pablo Neira Ayuso wrote:
> > This fix is similar to 22d201010919 ("netlink_linearize: skip set element
> > expression in set statement key") to fix map statement.
> > 
> > netlink_gen_map_stmt() relies on the map key, that is expressed as a set
> > element. Use the set element key instead to skip the set element wrap,
> > otherwise get_register() abort execution:
> > 
> >   nft: netlink_linearize.c:650: netlink_gen_expr: Assertion `dreg < ctx->reg_low' failed.
> > 
> > Reported-by: Luci Stanescu <luci@cnix.ro>
> > Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> 
> This patch adds map stmt printing and parsing support to JSON, but not a
> word about that in the commit message. Did this slip in by accident
> (e.g.  'git commit -a')? Anyway, I think it should go into a separate
> patch.

Not accidental.

I just added complete JSON, it has been time consuming, I initially
thought about fixing this issue only and leave JSON alone unfixed, but
looking at recent stuff, that will backfire sooner or later.

I took the existing set statement support and extend it to have a
"data" field to store the data mapping.

> [...]
> > diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
> > index 53a318aa2e62..99ed9f387a81 100644
> > --- a/src/netlink_linearize.c
> > +++ b/src/netlink_linearize.c
> > @@ -1585,13 +1585,13 @@ static void netlink_gen_map_stmt(struct netlink_linearize_ctx *ctx,
> >  	int num_stmts = 0;
> >  	struct stmt *this;
> >  
> > -	sreg_key = get_register(ctx, stmt->map.key);
> > -	netlink_gen_expr(ctx, stmt->map.key, sreg_key);
> > +	sreg_key = get_register(ctx, stmt->set.key->key);
> > +	netlink_gen_expr(ctx, stmt->set.key->key, sreg_key);
> >  
> >  	sreg_data = get_register(ctx, stmt->map.data);
> >  	netlink_gen_expr(ctx, stmt->map.data, sreg_data);
> >  
> > -	release_register(ctx, stmt->map.key);
> > +	release_register(ctx, stmt->set.key->key);
> >  	release_register(ctx, stmt->map.data);
> >  
> >  	nle = alloc_nft_expr("dynset");
> 
> Any particular reason why this doesn't just use stmt->map.key->key? The

It should use map.key->key, yes.

> first two fields in structs set_stmt and map_stmt are identical, so the
> above works "by accident".

Exactly.

I will fix and send a v2.

      reply	other threads:[~2023-09-26 15:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-26 15:24 [PATCH nft 1/3] tests: py: add map support Pablo Neira Ayuso
2023-09-26 15:24 ` [PATCH nft 2/3] json: expose dynamic flag Pablo Neira Ayuso
2023-09-26 15:36   ` Phil Sutter
2023-09-26 15:25 ` [PATCH nft 3/3] netlink_linearize: skip set element expression in map statement key Pablo Neira Ayuso
2023-09-26 15:49   ` Phil Sutter
2023-09-26 15:58     ` Pablo Neira Ayuso [this message]

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=ZRL/p+d/rIGhLCLh@calendula \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=phil@nwl.cc \
    /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).