Skip to content

Fix ICMP echo replies for alias resources to come from the pinged address - #483

Merged
oschwartz10612 merged 1 commit into
fosrl:devfrom
rskallies:fix/icmp-alias-reply-source
Nov 12, 2026
Merged

oschwartz10612 merged 1 commit into
fosrl:devfrom
rskallies:fix/icmp-alias-reply-source

Conversation

@rskallies

Copy link
Copy Markdown

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, destination 192.168.1.50.

$ ping -c1 100.96.128.5
64 bytes from 192.168.1.50: icmp_seq=1 ttl=64 time=21.9 ms (DIFFERENT ADDRESS!)

ping tolerates this, stricter tools do not. check_icmp from 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:

$ check_icmp -H 100.96.128.5 -vvv
received 96 bytes from 192.168.1.50
dropping reply with our icmp_id from unexpected address 192.168.1.50
CRITICAL - 100.96.128.5: rta nan, lost 100%

TCP and UDP are not affected.

Cause

For a non-loopback rewrite target, HandleIncomingPacket rewrites 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 in ReadOutgoingPacket, but injected ICMP replies are returned before that code runs.

Fix

HandleIncomingPacket no longer rewrites the destination of ICMP packets. The ICMP handler already resolves the real target through destRewriteTable (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?

  1. Create a private resource with an alias address and a destination on the site's LAN, with ICMP allowed.
  2. From an Olm client, run ping <alias>.
    • Before: replies come from the destination address and ping prints DIFFERENT ADDRESS!.
    • After: replies come from the alias.
  3. Optional: check_icmp -H <alias> from monitoring-plugins master (or Checkmk 2.5.0p16 or newer) reports 100% loss before and OK after.
  4. go test ./netstack2/ -run ICMP -v

@oschwartz10612

Copy link
Copy Markdown
Member

Thanks

@oschwartz10612
oschwartz10612 merged commit 01242ed into fosrl:dev Nov 12, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants