From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf-next 2/2] netfilter: nf_tables: add packets conntrack state to debug trace info
Date: Wed, 21 May 2025 11:35:13 +0200 [thread overview]
Message-ID: <aC2eUd6OOxn9ramP@calendula> (raw)
In-Reply-To: <20250508150855.6902-3-fw@strlen.de>
Hi Florian,
On Thu, May 08, 2025 at 05:08:52PM +0200, Florian Westphal wrote:
> Add the minimal relevant info needed for userspace ("nftables monitor
> trace") to provide the conntrack view of the packet:
>
> - state (new, related, established)
> - direction (original, reply)
> - status (e.g., if connection is subject to dnat)
> - id (allows to query ctnetlink for remaining conntrack state info)
>
> Example:
> trace id a62 inet filter PRE_RAW packet: iif "enp0s3" ether [..]
> [..]
> trace id a62 inet filter PRE_MANGLE conntrack: ct direction original ct state new ct id 32
> trace id a62 inet filter PRE_MANGLE packet: [..]
> [..]
> trace id a62 inet filter IN conntrack: ct direction original ct state new ct status dnat-done ct id 32
> [..]
>
> In this case one can see that while NAT is active, the new connection
> isn't subject to a translation.
>
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> include/uapi/linux/netfilter/nf_tables.h | 2 +
> net/netfilter/nf_tables_trace.c | 65 +++++++++++++++++++++++-
> 2 files changed, 66 insertions(+), 1 deletion(-)
[...]
> diff --git a/net/netfilter/nf_tables_trace.c b/net/netfilter/nf_tables_trace.c
> index 580c55268f65..ba8b0a8c00e6 100644
> --- a/net/netfilter/nf_tables_trace.c
> +++ b/net/netfilter/nf_tables_trace.c
[...]
> + if (nla_put_be32(nlskb, NFT_CT_STATE, htonl(state)))
> + goto nla_put_failure;
> +
> + if (ct) {
> + u32 id = ct_hook->get_id(&ct->ct_general);
> + u32 status = READ_ONCE(ct->status);
> + u8 dir = CTINFO2DIR(ctinfo);
> +
> + if (nla_put_u8(nlskb, NFT_CT_DIRECTION, dir))
> + goto nla_put_failure;
> +
> + if (nla_put_be32(nlskb, NFT_CT_ID, (__force __be32)id))
> + goto nla_put_failure;
> +
> + if (status && nla_put_be32(nlskb, NFT_CT_STATUS, htonl(status)))
> + goto nla_put_failure;
NFT_CT_* is enum nft_ct_keys which is not intended to be used as
netlink attribute.
NFT_CT_STATE is 0 which is usually reserved for _UNSPEC in netlink
attribute definitions.
My suggestion is that you define new attributes for this, it is
boilerplate code to be added to uapi.
Thanks.
next prev parent reply other threads:[~2025-05-21 9:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-08 15:08 [PATCH nf-next 0/2] netfilter: nf_tables: include conntrack state in trace messages Florian Westphal
2025-05-08 15:08 ` [PATCH nf-next 1/2] netfilter: conntrack: make nf_conntrack_id callable without a module dependency Florian Westphal
2025-05-08 15:08 ` [PATCH nf-next 2/2] netfilter: nf_tables: add packets conntrack state to debug trace info Florian Westphal
2025-05-21 9:35 ` Pablo Neira Ayuso [this message]
2025-05-21 11:26 ` Florian Westphal
2025-05-21 13:52 ` 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=aC2eUd6OOxn9ramP@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.