All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft] evaluate: fix get element for concatenated set
Date: Tue, 5 Sep 2023 20:58:12 +0200	[thread overview]
Message-ID: <ZPd6RGiItVPcfGsi@calendula> (raw)
In-Reply-To: <20230905144141.9290-1-fw@strlen.de>

On Tue, Sep 05, 2023 at 04:41:38PM +0200, Florian Westphal wrote:
> given:
> table ip filter {
> 	set test {
> 		type ipv4_addr . ether_addr . mark
> 		flags interval
> 		elements = { 198.51.100.0/25 . 00:0b:0c:ca:cc:10-c1:a0:c1:cc:10:00 . 0x0000006f, }
> 	}
> }
> 
> We get lookup failure:
> 
> nft get element ip filter test { 198.51.100.1 . 00:0b:0c:ca:cc:10 . 0x6f }
> Error: Could not process rule: No such file or directory
> 
> Its possible to work around this via dummy range somewhere in the key, e.g.
> nft get element ip filter test { 198.51.100.1 . 00:0b:0c:ca:cc:10 . 0x6f-0x6f }
> 
> but that shouldn't be needed, so make sure the INTERVAL flag is enabled
> for the queried element if the set is of interval type.

LGTM, comment below:

> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  src/evaluate.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/src/evaluate.c b/src/evaluate.c
> index ab3ec98739e9..b1fe7147c2e1 100644
> --- a/src/evaluate.c
> +++ b/src/evaluate.c
> @@ -4500,11 +4500,14 @@ static int setelem_evaluate(struct eval_ctx *ctx, struct cmd *cmd)
>  		return -1;
>  
>  	cmd->elem.set = set_get(set);
> +	if (set_is_interval(ctx->set->flags)) {
> +		if (!(set->flags & NFT_SET_CONCAT) &&
> +		    interval_set_eval(ctx, ctx->set, cmd->expr) < 0)
> +			return -1;
>  
> -	if (set_is_interval(ctx->set->flags) &&
> -	    !(set->flags & NFT_SET_CONCAT) &&
> -	    interval_set_eval(ctx, ctx->set, cmd->expr) < 0)
> -		return -1;
> +		if (cmd->expr->etype == EXPR_SET)

setelem_evaluate() is always called for CMD_OBJ_ELEMENTS.

I think this branch always evaluates 'true'.

                if (cmd->expr->etype == EXPR_SET)


> +			cmd->expr->set_flags |= NFT_SET_INTERVAL;

so maybe set_flags inconditionally?

> +	}
>  
>  	ctx->set = NULL;
>  
> -- 
> 2.41.0
> 

      reply	other threads:[~2023-09-05 19:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-05 14:41 [PATCH nft] evaluate: fix get element for concatenated set Florian Westphal
2023-09-05 18: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=ZPd6RGiItVPcfGsi@calendula \
    --to=pablo@netfilter.org \
    --cc=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.