From: Florian Westphal <fw@strlen.de>
To: Juan Carlos Lazcano <juan@placidnetworks.com>
Cc: "netfilter@vger.kernel.org" <netfilter@vger.kernel.org>
Subject: Re: Stateless NAT in nftables with maps for performance
Date: Fri, 12 Sep 2025 14:05:30 +0200 [thread overview]
Message-ID: <aMQMg33uIM63vKAC@strlen.de> (raw)
In-Reply-To: <1643443761.529082.1757676483522@email.ionos.com>
Juan Carlos Lazcano <juan@placidnetworks.com> wrote:
> Hi netfilter community!
> I'm trying to orchestrate the generation and maintenance of thousands of dnat & snat rules in a stateless configuration within the prerouting and forward hooks with chain types of filter, and unfortunately am hitting a big performance barrier as a result. Its fine with a few thousand, but once we get into the tens of thousands of rules, things start slowing down linearly, which is why we would like to switch to maps. However, I cannot figure out 1) if maps are supported in filter chains within prerouting/forward hooks and 2) if it supports the syntax for stateless nat?
>
> For example:
>
> table ip mytable {
> map dnat_map {
> type ipv4_addr : ipv4_addr
> }
> chain dnat {
> type filter hook prerouting priority raw; policy accept;
> }
> }
>
> I normally generate stateless dnat's via:
>
> $ nft add rule ip mytable dnat ip daddr 100.101.84.137 counter ip daddr set 10.11.1.32 notrack comment "comment 1"
>
> But, lets say I want to try to replace this rule with a map. If i populate my map with a a key pair like:
>
> $ nft add element ip mytable dnat_map { 100.101.84.137 : 10.11.33.32 }
>
> How can I represent my original rule using a map?
ip daddr set ip daddr map @dnat_map
~~~~~~~~ #######
| \ The key to query the map for
|
\ What you want replaced
This rule is:
[ payload load 4b @ network header + 16 => reg 1 ] # loads the key (second ip daddr).
[ lookup reg 1 set dnat_map dreg 1 0x0 ] # queries map
[ payload write reg 1 => 4b @ network header + 16 csum_type 1 csum_off 10 csum_flags 0x1 ]
# Then places the result of the map at the location (first ip daddr).
next prev parent reply other threads:[~2025-09-12 12:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 11:28 Stateless NAT in nftables with maps for performance Juan Carlos Lazcano
2025-09-12 12:05 ` Florian Westphal [this message]
2025-09-12 12:23 ` Florian Westphal
2025-09-12 12:47 ` Juan Carlos Lazcano
2025-09-12 13:37 ` Florian Westphal
2025-09-15 9:11 ` 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=aMQMg33uIM63vKAC@strlen.de \
--to=fw@strlen.de \
--cc=juan@placidnetworks.com \
--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;
as well as URLs for NNTP newsgroup(s).