Skip to content

Transport: Bind the UDP outbound socket in the destination family - #6688

Merged
RPRX merged 2 commits into
XTLS:mainfrom
adsdevdoo:udp-outbound-family
Aug 27, 2026
Merged

RPRX merged 2 commits into
XTLS:mainfrom
adsdevdoo:udp-outbound-family

Conversation

@adsdevdoo

Copy link
Copy Markdown
Contributor

The generic half I mentioned in #6624.

An outbound UDP socket with no sendThrough address is bound to the 0.0.0.0
wildcard. On most platforms that's fine: the runtime turns it into a
dual-stack socket on [::] (see ipToSockaddrInet6 in net/ipsock_posix.go), so
IPv6 destinations work anyway. OpenBSD and DragonFly have no IPv4-mapped
addresses at all, there the socket stays AF_INET and a send to an IPv6 peer
fails with "non-IPv4 address".

So bind the wildcard of the destination's own family instead: 0.0.0.0 for a
v4 destination, :: for a v6 one. On platforms with the mapping both wildcards
produce exactly the same dual-stack socket as before, nothing changes there.
The network string passed to ListenPacket is untouched too, so sockopt
controllers keep getting the same arguments.

Tested on OpenBSD 7.7/7.8/7.9 amd64: with this and #6624 the transparent
proxy handles IPv6 UDP (DNS, QUIC) end to end on a live router.

An outbound UDP socket without a sendThrough address is bound to the
0.0.0.0 wildcard. Where IPv4-mapped IPv6 addresses are available the
runtime turns that into a dual-stack socket on [::], so an IPv6
destination still works, but OpenBSD and DragonFly have no such mapping
and the socket stays AF_INET, which cannot reach an IPv6 peer: the send
then fails with "non-IPv4 address".

Bind the wildcard of the destination own family instead. On the
platforms that do support the mapping this is the very same socket as
before, because 0.0.0.0 is already translated to [::] on bind.
@Fangliding

Fangliding commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

不是 怎么上个pr放了这么久刚合一天都没有又追加一个 两次了 不能一起弄完吗

@adsdevdoo

Copy link
Copy Markdown
Contributor Author

That was the plan agreed in #6624, actually: keep that one OpenBSD-only so it could be merged quickly, and send this piece separately because it touches every platform and deserves its own review. It was already mentioned there and RPRX was fine with it.

Update comments to clarify wildcard binding for address family.
@Fangliding

Copy link
Copy Markdown
Member

好吧 我看到了 bsd破事真多

@RPRX

RPRX commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

改成这样写在其它系统上也没问题,不过下面应用 sockopt 或许会受影响?可以先合了看看

@RPRX
RPRX merged commit 540b907 into XTLS:main Aug 27, 2026
40 checks passed
@RPRX

RPRX commented Aug 27, 2026

Copy link
Copy Markdown
Member

好吧 我看到了 bsd破事真多

或许只是因为 OpenBSD 追求严谨性安全性,可能在 FreeBSD 上单个 socket 能双栈

@Fangliding

Copy link
Copy Markdown
Member

正常系统不会有影响 正常系统一个ipv6 socket可以同时管ipv4和v6 对ipv4的操作自动映射到一个划分好的ipv6段 所以go的行为是无论0000还是::全部用 :: 然后使用双栈特性 oepnbsd不支持而已 理由还是security reason 就跟不让用syscall一样

adsdevdoo added a commit to adsdevdoo/Xray-core that referenced this pull request Oct 25, 2026
XTLS#6688 picks the wildcard of the destination's family, but still passes
the generic "udp" network to ListenPacket. For "[::]:0" Go also tries
0.0.0.0 (golang/go#18806) and ListenPacket prefers the IPv4 address.
Where IPv4-mapped addresses exist that is still a dual-stack socket, but
OpenBSD has none: the socket stays AF_INET and every send to an IPv6
peer fails with "non-IPv4 address". Name the family explicitly there;
other platforms keep the dual-stack socket they get today.

Completes XTLS#6688

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

4 participants