Skip to content

feat(net): enhance Linux compatibility for socket operations#1818

Open
fslongjin wants to merge 2 commits intoDragonOS-Community:masterfrom
fslongjin:fix-linux-dual-stack-tcp-listen-backlog
Open

feat(net): enhance Linux compatibility for socket operations#1818
fslongjin wants to merge 2 commits intoDragonOS-Community:masterfrom
fslongjin:fix-linux-dual-stack-tcp-listen-backlog

Conversation

@fslongjin
Copy link
Member

  • Implement dual-stack rule validation for bound IPv6 sockets
  • Add auto-binding for unbound TCP sockets on listen() call
  • Improve backlog handling for INADDR_ANY listeners across interfaces
  • Fix socketpair error code mapping for unsupported families

- Implement dual-stack rule validation for bound IPv6 sockets
- Add auto-binding for unbound TCP sockets on listen() call
- Improve backlog handling for INADDR_ANY listeners across interfaces
- Fix socketpair error code mapping for unsupported families

Signed-off-by: longjin <longjin@DragonOS.org>
@fslongjin
Copy link
Member Author

@codex review

@github-actions github-actions bot added the enhancement New feature or request label Mar 16, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85ee6f0c32

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +265 to +267
let new_listen = socket::inet::BoundInner::bind_on_iface(
new_listen_smoltcp_socket(listen_addr)?,
iface.clone(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep port-owning listener first for INADDR_ANY

This branch inserts non-primary interface listeners into inners before the original bound listener, but Listening::close() still frees the bound TCP port via self.inners[0].iface().port_manager().unbind_port(...), which assumes index 0 owns the reservation. On multi-interface INADDR_ANY listeners, close will unbind the wrong iface and leak the actual port binding on the primary iface, so subsequent bind/listen on the same port can fail with EADDRINUSE.

Useful? React with 👍 / 👎.

let nic_id = b.iface().nic_id();
if !registered_ifaces.contains(&nic_id) {
b.iface().common().register_tcp_listen_port(port, backlog);
b.iface().common().bind_socket(me.clone());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Unbind listener from every iface during teardown

Registering the listening socket on each unique iface here is not matched by symmetric unregistration: close/shutdown paths only call unbind_socket() through a single iface (inner.iface() / inners[0]). For INADDR_ANY listeners spanning multiple interfaces, extra IfaceCommon::bounds entries remain after close, causing leaked socket references and repeated stale notifications on those interfaces.

Useful? React with 👍 / 👎.

- Fix port unbinding to use last inner socket instead of first
- Add socket unbinding to all interface cleanup loops for listening sockets
- Prevent double unbinding for non-listening socket states

Signed-off-by: longjin <longjin@DragonOS.org>
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