From: "Kerin Millar" <kfm@plushkava.net>
To: Wolfgang <netfilter-user@wkraft.org>, netfilter@vger.kernel.org
Subject: Re: Problems understanding nftables part 2
Date: Wed, 29 May 2024 23:31:06 +0100 [thread overview]
Message-ID: <4ac23ef0-13df-4423-b1d5-aa9d5eb5423d@app.fastmail.com> (raw)
In-Reply-To: <14110673198.20240529174630@WKraft.org>
On Wed, 29 May 2024, at 4:46 PM, Wolfgang wrote:
> Hello all,
>
> I have asked already some questions about nftables. While diving
> deeper into it, there
> are arising more questions.
>
>
> In my last test I have hooked rules into the 5 inet hook filter
> destinations
> ( prerouting, input, output,postrouting, forward), to watch how packets
> are flowing to
> my rules. Now I extended that, to see packets also flowing through nat
> destinations,
> but I have seen no packets.
>
> 1) It looks like, that it needs at least one configured nat-rule,
> which gets triggered
> to see packets flowing through the kernel. It looks like, that
> without such an initial
> trigger, trace is either
> a) not showing packets
> b) packet flow through nat is enabled only, after a first nat rule
> matched
> When I have a matching rule like in example 1, I see packets not
> only in prerouting,
> but also in input, output and postrouting, even when the chain
> contains no nat
> specific rule. But: For tcp this seems to be valid only for
> packets with SYN-Flag set,
> others are not showing up.
> c) As soon, as I had such a trigger-packet I see however all
> udp-traffic from the system,
> I have not seen, before the tcp rule triggered.
> So I have the question, if there are other options to get trace
> through nat-hooks enabled
> without having an initial trigger?
> Unfortunately the "dnat" option, does not allow to add a "meta
> nftrace set 1" behind this
> specific line, so i must trace in a more general way.
I wouldn't consider the nat hook to be an especially useful context in which to enable tracing, partly owing to its semantics.
https://wiki.nftables.org/wiki-nftables/index.php/Performing_Network_Address_Translation_(NAT)
Instead, I would recommend using the following hook for tracing packets that arrive.
type filter hook prerouting priority raw; policy accept;
And the following hook for tracing packets that are generated by your host.
type filter hook output priority raw; policy accept;
Going about it in this way should afford you the greatest degree of insight, as regards the traversal of any given packet through your ruleset.
> 2) Prerouting, postrouting and route allow for for symbolic priorities,
> that seems to be broken
> for
> a) input and
> b) output
> where I need to know the corresponding value. What is the reason
> behind this inconsistent
> behaviour?
Unlike iptables, the design of nftables is such that all Netfilter hooks must be explicitly defined by the ruleset. Consequently, it exposes some of the rougher edges of Netfilter to the user. In particular, not all hook type and priority combinations necessarily make sense in practice. This is compounded by the matter of the nft(8) man page having tended towards under-documenting such nuances, though it has gotten a little better as of the most recent release.
During the time in which I was learning nftables, I found it useful to consider iptables as a point of reference. For instance, iptables has a built-in raw table and a built-in PREROUTING chain. One may use iptables-nft to infer how its hook is set up, in a manner whereby it is rendered explicit.
# nft flush ruleset
# iptables-nft -t raw -A PREROUTING
# nft list ruleset
table ip raw {
chain PREROUTING {
type filter hook prerouting priority raw; policy accept;
counter
}
}
The wording of the TABLES section of the iptables(8) man page can thus also be useful as a point of reference. Such a chain is suitable for acting on packets that arrive before any routing decision is made, and before the conntrack table is consulted i.e. even before a nat hook is potentially attended to. These characteristics render it particularly useful for tracing.
--
Kerin Millar
next prev parent reply other threads:[~2024-05-29 22:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-29 15:46 Problems understanding nftables part 2 Wolfgang
2024-05-29 22:31 ` Kerin Millar [this message]
[not found] ` <305618533.20240530185617@WKraft.org>
2024-05-31 1:46 ` Kerin Millar
2024-05-31 15:11 ` Wolfgang
2024-05-31 15:19 ` Kevin P. Fleming
2024-05-31 15:34 ` Wolfgang
2024-05-31 16:26 ` Kerin Millar
2024-05-31 16:06 ` Kerin Millar
2024-05-31 19:31 ` Wolfgang
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=4ac23ef0-13df-4423-b1d5-aa9d5eb5423d@app.fastmail.com \
--to=kfm@plushkava.net \
--cc=netfilter-user@wkraft.org \
--cc=netfilter@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox