Repository navigation
finalmask: UDP masks on freedom and WireGuard - #246
Merged
Merged
Conversation
added 5 commits
November 9, 2026 19:19
Freedom's UDP flows (SOCKS, TUN, DNS through freedom) and WireGuard's socket take finalmask.udp, as Xray-core's FinalMask.DialUDP wraps every UDP socket it dials. xray_transport::MaskedUdpSocket runs the QUIC carriers' masks one datagram at a time over its own connected socket, without Quinn's UDP state. udphop, realm and mkcp-legacy stay refused on these carriers, sudoku under xdns or xicmp too, and WireGuard under masks takes one peer.
A standalone header-custom holds a send until the server answers its request, and only a read takes the answer in. Freedom's flows read only between their sends, so every SOCKS, TUN and DNS flow under such a mask hung; WireGuard's receive task also sends, under its peer's lock. Xray-core's mask reads in a goroutine of its own meanwhile. Under a standalone mask, a held send now reads in the receiver's place. The masks take the answer in; what they hand over is kept for the receiver, up to 256 KiB, and the receiver is woken for it and again once the send is through, since the socket wakes only the last task waiting on it. The TUN DNS proxy sent its queries through freedom on a plain socket, so every query but a plain A or AAAA one bypassed the masks. It now opens freedom's masked socket, as the other freedom paths do.
added 3 commits
November 10, 2026 10:30
…de/finalmask-udp-direct
The test parsed its realm mask from a freedom outbound over XHTTP H3 and moved it onto the VLESS config it runs. Freedom now takes finalmask.udp for its own UDP flows and refuses realm there, so that parse failed and check-realm-interop.sh stopped go-oracles. A VLESS outbound over the same transport, which is what the test runs, reads the mask as before.
… into claude/finalmask-udp-direct
aimalygin
pushed a commit
that referenced
this pull request
Nov 14, 2026
go-oracles failed on PR #295 (run 43619978436, "Verify Shadowsocks 2022 TCP, UDP and TUN"): shadowsocks_runtime_udp_reopens_after_port_change_and _survives_server_restart panicked with "reference exited", and Xray's log said "listen tcp 127.0.0.1:45109: bind: address already in use". The harness picks the reference's port by binding 127.0.0.1:0 and dropping the listener before Xray binds it; the binary's other tests run in parallel, and one of their sockets took the port in that gap. The same race failed v08_carriers on PR #246. Unrelated to the PR's change. The shared harness (mux, Shadowsocks, Trojan and VMess runtime tests) now treats a reference that exits with "address already in use" as a lost port: a start tries again on a fresh port, up to five times, and a restart, which must keep its port, respawns for about two seconds. Any other exit still fails the test with the reference's log.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Xray-core v26.10.31's
FinalMask.DialUDPwraps every UDP socket it dials, so freedom's flows and WireGuard's socket takefinalmask.udpthere. Here the parser (WireGuard) orCore::build(both) refused them, and the freedomnoisesdeprecation warning pointed to a config that then failed to start.How
xray_transport::MaskedUdpSocketruns the QUIC carriers' masks one datagram at a time: noise,header-custom, Salamander with Gecko, sudoku, xdns and xicmp. It uses the carriers' own code in Xray-core's order:carrier::wrap_masks, with the xdns and xicmp clients from the newcarrier::tunnel.header-customholds a send until the server answers its request, and only a read takes the answer in. Xray-core's mask reads in a goroutine of its own meanwhile. Here, under a standalone mask, a held send reads in the receiver's place:Freedom. Every UDP flow goes through the masks: flows from SOCKS and TUN, the PROXY header, freedom's
noises, and DNS queries routed through freedom, the core's own and the TUN DNS proxy's. A masked flow sends only to its destination and takes replies only from it.WireGuard. Its one socket goes under the masks.
sockoptandfinalmask.udpin WireGuard'sstreamSettings, and refusesfinalmask.tcpandquicParams.Refused on both, in the parser, in
Core::buildand in the outbound constructors:mkcp-legacy, as on every carrier except mKCP;Differences from Xray-core
These are written up in
docs/xray-core-differences.md:Evidence
Core::buildaccepts freedom and one-peer WireGuard under masks, and refuses two peers.direct_udp_masks::incheck-hysteria-interop.sh:tunnelinbound under the same masks: Salamander, noise inside it, header-custom in prefix and standalone mode, sudoku, and sudoku inside Salamander;[::]:0freedom socket got our IPv4 socket's port, and our socket took the reply. A connected socket does not take it.xray-wireguardlib, lifecycle, interop and multi-peer, pluswireguard_runtime_.direct_udp_masks::2/2.cargo test --workspace --exclude xray-rust-fuzz: 3855 passed, 0 failed.socks_inbound_wire::the_handshake_has_one_deadline, which failed once on macOS after the c10f9d8 merge and fails there on main too, is fixed separately in SOCKS handshake-deadline test: a reset after the deadline is the close (macOS flake) #259.-D warnings,cargo fmt --check, andcheck-public-fixtures.test.shall pass;docs/config-contract.jsonmatches a fresh regeneration.direct_udp_masks::against 26.11.9: 2/2.check-realm-interop.shon every run of this PR; on c10f9d8 the steps from there on were run locally against 26.11.9 and all passed.Also in this PR
realm_introduces_xhttp_h3_to_xrayread its mask off a freedom outbound over XHTTP H3 and moved it onto the VLESS config it runs. Freedom now takesfinalmask.udpitself and refuses realm, so that parse failed and stopped go-oracles on 674b8bf. The test reads the mask off a VLESS outbound now (af48276).finalmask.tcpand realm on WireGuard.docs/config-contract.jsonis regenerated.docs/xray-core-differences.md, both sides kept. The bridge's UDP sessions through freedom take the SOCKS flow path, so they go under the masks too;for_reversekeeps them.docs/config-contract.jsonmatches a fresh regeneration.FinalMask.DialUDPas it was; its freedomfinalRulesand WireGuard endpoint lookup changes do not meet this code. So the docs keep citing v26.10.31 for it, as main does for features v26.11.9 did not change. The merged contract matches a fresh regeneration.xicmpraw socket takes the outbound'ssockopt, withinterfacebound first. Freedom and WireGuard open both through the same code and the same outbound protector as the QUIC carriers, so they behave the same there. Both are deliberate differences from Xray-core that Land #251: transport hardening against a hostile peer (mKCP, xmc, realm, MASQUE, HTTP inbound, xdns, reverse, DNS, sockopt) #260 records.🤖 Generated with Claude Code