Skip to content

TUN inbound: Ignore dns IPv6 setup error when neither gateway nor autoSystemRoutingTable has an IPv6 entry on Windows - #7325

Merged
RPRX merged 2 commits into
XTLS:mainfrom
YOIMIYA66:pr-fix-windows-tun-ipv6-setdns
Nov 4, 2026
Merged

RPRX merged 2 commits into
XTLS:mainfrom
YOIMIYA66:pr-fix-windows-tun-ipv6-setdns

Conversation

@YOIMIYA66

Copy link
Copy Markdown
Contributor

Problem Description

On Windows 11 24H2 (OS Build 26100+), starting Xray in native TUN mode fails with:

proxy/tun: xray_tun up: failed to set dns: Access is denied.

Root Cause Analysis

  1. In Windows 11 24H2, the NSI/TCP stack allocates an MIB row for IPv6 on newly created Wintun virtual adapters even if IPv6 is systemically disabled or has DisabledComponents = 0x28.
  2. As a result, t.luid.IPInterface(windows.AF_INET6) returns nil instead of windows.ERROR_NOT_FOUND.
  3. Execution then reaches t.luid.SetDNS(windows.AF_INET6, dns, nil), which invokes SetInterfaceDnsSettings with DNS_INTERFACE_SETTINGS_VERSION1 and DNS_SETTING_IPV6.
  4. Windows kernel rejects this call with Win32 Error 5 (ERROR_ACCESS_DENIED) because the Wintun interface possesses no unicast IPv6 address (unicastAddresses is empty).

Changes in this PR

  1. Guard Loop by Configured State: Check whether the address or route is actually configured for the protocol family. If neither address nor route is present, safely skip IPInterface and SetDNS.
  2. SetDNS Guard by Unicast Address: Skip SetDNS() on families without assigned unicast IP addresses, which prevents Win32 Error 5.
  3. Preserve Empty DNS Clearing Semantics: Distribute configured DNS servers into familyDNS. If an addressed family is provided with an empty DNS list, it still passes the empty slice to SetDNS() to clear existing DNS servers, maintaining proper DNS lifecycle semantics.

Test Verification

Tested on Windows 11 24H2 (Build 26100.2161) with Wintun 0.14.1 across 6 scenarios:

  • IPv4-only TUN: Successfully creates and configures the adapter without Access is denied.
  • Dual-stack IPv4 + IPv6: Correctly applies routes and DNS to both families.
  • IPv4 DNS + IPv6 Route (::/0): Sets IPv4 DNS while skipping IPv6 SetDNS on unaddressed IPv6 interface.
  • Empty DNS clearing: Correctly passes empty slice to addressed interfaces to reset DNS.
  • Process SIGKILL & rapid restart: Rapid recovery on existing adapter name without registry corruption.
  • External IPv6 leak prevention: WFP block leak rules verified 100% effective.

YOIMIYA66 and others added 2 commits November 3, 2026 21:00
…not be set

Instead of the checks of the previous commit, IPv6 that neither gateway
nor autoSystemRoutingTable has is skipped when setting its DNS servers
fails, as when the adapter has no IPv6 interface. Everything else is set
up as before.

Skipping SetDNS for an IP version without an address in gateway left dns
unapplied without gateway, where Windows gives the TUN link-local
addresses, and winipcfg's SetDNS already keeps only the servers of the
IP version given.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@patterniha

Copy link
Copy Markdown
Collaborator

I pushed a simpler fix: if neither gateway nor autoSystemRoutingTable has an IPv6 entry, a failed IPv6 DNS setup is now just skipped instead of stopping Xray.

@YOIMIYA66

Copy link
Copy Markdown
Contributor Author

Thanks for the simpler fix — I agree with it completely, and it is clearly better than what I submitted.

The part I find most elegant is that it does not try to predict the interface state at all. My version skipped SetDNS when gateway had no entry for the family, but that is not the same as the interface having no address: without gateway, Windows still gives the TUN link-local addresses and DNS can be applied normally. Making the call anyway and only tolerating the failure for a family nobody asked for keeps that case intact. Dropping the manual DNS split was right too — winipcfg's SetDNS already keeps only the servers of the given IP version.

I learned a lot from this: fix at the point where it actually fails, use the narrowest condition, and do not re-implement what the called library already guarantees. Thank you for taking the time to push a cleaner patch instead of just asking me to redo it. I would love to keep learning from your reviews and changes in this repo.

@RPRX RPRX changed the title TUN inbound: Skip SetDNS on unaddressed IPv6 interface on Windows TUN inbound: Ignore dns IPv6 setup error when neither gateway nor autoSystemRoutingTable has an IPv6 entry on Windows Nov 4, 2026
@RPRX
RPRX merged commit ad98ffd into XTLS:main Nov 4, 2026
39 checks passed
@RPRX

RPRX commented Nov 4, 2026

Copy link
Copy Markdown
Member

@patterniha 更新文档 XTLS/Xray-docs-next#903

虽然这么改跟 autoSystemWfpBlockLeak "misconfigtun" 一样抽象,如果用户那两项都没配置 IPv6,为什么配置 IPv6 dns?

况且 gateway 都没有 IPv6 的话,dns 有 IPv6 真的实际有用吗?以及 Windows 上自动分配 gateway,这个判断结果可靠吗?

再说如果 IPv6 被系统级 disable 了,gateway 和 autoSystemRoutingTable 含 IPv6 不退出吗?为什么 dns 搞特殊?

如果追求即使 IPv6 被系统级 disable 了,那些设置项含 IPv6 也不会阻止 TUN 启动,也不是这么改,虽然可能不该追求这个

@RPRX

RPRX commented Nov 4, 2026

Copy link
Copy Markdown
Member

声明一下:显然,我先合并了这个 PR 只是因为看你俩都认同这么改,但是我并没有完全认同这个修改方向

@patterniha

Copy link
Copy Markdown
Collaborator

@patterniha 更新文档 XTLS/Xray-docs-next#903

虽然这么改跟 autoSystemWfpBlockLeak "misconfigtun" 一样抽象,如果用户那两项都没配置 IPv6,为什么配置 IPv6 dns?

况且 gateway 都没有 IPv6 的话,dns 有 IPv6 真的实际有用吗?以及 Windows 上自动分配 gateway,这个判断结果可靠吗?

再说如果 IPv6 被系统级 disable 了,gateway 和 autoSystemRoutingTable 含 IPv6 不退出吗?为什么 dns 搞特殊?

如果追求即使 IPv6 被系统级 disable 了,那些设置项含 IPv6 也不会阻止 TUN 启动,也不是这么改,虽然可能不该追求这个

Xray sets the TUN's IPv6 DNS on every start, and just clears it when dns has no IPv6 server or isn't set at all. That clearing is what failed for the reporter, so even a TUN with no IPv6 anywhere couldn't start. The check is the same as for the missing IPv6 interface, so it doesn't depend on the addresses Windows assigns.

But you're right that dns shouldn't be special: in #7332, IPv6 servers in dns also keep the TUN from starting, like IPv6 in gateway and autoSystemRoutingTable. Docs updated in XTLS/Xray-docs-next#903.

RPRX pushed a commit that referenced this pull request Nov 6, 2026
… cannot be set up, as in `gateway` and `autoSystemRoutingTable` (#7332)

#7325 (comment)
#7332 (comment)
#7332 (comment)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
patterniha added a commit that referenced this pull request Nov 7, 2026
…onents` turns IPv6 off, with "misconfigtun" blocking IPv6 then

#7341 (comment)

IPv6 entries are no longer left out. With IPv6 turned off by
DisabledComponents (0x10, the non-tunnel interfaces, the TUN among them,
as in 0xFF), IPv6 is set up as usual, and errors doing so, clearing its
DNS servers included, are only logged; otherwise they exit, also for a
config without IPv6 entries, which replaces the skips of #6874, #7325 and
#7332. "misconfigtun" then blocks IPv6 outside the TUN whatever the routes,
as IPv6 still works until the reboot that applies the value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RPRX pushed a commit that referenced this pull request Nov 8, 2026
… `DisabledComponents` turns IPv6 off, with "misconfigtun" blocking IPv6 then (#7341)

#7325 (comment)
#7332 (comment)
#7341 (comment)

Replaces #7332, #7325 and #6874

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
RPRX pushed a commit that referenced this pull request Nov 8, 2026
…outingTable`) instead of exiting on Windows when `DisabledComponents` turns IPv6 off, with `autoSystemWfpBlockLeak`'s "misconfigtun" blocking IPv6 then (#7341)

#7325 (comment)
#7332 (comment)
#7341 (comment)

Replaces #7332, #7325 and #6874

---------

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.

3 participants