Repository navigation
fix(netlink): request unique port identifiers - #910
Open
stephenlclarke wants to merge 1 commit into
Open
stephenlclarke wants to merge 1 commit into
stephenlclarke wants to merge 1 commit into
Conversation
stephenlclarke
force-pushed
the
upstream/netlink-port-identifiers
branch
from
September 28, 2026 08:03
2ee4d23 to
ed533ab
Compare
| guard let ptr = buffer.bind(as: sockaddr.self, size: buffer.count) else { | ||
| throw NetlinkSocketError.bindFailure(rc: 0) | ||
| } | ||
| guard osBind(socketFD, ptr, UInt32(buffer.count)) >= 0 else { |
Contributor
There was a problem hiding this comment.
I think we should use socklen_t throughout if you can.
Contributor
Author
There was a problem hiding this comment.
Updated in d35cb51acce19b7df5ea5d0cf75e88e88a303331 and rebased onto current upstream. Both the bind buffer length and returned-address length comparison now use socklen_t; only the kernel netlink port identifier remains UInt32. The current ContainerizationNetlink production target cross-compiles successfully for aarch64 Linux/musl with Swift 6.3 and warnings as errors. This is compilation proof; I have not relabelled the earlier VM test failures as passes.
stephenlclarke
force-pushed
the
upstream/netlink-port-identifiers
branch
from
October 19, 2026 07:28
ed533ab to
d35cb51
Compare
This branch has not been deployed
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
Allow multiple Netlink route sockets in one process by requesting kernel-assigned port identifiers.
Binding every socket with
nl_pid = getpid()makes the second concurrent socket collide with the first. Bind with port identifier zero, read the unique assigned identifier back withgetsockname, and keep exposing it through the existingpidproperty.The initialization path also closes the descriptor on every post-
socket()failure and reports a dedicated socket-name error when the assigned address cannot be read or validated.Testing
Added a Linux-only regression that opens eight concurrent route sockets and verifies every assigned port identifier is non-zero and distinct.
The installed macOS cross-compilation SDK is not compatible with the active Apple Swift compiler, so the Linux test is intentionally delegated to this pull request's native Linux CI rather than treated as locally executed evidence.
git diff --checkand focused Swift formatting of the added code pass.Compatibility
The public property name remains
pidfor source compatibility, but its documentation now reflects Netlink semantics: it is a socket port identifier, not necessarily the process ID.