From 36756ad6720560f352ee46512aa2531639c05fa9 Mon Sep 17 00:00:00 2001 From: patterniha <71074308+patterniha@users.noreply.github.com> Date: Fri, 6 Nov 2026 07:23:19 +0330 Subject: [PATCH] TUN inbound: IPv6 entries in `dns` exit the core on Windows when IPv6 cannot be set up, as in `gateway` and `autoSystemRoutingTable` (#7332) https://github.com/XTLS/Xray-core/pull/7325#issuecomment-6637932641 https://github.com/XTLS/Xray-core/pull/7332#issuecomment-6643930058 https://github.com/XTLS/Xray-core/pull/7332#issuecomment-6676374920 --------- Co-authored-by: Claude Opus 5.5 --- proxy/tun/README.md | 2 +- proxy/tun/tun_windows.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/proxy/tun/README.md b/proxy/tun/README.md index 6e6350277..71a0de723 100644 --- a/proxy/tun/README.md +++ b/proxy/tun/README.md @@ -223,7 +223,7 @@ To make it start, wintun.dll specific for your Windows/arch must be present next After the start network adapter with the name you chose in the config will be created in the system, and exist while Xray is running. A Wintun adapter that already has that name is reused. -With IPv6 disabled system-wide (the `DisabledComponents` registry value), the adapter has no IPv6, and the TUN starts with IPv4 only, unless `gateway` or `autoSystemRoutingTable` has IPv6 entries, which then keep it from starting. +With IPv6 disabled system-wide (the `DisabledComponents` registry value), the adapter has no IPv6, and the TUN starts with IPv4 only, unless `gateway`, `dns` or `autoSystemRoutingTable` has IPv6 entries, which then keep it from starting. When `dns` is set, those servers are applied to the adapter. Windows is kept from registering the TUN's addresses in DNS, and its DNS cache is flushed when the TUN starts and stops. Xray's own lookups through the system's DNS servers, like those of the `localhost` DNS server with `autoOutboundsInterface`, skip them, unless another interface uses them as well, as they would lead back into the TUN. diff --git a/proxy/tun/tun_windows.go b/proxy/tun/tun_windows.go index 81fc149e1..9f53cc189 100644 --- a/proxy/tun/tun_windows.go +++ b/proxy/tun/tun_windows.go @@ -115,6 +115,7 @@ func (t *WindowsTun) Start() (err error) { for _, ip := range t.options.DNS { dns = append(dns, netip.MustParseAddr(ip)) } + dns6 := slices.ContainsFunc(dns, netip.Addr.Is6) var route4, route6 bool routesMap := make(map[winipcfg.RouteData]struct{}) @@ -175,7 +176,7 @@ startOver: if err != nil { // With IPv6 disabled system-wide (DisabledComponents), the adapter has no // IPv6 interface at all. Skip the family unless the config asks for it. - if err == windows.ERROR_NOT_FOUND && family == windows.AF_INET6 && !address6 && !route6 { + if err == windows.ERROR_NOT_FOUND && family == windows.AF_INET6 && !address6 && !route6 && !dns6 { continue } return err @@ -204,7 +205,7 @@ startOver: // Skip IPv6 the config does not ask for also when setting its DNS // servers fails, as reported on Windows 11 24H2 with IPv6 disabled // (Access is denied). - if family == windows.AF_INET6 && !address6 && !route6 { + if family == windows.AF_INET6 && !address6 && !route6 && !dns6 { continue } firstErr = errors.New("unable to set DNS").Base(err)