Skip to content

Propagate ICMP echo reply TTL when available#1658

Open
kurochan wants to merge 1 commit into
cloudflare:masterfrom
kurochan:supprt-icmp-ttl
Open

Propagate ICMP echo reply TTL when available#1658
kurochan wants to merge 1 commit into
cloudflare:masterfrom
kurochan:supprt-icmp-ttl

Conversation

@kurochan
Copy link
Copy Markdown

@kurochan kurochan commented Jun 4, 2026

Adds TTL/HopLimit propagation for ICMP Echo Reply packets returned from the origin.

cloudflared already behaves like one hop on the request path by decrementing the TTL/HopLimit before forwarding ICMP packets to the origin. This change applies the same behavior on the reply path when the origin reply TTL/HopLimit is available: cloudflared decrements it by 1 before returning the packet to the eyeball.

Replies whose received TTL/HopLimit is 1 or lower are dropped instead of returning a packet with TTL=0. When the reply TTL/HopLimit is unavailable, cloudflared keeps the existing default TTL fallback.

Fixes #1657

Supported paths

Linux now reads IPv4 TTL and IPv6 HopLimit from packet control messages, so both IPv4 and IPv6 Echo Replies can preserve the origin reply hop limit.

Windows IPv4 uses the TTL from the parsed IcmpSendEcho reply.

Partial and fallback behavior

Darwin keeps the existing default TTL fallback on the normal socket read path, where the reply is parsed as an ICMP message without IP header metadata. When Darwin returns a full IP packet and cloudflared can decode the IP header, the reply TTL from that header is preserved and decremented.

Windows IPv6 keeps the existing default TTL behavior because the current parsed Icmp6SendEcho2 reply path does not expose HopLimit.

Any other path where cloudflared cannot obtain the received TTL/HopLimit also keeps the default TTL fallback.

Respect TTL/HopLimit from origin ICMP echo replies when returning packets
to the eyeball. Treat cloudflared as one hop by decrementing the received
TTL/HopLimit and drop replies that would expire instead of emitting TTL=0.

Keep the default TTL fallback when the reply TTL/HopLimit is unavailable.
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.

ICMP echo replies returned from origin do not preserve TTL/HopLimit

1 participant