Fix pktinfo send cmsg_level/cmsg_type (IPPROTO_IP / IP_PKTINFO) - #238
Merged
swhitty merged 1 commit intoAug 13, 2026
Conversation
Send-side IP_PKTINFO/IPV6_PKTINFO control messages used SOL_SOCKET as the cmsg_level and the protocol number as the cmsg_type, inconsistent with the library's own receive path. Set IPPROTO_IP/IP_PKTINFO and IPPROTO_IPV6/IPV6_PKTINFO as required by ip(7) and RFC 3542 §6. Add deterministic tests asserting the exact level/type pairs against platform constants (verified to fail against the previous values), plus loopback round-trip smoke tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ianegordon
marked this pull request as ready for review
August 11, 2026 00:02
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #238 +/- ##
==========================================
+ Coverage 93.00% 93.72% +0.71%
==========================================
Files 72 72
Lines 3748 3777 +29
==========================================
+ Hits 3486 3540 +54
+ Misses 262 237 -25 ☔ View full report in Codecov by Harness. |
swhitty
approved these changes
Aug 13, 2026
Owner
|
nice, thank you |
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.
Problem
The send-side
IP_PKTINFO/IPV6_PKTINFOcontrol messages built bySocket.withPacketInfoControlset:Per cmsg(3),
cmsg_levelis the originating protocol andcmsg_typethe protocol-specific type. A pktinfo ancillary message requiresIPPROTO_IP/IP_PKTINFO(RFC 3542 §6 for IPv6: "the socket option and cmsghdr level will be IPPROTO_IPV6, the type will be IPV6_PKTINFO"). The library's own receive path (getPacketInfoControl) already matches on exactly those pairs — so send and receive were mutually inconsistent, andsend(message:to:interfaceIndex:from:)could not apply source-address/interface selection.Change
Set
cmsg_level = IPPROTO_IP/cmsg_type = IP_PKTINFO(IPv6:IPPROTO_IPV6/IPV6_PKTINFO) on the send side, matching the receive path. Depends on theipv6_pktinfoconstant fix from #233 (already on main): with the correct cmsg level the kernel interpretscmsg_typefor the first time, so both fixes are needed together for IPv6 sends to succeed on Darwin.Tests
Full suite passes (464 tests).
🤖 Generated with Claude Code