Repository navigation
Conversation
withPacketInfoControl built the in_pktinfo or in6_pktinfo in the element storage of a ManagedBuffer, which starts out uninitialised, and: - For IPv4 it wrote the local address to ipi_addr and never set ipi_spec_dst, the field ip(7) says sendmsg(2) takes the source address from. So the source was whatever was in memory, and sendmsg could fail with ENETUNREACH, as sendMessage_WithPacketInfo_RoundTripsDatagram does on some Linux builds. - It read the address by reinterpreting the bytes of the any SocketAddress existential. Those bytes are the address only when the value is held inline: a sockaddr_in6 or sockaddr_storage is boxed, so what was read was the box. Zero the structure, read the address from makeStorage(), and put an IPv4 source in ipi_spec_dst. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Fq7ie1LzJERrh9uRuZZWE
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #243 +/- ##
==========================================
+ Coverage 93.72% 93.73% +0.01%
==========================================
Files 72 72
Lines 3777 3785 +8
==========================================
+ Hits 3540 3548 +8
Misses 237 237 ☔ View full report in Codecov by Harness. |
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.
Summary
Socket.withPacketInfoControlsends IPv4 datagrams with an uninitialised source address. On Linux,sendMessage_WithPacketInfo_RoundTripsDatagram()then fails withSendMsg errno 101 (Network is unreachable). Whether it fails depends on what happens to be in memory, so it passes on some builds and fails on others:Cause
The
in_pktinfoandin6_pktinfoare built in the element storage of aManagedBuffer, which starts out uninitialised.ipi_addr, andipi_spec_dstis never set. ip(7): "If IP_PKTINFO is passed to sendmsg(2) and ipi_spec_dst is not zero, then it is used as the local source address for the routing table lookup".ipi_addris the destination of a received packet. So the source used is whatever was in memory.any SocketAddressexistential as asockaddr_inorsockaddr_in6. Those bytes are the address only when the value is stored inline in the existential. Asockaddr_in6(28 bytes) or asockaddr_storageis boxed, so what gets read is the box. This affects every IPv6 send with a local address.Changes
in_pktinfoorin6_pktinfo.makeStorage(), checking its family.ipi_spec_dst. For IPv6,ipi6_addrwas already the right field (RFC 3542 §6.1).Tests
Two new unit tests read back the control message that's built, with the address passed both as a plain value and as a boxed
sockaddr_storage:withPacketInfoControl_IP4_SetsSourceAddressInSpecDst: checksipi_spec_dstis the source address,ipi_addris 0, andipi_ifindexis set. Without this change it fails:ipi_spec_dstis 0, andipi_addris 127.0.0.1 for the plain value but garbage for the boxed one.withPacketInfoControl_IP6_SetsSourceAddress: checksipi6_addris the source address. Without this change it fails:ipi6_addrholds the existential's box pointer rather than::1.Test plan:
sendMessage_WithPacketInfo…round trips pass in 10 of 10 runs. On the same machine and toolchain,sendMessage_WithPacketInfo_RoundTripsDatagramfailed 10 of 10 without this change.🤖 Generated with Claude Code
https://claude.ai/code/session_012Fq7ie1LzJERrh9uRuZZWE