feat(net/socket): implement net reuse port - #2173
Draft
mistcoversmyeyes wants to merge 3 commits into
Draft
Conversation
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).
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