Skip to content

Conversation

picoHz
Copy link
Owner

@picoHz picoHz commented Mar 31, 2025

Implement the IPV6_V6ONLY flag to ensure that TCP and UDP sockets bind exclusively to IPv6 addresses, preventing dual-stack binding.

@picoHz picoHz added the bug Something isn't working label Mar 31, 2025
@picoHz picoHz requested a review from Copilot March 31, 2025 09:11
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the IPV6_V6ONLY flag for socket creation to avoid dualstack binding for both TCP and UDP servers. Key changes include:

  • Introducing the create_udp_socket function in udp.rs to enforce IPV6_V6ONLY for UDP sockets.
  • Introducing the create_tcp_listener function in tcp.rs with IPV6_V6ONLY support for TCP sockets.
  • Adding the socket2 dependency in Cargo.toml to support advanced socket option configuration.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
taxy/src/server/udp.rs Replaces direct binding with a custom function that sets IPV6_V6ONLY.
taxy/src/server/tcp.rs Uses a custom listener creation function with IPV6_V6ONLY enforcement; note the minimal listen backlog.
taxy/Cargo.toml Adds the socket2 dependency required for the new socket configuration.

socket.set_reuse_address(true)?;
socket.set_nonblocking(true)?;
socket.bind(&addr.into())?;
socket.listen(1)?;
Copy link
Preview

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

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

The listen backlog of 1 may be too low for production use; consider increasing the backlog value or making it configurable to better handle incoming connections.

Suggested change
socket.listen(1)?;
socket.listen(128)?;

Copilot uses AI. Check for mistakes.

@picoHz picoHz force-pushed the socket-ipv6-only branch from c4aaf7c to 1aaa426 Compare March 31, 2025 09:12
@picoHz picoHz requested a review from Copilot March 31, 2025 09:12
@picoHz picoHz linked an issue Mar 31, 2025 that may be closed by this pull request
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements exclusive IPv6 binding by setting the IPV6_V6ONLY flag for both TCP and UDP sockets to prevent dualstack binding. The changes include introducing helper functions to create sockets, removing unused instrumentation imports, and updating the Cargo.toml to add the socket2 dependency.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
taxy/src/server/udp.rs Refactored UDP socket creation to use socket2 and apply IPV6_V6ONLY.
taxy/src/server/tcp.rs Refactored TCP listener creation similarly to include IPV6_V6ONLY flag.
taxy/Cargo.toml Updated dependencies by adding socket2 for low-level socket configuration.
Comments suppressed due to low confidence (1)

taxy/src/server/tcp.rs:164

  • [nitpick] Consider replacing the magic number '128' used for the backlog in the TCP listener with a named constant to improve code readability and maintainability.
socket.listen(128)?;

@picoHz picoHz force-pushed the socket-ipv6-only branch from 1aaa426 to e2232d3 Compare March 31, 2025 09:14
@picoHz picoHz changed the title Use IPV6_V6ONLY flag to avoid dualstack binding; Fix #114 Use IPV6_V6ONLY flag to avoid dualstack binding Mar 31, 2025
@picoHz picoHz changed the base branch from fix-missing-interface-api to main March 31, 2025 09:14
@picoHz picoHz force-pushed the socket-ipv6-only branch from e2232d3 to c88a5b2 Compare March 31, 2025 09:16
@picoHz picoHz force-pushed the socket-ipv6-only branch from c88a5b2 to a5645c2 Compare March 31, 2025 09:16
@picoHz picoHz merged commit e1fc92c into main Mar 31, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IPv6 Interface Selection in Web Interface and Dual-Stack Binding Issue
1 participant