Skip to content

Commit aa60c0b

Browse files
committed
netfilter: nat: restore default DNAT behavior
JIRA: https://issues.redhat.com/browse/RHEL-115630 Upstream Status: commit 0f1ae28 commit 0f1ae28 Author: Kyle Swenson <kyle.swenson@est.tech> Date: Thu Feb 8 23:56:31 2024 +0000 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: 6ed5943 ("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> Signed-off-by: Florian Westphal <fwestpha@redhat.com>
1 parent 6d87b50 commit aa60c0b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/netfilter/nf_nat_core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,11 @@ static void nf_nat_l4proto_unique_tuple(struct nf_conntrack_tuple *tuple,
544544
find_free_id:
545545
if (range->flags & NF_NAT_RANGE_PROTO_OFFSET)
546546
off = (ntohs(*keyptr) - ntohs(range->base_proto.all));
547-
else
547+
else if ((range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL) ||
548+
maniptype != NF_NAT_MANIP_DST)
548549
off = prandom_u32();
550+
else
551+
off = 0;
549552

550553
attempts = range_size;
551554
if (attempts > NF_NAT_MAX_ATTEMPTS)

0 commit comments

Comments
 (0)