From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>, Florian Westphal <fw@strlen.de>,
netfilter-devel@vger.kernel.org
Subject: Re: [libnftnl RFC] data_reg: Improve data reg value printing
Date: Wed, 17 Sep 2025 00:32:34 +0200 [thread overview]
Message-ID: <aMnlgsXe8ufMGoAF@calendula> (raw)
In-Reply-To: <aMiQSi-ASbcAE5CL@orbyte.nwl.cc>
Hi Phil,
On Tue, Sep 16, 2025 at 12:16:42AM +0200, Phil Sutter wrote:
> Hi Pablo,
>
> On Mon, Sep 15, 2025 at 11:19:27PM +0200, Pablo Neira Ayuso wrote:
> > On Thu, Sep 11, 2025 at 04:11:45PM +0200, Phil Sutter wrote:
> > > The old code printing each field with data as u32 value is problematic
> > > in two ways:
> > >
> > > A) Field values are printed in host byte order which may not be correct
> > > and output for identical data will divert between machines of
> > > different Endianness.
> > >
> > > B) The actual data length is not clearly readable from given output.
> > >
> > > This patch won't entirely fix for (A) given that data may be in host
> > > byte order but it solves for the common case of matching against packet
> > > data.
> > >
> > > Fixing for (B) is crucial to see what's happening beneath the bonnet.
> > > The new output will show exactly what is used e.g. by a cmp expression.
> >
> > Could you fix this from libnftables? ie. add print functions that have
> > access to the byteorder, so print can do accordingly.
>
> You mean replacing nftnl_expr_fprintf() and all per-expr callbacks
> entirely? I guess this exposes lots of libnftnl internals to
> libnftables.
>
> IIRC, the last approach from 2020 was to communicate LHS byteorder to
> RHS in libnftnl internally and in addition to that annotate sets with
> element byteorder info (which is not entirely trivial due to
> concatenations of data with varying byteorder.
>
> I don't get the code in my old branches anymore, though. Maybe if I read
> up on our past mails. Or maybe we just retry from scratch with a fresh
> mind. :)
Maybe this approach?
For immediates, a new libnftnl function could help us deal with this:
- nftnl_expr_set(nle, NFTNL_EXPR_CMP_DATA, nld2.value, nld2.len);
+ nftnl_expr_set_imm(nle, NFTNL_EXPR_CMP_DATA, nld2.value, nld2.len, nld2.byteorder);
Then, for set elements, add a new field here:
struct nft_data_linearize {
uint32_t len;
uint32_t value[NFT_REG32_COUNT];
+ uint32_t byteorder[NFT_REG32_COUNT];
where byteorder stores a bitmask that specifies byteorder, 0 can be
network endian and 1 host endian, the length of the bitmask length
tells us the size of this field.
Then, add nftnl_set_elem_set_imm() that takes nld.byteorder.
From libnftnl, use this bitmask from _snprintf to swap bits
accordingly.
union nftnl_data_reg would need to be modified to store this
byteorder[] array including the bitmask. This will not increase memory
consumption because only one intermediate libnftnl object is used to
generate the netlink bytecode blob at a time.
This should not be too hard to make it work for userspace -> kernel.
Would this be good enough to make tests/py happy?
next prev parent reply other threads:[~2025-09-16 22:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-11 14:11 [libnftnl RFC] data_reg: Improve data reg value printing Phil Sutter
2025-09-11 14:33 ` Florian Westphal
2025-09-11 15:57 ` Phil Sutter
2025-09-15 21:19 ` Pablo Neira Ayuso
2025-09-15 22:16 ` Phil Sutter
2025-09-16 22:32 ` Pablo Neira Ayuso [this message]
2025-09-16 12:08 ` Florian Westphal
2025-09-30 17:14 ` Phil Sutter
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=aMnlgsXe8ufMGoAF@calendula \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--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.