Skip to content

fix(gateway): truncate payload of ICMP errors - #9059

Merged
thomaseizinger merged 4 commits into
mainfrom
fix/truncate-icmp-error
May 9, 2025
Merged

fix(gateway): truncate payload of ICMP errors#9059
thomaseizinger merged 4 commits into
mainfrom
fix/truncate-icmp-error

Conversation

@thomaseizinger

Copy link
Copy Markdown
Member

When the Gateway is handed an IP packet for a DNS resource that it cannot route, it sends back an ICMP unreachable error. According to RFC 792 0 (for ICMPv4) and RFC 4443 1 (for ICMPv6), parts of the original packet should be included in the ICMP error payload to allow the sending party to correlate, what could not be sent.

For ICMPv4, the RFC says:

Internet Header + 64 bits of Data Datagram

The internet header plus the first 64 bits of the original
datagram's data.  This data is used by the host to match the
message to the appropriate process.  If a higher level protocol
uses port numbers, they are assumed to be in the first 64 data
bits of the original datagram's data.

For ICMPv6, the RFC says:

As much of invoking packet as possible without the ICMPv6 packet exceeding the minimum IPv6 MTU

@thomaseizinger
thomaseizinger requested review from Copilot and jamilbk May 9, 2025 01:11
@thomaseizinger
thomaseizinger force-pushed the fix/truncate-icmp-error branch from d9e2067 to dabd29b Compare May 9, 2025 01:11
@vercel

vercel Bot commented May 9, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
firezone ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2025 1:15am

@sentry

sentry Bot commented May 9, 2025

Copy link
Copy Markdown

Sentry Issue: GATEWAY-C9

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the truncation of ICMP error payloads by updating how the unreachable ICMP packets are built for both IPv4 and IPv6, in accordance with RFC 792 and RFC 4443. Key changes include:

  • Introducing new functions (icmp_dst_unreachable, icmpv4_network_unreachable, icmpv6_address_unreachable) to correctly truncate and build ICMP error packets.
  • Adding property-based tests to verify the behavior of both IPv4 and IPv6 ICMP unreachable packet generation.
  • Removing deprecated unreachable functions in favor of the new, consolidated implementation.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
rust/ip-packet/src/make.rs Adds new functions for ICMP unreachable error packet construction with proper payload truncation.
rust/connlib/tunnel/src/peer.rs Replaces legacy unreachable logic with calls to the new icmp_dst_unreachable function.
Comments suppressed due to low confidence (1)

rust/ip-packet/src/make.rs:159

  • [nitpick] Consider renaming the parameters 'ipv4_src' and 'ipv6_src' to 'gateway_ipv4' and 'gateway_ipv6' respectively to more clearly indicate that these addresses are the source addresses of the gateway for ICMP errors.
pub fn icmp_dst_unreachable(ipv4_src: Ipv4Addr, ipv6_src: Ipv6Addr, original_packet: &IpPacket) -> Result<IpPacket> {

let header_len = original_packet
.ipv4_header()
.context("Not an IPv4 packet")?
.header_len();

Copilot AI May 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to add an inline comment explaining that 'header_len + 8' represents the IPv4 header plus the first 64 bits of data as specified in RFC 792.

Suggested change
.header_len();
.header_len();
// According to RFC 792, ICMP error messages include the IPv4 header
// and the first 64 bits (8 bytes) of the original packet's data.

Copilot uses AI. Check for mistakes.
@thomaseizinger
thomaseizinger added this pull request to the merge queue May 9, 2025
Merged via the queue into main with commit 33d5c32 May 9, 2025
@thomaseizinger
thomaseizinger deleted the fix/truncate-icmp-error branch May 9, 2025 01:51
@sentry

sentry Bot commented May 9, 2025

Copy link
Copy Markdown

Sentry Issue: GATEWAY-C8

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.

3 participants