All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft 1/7] src: normalize set element with EXPR_MAPPING
Date: Wed, 25 Nov 2026 01:18:18 +0100	[thread overview]
Message-ID: <awYpSv50FCy3yFhV@chamomile> (raw)
In-Reply-To: <awXRzNwL7JIR8InP@orbyte.nwl.cc>

Hi Phil,

On Tue, Nov 24, 2026 at 07:05:00PM +0100, Phil Sutter wrote:
> Hi Pablo,
> 
> On Fri, Sep 05, 2025 at 05:36:21PM +0200, Pablo Neira Ayuso wrote:
> > EXPR_SET_ELEM provides the timeout, expiration, comment and list of
> > statements, this is a shim expression.
> > 
> > Currently, expr_set(x)->expressions can have either:
> > 
> > - EXPR_SET_ELEM
> > 
> >         EXPR_SET_ELEM -> EXPR_VALUE
> > 
> > - EXPR_MAPPING, which contains EXPR_SET_ELEM in the lhs.
> > 
> >                       EXPR_SET_ELEM -> EXPR_VALUE
> >                      /
> > 	EXPR_MAPPING |
> >                      \
> >                       EXPR_VALUE
> > 
> > This patch normalizes the expression for mappings:
> > 
> >                                        EXPR_SET_ELEM -> EXPR_VALUE
> >                                       /
> > 	EXPR_SET_ELEM -> EXPR_MAPPING |
> >                                       \
> >                                        EXPR_VALUE
> > 
> > The previous representation makes it natural for expr_print() to print the
> > timeout, expiration, statements and comments.
> > 
> > 	1.1.1.1 counter packets 1 bytes 564 : 0x00000001,
> > 
> > This patch adds an exception for expr_mapping_print() to stick to the
> > existing representation.
> > 
> > The JSON representation provides this set element information too in the
> > lhs, which is does not really belong there because it is exposing
> > transparently the syntax tree for set elements. A workaround to retain
> > compatibility is included in this patch.
> > 
> > The end goal is to replace EXPR_SET_ELEM by a smaller shim object, to
> > further reduce memory consumption in set elements in userspace.
> > 
> > Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> 
> Git bisect identified this commit as the culprit of a regression I
> noticed: Restoring the following ruleset exposes it:
> 
> | table inet t {
> | 	map m6 {
> | 		typeof numgen inc mod 2000 : ct zone
> | 		elements = { 1 : 1 }
> | 	}
> | }
> 
> When listing, the element shows as '16777216 : 1', whereas:
> 
> | % bc <<< "obase = 16; 16777216"
> | 1000000
> 
> The key seems to be in wrong byte order. It is not just a display issue:
> nft_zones_many.sh kselftest is failing due to it which performs lookups
> in such a set.

Yes, wrong byteorder. TYPE_INTEGER (integer_type) uses
BYTEORDER_INVALID in this case, which is handled as
BYTEORDER_BIG_ENDIAN for historical reasons.

> Can you quickly point at where we lost some byteorder conversion (or got
> an extra one?) by your patch? I guess it missed to adjust a check. I'll
> start digging through the code meanwhile, but tracing expression
> manipulation in eval phase is tedious. :(

Patch:
https://lore.kernel.org/netfilter-devel/20261124235306.1777-1-pablo@netfilter.org/

This rework uncovered this underlying bug.

BTW, nft --debug=netlink does not help to find endianness bugs anymore.

nft --debug=netlink -f /tmp/o 
family 1 m6 t 8
family 1 m6 t 0
        element 00000001 : 0001

This looks right...

... but --debug=mnl uncovers the bug:

|00032|N-|00003|        |len |flags| type|
|00028|N-|00001|        |len |flags| type|
|00012|N-|00001|        |len |flags| type|
|00008|--|00001|        |len |flags| type|
| 00 00 00 01  |        |      data      | <--- 01 00 00 00 !
|00012|N-|00002|        |len |flags| type|
|00006|--|00001|        |len |flags| type|
| 01 00 00 00  |        |      data      |


  reply	other threads:[~2026-11-25  0:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 15:36 [PATCH nft 0/7] prepare for EXPR_SET_ELEM removal Pablo Neira Ayuso
2025-09-05 15:36 ` [PATCH nft 1/7] src: normalize set element with EXPR_MAPPING Pablo Neira Ayuso
2025-09-07 14:10   ` Florian Westphal
2025-09-08  7:59     ` Pablo Neira Ayuso
2026-11-24 18:05   ` Phil Sutter
2026-11-25  0:18     ` Pablo Neira Ayuso [this message]
2026-11-25 10:49       ` Phil Sutter
2025-09-05 15:36 ` [PATCH nft 2/7] src: allocate EXPR_SET_ELEM for EXPR_SET in embedded set declaration in sets Pablo Neira Ayuso
2025-09-05 15:36 ` [PATCH nft 3/7] src: assert on EXPR_SET only contains EXPR_SET_ELEM in the expressions list Pablo Neira Ayuso
2025-09-05 15:36 ` [PATCH nft 4/7] evaluate: simplify sets as set elems evaluation Pablo Neira Ayuso
2025-09-05 15:36 ` [PATCH nft 5/7] evaluate: clean up expr_evaluate_set() Pablo Neira Ayuso
2025-09-05 15:36 ` [PATCH nft 6/7] segtree: rename set_elem_add() to set_elem_expr_add() Pablo Neira Ayuso
2025-09-05 15:36 ` [PATCH nft 7/7] src: move flags from EXPR_SET_ELEM to key 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=awYpSv50FCy3yFhV@chamomile \
    --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 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.