Repository navigation
Conversation
Before, when sockopt.interface named an interface that does not exist, the error was logged at info level and the dial went on unbound, so the socket followed the routing table. In full-tunnel setups where outbounds are bound to an interface precisely to avoid falling back into the TUN (XTLS#7160), that silent fallback sends traffic into the tunnel again: the connection loops until ephemeral ports are exhausted, or leaks past the tunnel. Now the dial fails closed, the same way a bound socket fails when its interface has no route. Scope: only errors with sockopt.Interface set are propagated. Other sockopt errors keep the current behavior, since kernel support for some of them (TCP_FASTOPEN, SO_MARK, tcpCongestion) varies and configs in the wild rely on those being ignored on systems that refuse the setsockopt. Also name the interface in the linux and windows bind errors, the way the darwin version already does, so the failure names the bad value.
Member
|
我也许需要处理一些其他东西 |
5 tasks done
RPRX
pushed a commit
that referenced
this pull request
Oct 16, 2026
…ntrollers included such as TUN inbound's (#7173) #7161 (comment) Fixes #7160 (comment) --------- Co-authored-by: Gleb <[email protected]>
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.
Fixes #7160.
Problem
With
sockopt.interfaceset and the interface missing at dial time, Xray logs the bind error at info level and dials anyway, unbound. The connection then follows the routing table — which is exactly what the binding exists to prevent. In the setup from #7160 the fallback loops the connection back into the TUN: about 8,000 looped connections, all 16,384 ephemeral ports in use on the host,EADDRNOTAVAILfor other processes, until a restart.Change
The two
Controlclosures insystem_dialer.go(tcp dial and udp listen-packet) now propagate the error whensockopt.Interfaceis set, so the dial fails closed — the same way it already fails when the interface has no route. The dial failure is then reported by the usual path (freedom logsfailed to open connection > failed to bind to interface <name> > no such device), visible at normal log levels instead of the info-only line it was.Since
RawConn.Controlruns the option application inside a callback that cannot return an error itself, the error is captured and returned from the closure afterControlcompletes.Scope is deliberately limited to the interface option: other sockopt errors (TCP_FASTOPEN, SO_MARK, tcpCongestion) keep the current log-and-continue behavior, because support for those varies across kernels and systems, and configs in the wild rely on the setsockopt being ignored where the kernel refuses it. Unbound dialing is different though — what replaces the missing binding is never acceptable, it loops or leaks.
Also names the interface in the linux (
BindToDevice) and windows (InterfaceByName) error wrappers, the way the darwin one already does, so the failing value shows up in the error:Tests
TestDialInterfaceMissingindialer_test.go: tcp and udp dials to a working listener withsockopt.interface: "nosuchif0", both must return an error naming the interface (before the change, both succeeded unbound; the reporter's reproduction is the same thing seen through a socks inbound);