All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Fabian Bläse" <fabian@blaese.de>
To: Florian Westphal <fw@strlen.de>
Cc: netdev@vger.kernel.org, netfilter-devel@vger.kernel.org,
	"Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: Re: [PATCH v2] icmp: fix icmp_ndo_send address translation for reply direction
Date: Wed, 27 Aug 2025 19:12:19 +0200	[thread overview]
Message-ID: <e1bf6193-d075-4593-81ef-99e8b93a4f74@blaese.de> (raw)
In-Reply-To: <aK7KYr5D7bD3OcHb@strlen.de>

On 27.08.25 11:05, Florian Westphal wrote:
> If the connection isn't subject to snat, why to we need to mangle the
> source address in the first place?
It is not limited to SNAT/MASQUERADE.
DNAT also affects which source address should be used, depending on the packet
direction.

With DNAT, the *destination* of the original direction is changed.
In the reply direction, this becomes the *source* address.

So reply packets of a DNAT connection are effectively subject to source address
translation. If icmp_ndo_send doesn’t account for this, rate limiting breaks,
which is exactly the problem this function was meant to solve.

> Don't understand this either.  Why these checks?
> AFAICS you can keep the original check in place, and then:
> 
> replace this
>>  	orig_ip = ip_hdr(skb_in)->saddr;
>> -	ip_hdr(skb_in)->saddr = ct->tuplehash[0].tuple.src.u3.ip;
> 
> ... with ...
You are right: the code can be simplified. I'm not sure show this slipped through.
I will send an updated patch with this change — thanks for the suggestion.
However, the old check (IPS_SRC_NAT only) cannot be kept, because:
- Reply packets of a DNAT connection also need handling.
- Reply packets of a pure SNAT connection don’t need it, but replacing the
   address is a no-op in that case (tuple == skb address).

To avoid unnecessary translations, I suggested the direction-specific checks.
Another option is to simplify them to:

     if (!(ct->status & IPS_NAT_MASK)) { … }

This ensures we only ever touch connections with NAT, while keeping the code
straightforward.

> Without dnat, the reply tuple saddr == original tuple daddr.
> 
> With dnat, its the dnat targets' address (i.e., the real destination
> the client is talking to).
Yes, exactly.

> If you are worried about "dnat to", then please update the commit
> message, which only mentions masquerade/snat.
Correct — the change not only fixes SNAT-in-reply handling, but also adds
proper handling for DNAT in the reply direction, which was missing entirely.
I will update the commit message to reflect this.

Best regards,
Fabian

  reply	other threads:[~2025-08-27 17:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-25 20:17 [PATCH] icmp: fix icmp_ndo_send address translation for reply direction Fabian Bläse
2025-08-25 20:38 ` [PATCH v2] " Fabian Bläse
2025-08-27  9:05   ` Florian Westphal
2025-08-27 17:12     ` Fabian Bläse [this message]
2025-08-27 17:25       ` Florian Westphal
2025-08-28  9:14   ` [PATCH v3] " Fabian Bläse
2025-08-28 12:00     ` Pablo Neira Ayuso
2025-08-28 12:15       ` Florian Westphal
2025-08-28 12:33         ` Pablo Neira Ayuso
2025-08-28 12:48           ` Florian Westphal
2025-08-28 12:48     ` Florian Westphal
2025-09-01 20:20     ` patchwork-bot+netdevbpf

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=e1bf6193-d075-4593-81ef-99e8b93a4f74@blaese.de \
    --to=fabian@blaese.de \
    --cc=Jason@zx2c4.com \
    --cc=fw@strlen.de \
    --cc=netdev@vger.kernel.org \
    --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.