Skip to content

connectd: set IPV6_V6ONLY=1 on IPv6 sockets for consistent dual-stack behaviour#9148

Open
nGoline wants to merge 1 commit into
ElementsProject:masterfrom
nGoline:ipv4-and-ipv6-fix
Open

connectd: set IPV6_V6ONLY=1 on IPv6 sockets for consistent dual-stack behaviour#9148
nGoline wants to merge 1 commit into
ElementsProject:masterfrom
nGoline:ipv4-and-ipv6-fix

Conversation

@nGoline
Copy link
Copy Markdown
Collaborator

@nGoline nGoline commented May 19, 2026

As discussed in #9013, systems with net.ipv6.bindv6only=0 (macOS, Fedora, Arch, vanilla kernels) create dual-stack sockets by default: binding '::' also covers '0.0.0.0', so the subsequent IPv4 wildcard bind fails with EADDRINUSE. Debian/Ubuntu ship bindv6only=1 so both binds succeed here, which is why this was never noticed on typical Linux CI.

On this PR I've gone with option 1 and 2: Explicitly set IPV6_V6ONLY=1 on AF_INET6 sockets before bind so both address families always get independent sockets regardless of the system sysctl. Also free the errstr allocation left behind when the IPv4 bind fails acceptably (IPv6 succeeded), fixing a memleak in connectd on those systems.

Also gave a better chance for test_ipv4_and_ipv6 in case something fails.

Changelog-Fixed: connectd: on macOS and other systems with dual-stack IPv6 default, wildcard '--addr=:' now correctly binds both IPv4 and IPv6.

Closes #9013


This PR also fixes the memleak in tests/test_connection.py::test_websocket and tests/test_connection.py::test_wss_proxy.

Closes #9016
Closes #9017

… behaviour

Systems with net.ipv6.bindv6only=0 (macOS, Fedora, Arch, vanilla kernels) create dual-stack sockets by default: binding '::' also covers '0.0.0.0', so the subsequent IPv4 wildcard bind fails with EADDRINUSE.  Debian/Ubuntu ship bindv6only=1 so both binds succeed here, which is why this was never noticed on typical Linux CI.

Explicitly set IPV6_V6ONLY=1 on AF_INET6 sockets before bind so both address families always get independent sockets regardless of the system sysctl.  Also free the errstr allocation left behind when the IPv4 bind fails acceptably (IPv6 succeeded), fixing a memleak in connectd on those systems.

test_ipv4_and_ipv6: accept IPv6-only binding in the single-socket case, which can still occur on IPv4-only hosts.

Changelog-Fixed: connectd: on macOS and other systems with dual-stack IPv6 default, wildcard '--addr=:<port>' now correctly binds both IPv4 and IPv6.
@nGoline nGoline self-assigned this May 19, 2026
@nGoline nGoline requested review from ddustin and rustyrussell May 19, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pytest: **BROKEN** in test_wss_proxy pytest: **BROKEN** in test_websocket pytest: **BROKEN** Error in test test_ipv4_and_ipv6

1 participant