Skip to content

fix(netlink): request unique port identifiers - #910

Open
stephenlclarke wants to merge 1 commit into
apple:mainfrom
stephenlclarke:upstream/netlink-port-identifiers
Open

fix(netlink): request unique port identifiers#910
stephenlclarke wants to merge 1 commit into
apple:mainfrom
stephenlclarke:upstream/netlink-port-identifiers

Conversation

@stephenlclarke

Copy link
Copy Markdown
Contributor

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 with getsockname, and keep exposing it through the existing pid property.

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 --check and focused Swift formatting of the added code pass.

Compatibility

The public property name remains pid for source compatibility, but its documentation now reflects Netlink semantics: it is a socket port identifier, not necessarily the process ID.

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.

1 participant