sockopt.interface: when the interface does not exist, the dial silently goes unbound (can loop back into TUN)

Open
#7,160 19 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #7161 by @izislesar — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
go
Domain
networking

Research direction

Start in transport/internet/system_dialer.go, where applyOutboundSocketOptions errors are only logged before dialer.DialContext (about lines 134-139 for TCP and 77-81 for UDP). The lookup error originates from net.InterfaceByName in transport/internet/sockopt_darwin.go (about lines 136-140). Reproduce with a freedom outbound whose sockopt.interface names a nonexistent utun, then check that the dial currently succeeds. Done when a missing interface fails the dial on both paths and is logged at warning level. Linked PR #7161 was closed unmerged, so check why before starting.

Written by the indexing model from the issue text.

Description

Integrity requirements
  • I have read all the comments in the issue template and ensured that this issue meet the requirements.
  • I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
  • I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
  • I searched issues and did not find any similar issues.
  • The problem can be successfully reproduced in the latest Release
Description

If an outbound has streamSettings.sockopt.interface set and that interface does not exist at dial time, Xray does not fail the dial. It logs failed to apply socket options > failed to get interface ... at Info level and opens the connection without any binding, so it follows the system routing table.

transport/internet/system_dialer.go (v26.10.10, lines 134-139; same in v26.9.9) only logs the error returned by applyOutboundSocketOptions and goes on to dialer.DialContext. The UDP path does the same (lines 77-81). The error itself comes from net.InterfaceByName in transport/internet/sockopt_darwin.go:136-140. From reading the source, Linux takes the same path (the error is logged, not returned); I tested macOS only.

Why this matters. A typical full-tunnel setup on a desktop routes everything into a TUN interface handled by Xray (default route split as 0.0.0.0/1 + 128.0.0.0/1 into the TUN), and binds outbounds with sockopt.interface so that their own sockets do not enter the TUN again. If the bound interface goes away, the fallback sends the outbound's sockets into the TUN, Xray routes them to the same outbound, and the connection loops.

We hit this loop in practice on macOS. A separate OpenVPN client provided a corporate network through its own utun interface, and the corporate subnet was routed to a freedom outbound so that it would follow that VPN's route. At night the OpenVPN client lost its connection and its utun interface was removed. From then on, every connection to the corporate subnet (including DNS queries to the corporate DNS server) entered the TUN, came back to the same outbound and entered the TUN again. When we looked, there were about 8,000 looped connections, all 16,384 ephemeral ports were in use, and other processes on the host got EADDRNOTAVAIL (Can't assign requested address) on connect until the loop was broken by restarting Xray.

In that incident the outbound had no sockopt.interface at all, so the loop itself is a config problem. The obvious fix is to bind the outbound to the other VPN's interface ("interface": "utunN"), so that it can never fall into the TUN. That does not work because of this issue: once the interface disappears, the binding is skipped and the loop is back. The only visible sign is an Info-level log line, which is hidden at the usual warning level.

Expected: if the interface named in sockopt.interface cannot be found, the dial fails (fail closed), as a bound socket does when its interface has no route. At the very least the error should be logged as a warning. A silent fallback to the routing table defeats the purpose of binding: it can send traffic into a tunnel (loop) or past it (leak).

Reproduction Method

No server and no TUN are needed. Run Xray with the config below (interface utun99 does not exist) and send a request through the SOCKS inbound:

curl --socks5-hostname 127.0.0.1:1080 http://example.com/

Result: HTTP 200. The log shows that the interface was not found and the connection was opened anyway; its local endpoint is the address of whatever interface the routing table chose (on our machine, the address of a TUN interface that held the default route).

For comparison, with "interface": "en0" the same request goes out through en0 (local endpoint is en0's address) and no error is logged.

Expected result: the connection through the outbound bound to utun99 fails.

Tested on macOS arm64 with Xray 26.10.10 (701af60, the latest release) and 26.9.9 (52a412d): same result with both.

Client config

{
  "log": {"loglevel": "debug"},
  "inbounds": [{"listen": "127.0.0.1", "port": 1080, "protocol": "socks", "settings": {}}],
  "outbounds": [{"protocol": "freedom", "streamSettings": {"sockopt": {"interface": "utun99"}}}]
}
Server config

Not needed: the reproduction uses a freedom outbound only.
Client log

Xray 26.10.10 (Xray, Penetrates Everything.) 701af60 (go1.27.2 darwin/arm64)
A unified platform for anti-censorship.
2026/10/15 09:13:07.993097 [Info] infra/conf/serial: Reading config: &{Name:cfg1080-utun99.json Format:json}
2026/10/15 09:13:07.993480 [Debug] app/log: Logger started
2026/10/15 09:13:07.993612 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:1080
2026/10/15 09:13:07.993745 [Info] transport/internet/tcp: listening tcp on 127.0.0.1:1080
2026/10/15 09:13:07.993835 [Warning] core: Xray 26.10.10 started
2026/10/15 09:13:09.516363 [Info] [3266420241] proxy/socks: TCP Connect request to tcp:example.com:80
2026/10/15 09:13:09.516442 [Info] [3266420241] app/dispatcher: default route for tcp:example.com:80
2026/10/15 09:13:09.516552 from tcp:127.0.0.1:<port> accepted tcp:example.com:80
2026/10/15 09:13:09.516680 [Info] [3266420241] transport/internet/tcp: dialing TCP to tcp:example.com:80
2026/10/15 09:13:09.516712 [Debug] [3266420241] transport/internet: dialing to tcp:example.com:80
2026/10/15 09:13:09.621224 [Info] [3266420241] transport/internet: failed to apply socket options > transport/internet: failed to get interface utun99 > route ip+net: no such network interface
2026/10/15 09:13:09.621871 [Info] [3266420241] proxy/freedom: connection opened to tcp:example.com:80, local endpoint <TUN interface address>:<port>, remote endpoint <example.com address>:80
2026/10/15 09:13:09.621988 [Debug] [3266420241] proxy: CopyRawConn (maybe) readv
2026/10/15 09:13:09.727896 [Debug] app/log: Logger closing

For comparison, the same request with "interface": "en0" (no error logged):


2026/10/15 09:13:11.342041 [Info] [3042018327] proxy/freedom: connection opened to tcp:example.com:80, local endpoint <en0 address>:<port>, remote endpoint <example.com address>:80
Server log

Not needed.
Dominant language
Go
Stars
43.3k
Forks
6.2k
Avg merge
2d 11h
Merged PRs (30d)
55

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from XTLS/Xray-core

All issues in XTLS/Xray-core

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.