From b3102b34b37578e720b261f97af7f3ad22089289 Mon Sep 17 00:00:00 2001 From: nirvanalinlei <143369142+nirvanalinlei@users.noreply.github.com> Date: Thu, 2 Apr 2026 20:47:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20sing-box=20TUN=20=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=20relay=20=E5=87=BA=E7=AB=99=E7=9A=84=20mux?= =?UTF-8?q?=20=E9=97=AE=E9=A2=98=20(#9018)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix sing-box selector generation for dynamic group tags * 修复 TUN 模式下 DNS 失败及 Windows 提权重启后 TUN 状态丢失 * 按上游意见回滚 TUN 提权时保留启用状态的改动 --- v2rayN/ServiceLib/Common/ProcUtils.cs | 5 ++-- .../Singbox/SingboxOutboundService.cs | 23 +++++++++++++++++++ .../ViewModels/StatusBarViewModel.cs | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/v2rayN/ServiceLib/Common/ProcUtils.cs b/v2rayN/ServiceLib/Common/ProcUtils.cs index ce487c7a..3f5c31af 100644 --- a/v2rayN/ServiceLib/Common/ProcUtils.cs +++ b/v2rayN/ServiceLib/Common/ProcUtils.cs @@ -46,7 +46,7 @@ public static class ProcUtils return null; } - public static void RebootAsAdmin(bool blAdmin = true) + public static bool RebootAsAdmin(bool blAdmin = true) { try { @@ -58,11 +58,12 @@ public static class ProcUtils FileName = Utils.GetExePath().AppendQuotes(), Verb = blAdmin ? "runas" : null, }; - _ = Process.Start(startInfo); + return Process.Start(startInfo) != null; } catch (Exception ex) { Logging.SaveLog(_tag, ex); + return false; } } } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs index 7a86761f..f422da96 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs @@ -345,6 +345,14 @@ public partial class CoreConfigSingboxService { try { + // The synthetic TUN relay outbound talks to the local Xray shadowsocks relay. + // Xray cannot terminate sing-box h2mux, so muxing here turns local relay traffic + // into sp.mux.sing-box.arpa pseudo-destinations and breaks DNS over TUN. + if (IsTunRelayProxyOutbound()) + { + return; + } + var muxEnabled = _node.MuxEnabled ?? _config.CoreBasicItem.MuxEnabled; if (muxEnabled && _config.Mux4SboxItem.Protocol.IsNotEmpty()) { @@ -364,6 +372,21 @@ public partial class CoreConfigSingboxService } } + private bool IsTunRelayProxyOutbound() + { + if (!context.IsTunEnabled + || _node.ConfigType != EConfigType.Shadowsocks + || _node.Address != Global.Loopback + || _node.Port != context.ProxyRelaySsPort + || _node.Password != Global.None) + { + return false; + } + + var protocolExtra = _node.GetProtocolExtra(); + return protocolExtra.SsMethod == Global.None; + } + private void FillOutboundTls(Outbound4Sbox outbound) { try diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index b8154c16..0ce40dbb 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -490,6 +490,7 @@ public class StatusBarViewModel : MyReactiveObject } } } + await ConfigHandler.SaveConfig(_config); AppEvents.ReloadRequested.Publish(); }