fix(gateway): truncate payload of ICMP errors - #9059
Merged
Conversation
thomaseizinger
force-pushed
the
fix/truncate-icmp-error
branch
from
May 9, 2025 01:11
d9e2067 to
dabd29b
Compare
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Sentry Issue: GATEWAY-C9 |
Contributor
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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. |
jamilbk
approved these changes
May 9, 2025
|
Sentry Issue: GATEWAY-C8 |
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.
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:
For ICMPv6, the RFC says: