]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
netfilter: nat: restore default DNAT behavior
authorKyle Swenson <kyle.swenson@est.tech>
Thu, 8 Feb 2024 23:56:31 +0000 (23:56 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 14 Feb 2024 23:20:00 +0000 (00:20 +0100)
commit0f1ae2821fa4b13ab0f5ad7ff89fa57efcb04fe0
tree0f836a472f63ddd356d8bec467e2ad6f33ac9925
parentf6374a82fc85bf911d033e2fa791372ce3356270
netfilter: nat: restore default DNAT behavior

When a DNAT rule is configured via iptables with different port ranges,

iptables -t nat -A PREROUTING -p tcp -d 10.0.0.2 -m tcp --dport 32000:32010
-j DNAT --to-destination 192.168.0.10:21000-21010

we seem to be DNATing to some random port on the LAN side. While this is
expected if --random is passed to the iptables command, it is not
expected without passing --random.  The expected behavior (and the
observed behavior prior to the commit in the "Fixes" tag) is the traffic
will be DNAT'd to 192.168.0.10:21000 unless there is a tuple collision
with that destination.  In that case, we expect the traffic to be
instead DNAT'd to 192.168.0.10:21001, so on so forth until the end of
the range.

This patch intends to restore the behavior observed prior to the "Fixes"
tag.

Fixes: 6ed5943f8735 ("netfilter: nat: remove l4 protocol port rovers")
Signed-off-by: Kyle Swenson <kyle.swenson@est.tech>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_nat_core.c