feat(net/socket): implement net reuse port - #2173
Draft
mistcoversmyeyes wants to merge 10 commits into
Draft
mistcoversmyeyes wants to merge 10 commits into
mistcoversmyeyes wants to merge 10 commits into
Conversation
mistcoversmyeyes
force-pushed
the
feat/net-reuseport-1848
branch
from
August 28, 2026 10:25
636beff to
04fb5ac
Compare
Replace the single-owner tcp_port_table (HashMap<u16, RawPid>) with multi-binding records mirroring the UDP side. A new binding is accepted when every conflicting binding shares SO_REUSEPORT or SO_REUSEADDR with the requester. Each record is identified by (iface_nic_id, smoltcp handle), so unbinding is exact without threading an extra id through the socket state. The generic bind_port/unbind_port/bind_ephemeral_port helpers are superseded by per-protocol variants.
Store the flag in TcpSocketOptions and wire it into setsockopt/getsockopt, mirroring the existing SO_REUSEADDR handling. The value is snapshotted at bind() time, matching Linux semantics where SO_REUSEPORT must be set before bind() to participate in port sharing.
Pass SO_REUSEPORT/SO_REUSEADDR from TcpSocket options into Init::bind and Init::listen, routing port registration through bind_tcp_port and bind_tcp_ephemeral_port. Every listening smoltcp socket that belongs to a reuseport listener - the primary socket, per-interface and backlog sockets, and the replacement socket created on accept - is marked with set_reuseport so the smoltcp dispatcher can distribute SYNs across the group. All unbind call sites now release by (iface_nic_id, handle).
mistcoversmyeyes
force-pushed
the
feat/net-reuseport-1848
branch
from
September 12, 2026 09:19
04fb5ac to
7edf3e4
Compare
Track stable TCP binding identities, owner credentials and live socket options in the network namespace. Refresh logical listener selection before ingress and preserve binding ownership across connect, accept and shutdown transitions. Replace port-wide backlog bookkeeping with per-listener slots and atomic accept handoff. Pin smoltcp with the matching logical listener dispatch API.
Rebuild readiness from completed accept slots and refresh it before listen returns, so prior HUP, writable and error events cannot leak into the listener state.
Convert IPv4 transport endpoints to IPv4-mapped IPv6 addresses at the AF_INET6 socket ABI boundary for local address, peer address and accept results.
Add a host harness for the actual TCP port manager and guest regressions for reuseport admission, distribution, address families, readiness and listener lifecycle.
Record the logical listener design, implementation plan, pre- and post-rebase validation, and paired atomic commits with their delivery boundaries.
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.
Related to