Skip to content

feat(net/socket): implement net reuse port - #2173

Draft
mistcoversmyeyes wants to merge 10 commits into
DragonOS-Community:masterfrom
mistcoversmyeyes:feat/net-reuseport-1848
Draft

mistcoversmyeyes wants to merge 10 commits into
DragonOS-Community:masterfrom
mistcoversmyeyes:feat/net-reuseport-1848

Conversation

@mistcoversmyeyes

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added the enhancement New feature or request label Aug 8, 2026
@mistcoversmyeyes
mistcoversmyeyes force-pushed the feat/net-reuseport-1848 branch from 636beff to 04fb5ac Compare August 28, 2026 10:25
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).
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant