fix: allow IPv4 and IPv6 inbounds to share a port (#6603)

* fix: distinguish IPv4 and IPv6 listen conflicts

* fix(ports): let an IPv4 address share a port only with a v6only wildcard

xray listens on tcp/udp, and Go opens every wildcard listen, 0.0.0.0
included, as one dual-stack socket unless sockopt.v6only is set. Treating
:: and 0.0.0.0 as separate families let the panel save pairs the core
then fails to bind, and it broke main's own TestListenOverlaps.

listenOverlaps now takes the inbound's sockopt.v6only: a wildcard claims
both families, or only IPv6 with v6only, so :: with v6only may share its
port with an IPv4 address while a plain :: or 0.0.0.0 still may not.

---------

Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
Xinny Lin
2026-09-27 04:02:22 +08:00
committed by GitHub
parent bd01f923fb
commit f3b100282a
4 changed files with 121 additions and 11 deletions
@@ -53,6 +53,30 @@ func TestBindConflicts(t *testing.T) {
{"listen":"0.0.0.0","port":443,"protocol":"vless","tag":"b","streamSettings":{"network":"tcp"}}`,
``, 0,
},
{
"ipv4 and ipv6 wildcards bind one dual-stack socket",
`{"listen":"::","port":443,"protocol":"vless","tag":"ipv6"},
{"listen":"0.0.0.0","port":443,"protocol":"vless","tag":"ipv4"}`,
``, 1,
},
{
"dual-stack ipv6 wildcard takes an ipv4 address",
`{"listen":"::","port":443,"protocol":"vless","tag":"ipv6"},
{"listen":"10.5.0.200","port":443,"protocol":"vless","tag":"ipv4"}`,
``, 1,
},
{
"v6only ipv6 wildcard leaves an ipv4 address free",
`{"listen":"::","port":443,"protocol":"vless","tag":"ipv6","streamSettings":{"network":"tcp","sockopt":{"v6only":true}}},
{"listen":"10.5.0.200","port":443,"protocol":"vless","tag":"ipv4"}`,
``, 0,
},
{
"v6only ipv6 wildcard still collides with the dual-stack 0.0.0.0",
`{"listen":"::","port":443,"protocol":"vless","tag":"ipv6","streamSettings":{"network":"tcp","sockopt":{"v6only":true}}},
{"listen":"0.0.0.0","port":443,"protocol":"vless","tag":"ipv4"}`,
``, 1,
},
{
"wildcard listen overlaps a loopback one",
`{"listen":"0.0.0.0","port":8443,"protocol":"vless","tag":"a"},