Netfilter-Devel Archive mirror
 help / color / mirror / Atom feed
From: Jeremy Sowden <jeremy@azazel.net>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Netfilter Devel <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH nftables] evaluate: add support for variables in map expressions
Date: Wed, 3 Apr 2024 08:38:41 +0100	[thread overview]
Message-ID: <20240403073841.GA907770@celephais.dreamlands> (raw)
In-Reply-To: <ZgyJ8yUi8CyOpEHX@calendula>

[-- Attachment #1: Type: text/plain, Size: 2380 bytes --]

On 2024-04-03, at 00:42:59 +0200, Pablo Neira Ayuso wrote:
> On Sun, Mar 24, 2024 at 02:59:07PM +0000, Jeremy Sowden wrote:
> > It is possible to use a variable to initialize a map, which is then used in a
> > map statement:
> > 
> >   define m = { ::1234 : 5678 }
> > 
> >   table ip6 nat {
> >     map m {
> >       typeof ip6 daddr : tcp dport;
> >       elements = $m
> >     }
> >     chain prerouting {
> >       ip6 nexthdr tcp redirect to ip6 daddr map @m
> >     }
> >   }
> > 
> > However, if one tries to use the variable directly in the statement:
> > 
> >   define m = { ::1234 : 5678 }
> > 
> >   table ip6 nat {
> >     chain prerouting {
> >       ip6 nexthdr tcp redirect to ip6 daddr map $m
> >     }
> >   }
> > 
> > nft rejects it:
> > 
> >   /space/azazel/tmp/ruleset.1067161.nft:5:47-48: Error: invalid mapping expression variable
> >       ip6 nexthdr tcp redirect to ip6 daddr map $m
> >                                   ~~~~~~~~~     ^^
> > 
> > Extend `expr_evaluate_map` to allow it.
> > 
> > Add a test-case.
> 
> Thanks for your patch.
> 
> > Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1067161
> > Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> > ---
> >  src/evaluate.c                                |  1 +
> >  .../shell/testcases/maps/anonymous_snat_map_1 | 16 +++++
> >  .../maps/dumps/anonymous_snat_map_1.json-nft  | 58 +++++++++++++++++++
> >  .../maps/dumps/anonymous_snat_map_1.nft       |  5 ++
> >  4 files changed, 80 insertions(+)
> >  create mode 100755 tests/shell/testcases/maps/anonymous_snat_map_1
> >  create mode 100644 tests/shell/testcases/maps/dumps/anonymous_snat_map_1.json-nft
> >  create mode 100644 tests/shell/testcases/maps/dumps/anonymous_snat_map_1.nft
> > 
> > diff --git a/src/evaluate.c b/src/evaluate.c
> > index 1682ba58989e..d49213f8d6bd 100644
> > --- a/src/evaluate.c
> > +++ b/src/evaluate.c
> > @@ -2061,6 +2061,7 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
> 
> expr_evaluate_objmap() also needs a similar fix.

Cool.  Will update and resend.

J.

> >  	mappings->set_flags |= NFT_SET_MAP;
> >  
> >  	switch (map->mappings->etype) {
> > +	case EXPR_VARIABLE:
> >  	case EXPR_SET:
> >  		if (ctx->ectx.key && ctx->ectx.key->etype == EXPR_CONCAT) {
> >  			key = expr_clone(ctx->ectx.key);

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2024-04-03  7:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-24 14:59 [PATCH nftables] evaluate: add support for variables in map expressions Jeremy Sowden
2024-03-24 14:59 ` [PATCH nftables] tests: shell: packetpath/flowtables: open all temporary files in /tmp Jeremy Sowden
2024-04-01 15:02   ` Pablo Neira Ayuso
2024-04-02 22:42 ` [PATCH nftables] evaluate: add support for variables in map expressions Pablo Neira Ayuso
2024-04-03  7:38   ` Jeremy Sowden [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=20240403073841.GA907770@celephais.dreamlands \
    --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 read-only IMAP folder(s) and NNTP newsgroup(s).