Repository navigation
Fix ICMP echo replies for alias resources to come from the pinged address - #483
Merged
Merged
Conversation
… source instead of the rewrite target.
rskallies
requested review from
miloschwartz and
oschwartz10612
as code owners
November 12, 2026 15:57
oschwartz10612
approved these changes
Nov 12, 2026
Member
|
Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Community Contribution License Agreement
By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.
AI Disclosure
The root cause analysis, the code change and the tests were written with Claude Code (Anthropic), working from a bug I hit in production. I reviewed the diff and run the patched build on two of my sites, where it fixes the problem.
Description
When a client pings a private resource through its alias address, Newt answers from the rewrite target instead of the alias.
Example: resource alias
100.96.128.5, destination192.168.1.50.pingtolerates this, stricter tools do not.check_icmpfrom monitoring-plugins now validates the source address of echo replies (monitoring-plugins/monitoring-plugins#2366, shipped in Checkmk since 2.5.0p16, werk 19254). It discards these replies and reports 100% packet loss, so every host monitored through an alias goes DOWN:TCP and UDP are not affected.
Cause
For a non-loopback rewrite target,
HandleIncomingPacketrewrites the packet destination before the packet reaches the proxy stack. The ICMP handler therefore only sees the post-DNAT address and uses it as the source of the echo reply it builds. TCP and UDP replies get their source restored by the reverse NAT inReadOutgoingPacket, but injected ICMP replies are returned before that code runs.Fix
HandleIncomingPacketno longer rewrites the destination of ICMP packets. The ICMP handler already resolves the real target throughdestRewriteTable(this is how loopback rewrite targets work today), so it now sees the original destination in every case, pings the rewrite target and replies from the address the client pinged.Rules without a rewrite and loopback rewrite targets behave as before.
Tests
Two tests added to
netstack2/icmp_dnat_test.go:TestICMPHandleIncomingPacket_DNATHandlerSeesOriginalDestination: the handler sees the alias and resolves the target through the rewrite table.TestICMPEchoReply_DNATSourceIsOriginalDestination: sends an echo request through a DNAT rule whose target is a local non-loopback address and checks the source of the reply. It skips when the environment cannot ping.Both fail without the change (
echo reply source = <target>, want the original destination <alias>).How to test?
ping <alias>.pingprintsDIFFERENT ADDRESS!.check_icmp -H <alias>from monitoring-pluginsmaster(or Checkmk 2.5.0p16 or newer) reports 100% loss before and OK after.go test ./netstack2/ -run ICMP -v