From dc94962900e6364824ef8f9b40f857f555ca248b Mon Sep 17 00:00:00 2001 From: DHR60 Date: Tue, 19 Aug 2025 09:10:54 +0800 Subject: [PATCH] Fix tun (#7802) --- .../Singbox/CoreConfigSingboxService.cs | 4 +-- .../CoreConfig/Singbox/SingboxDnsService.cs | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/CoreConfigSingboxService.cs index 7ee82af1..4e24d8e2 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/CoreConfigSingboxService.cs @@ -64,7 +64,7 @@ public partial class CoreConfigSingboxService(Config config) await GenRouting(singboxConfig); - await GenDns(singboxConfig); + await GenDns(node, singboxConfig); await GenExperimental(singboxConfig); @@ -421,7 +421,7 @@ public partial class CoreConfigSingboxService(Config config) } await GenOutboundsList(proxyProfiles, singboxConfig); - await GenDns(singboxConfig); + await GenDns(null, singboxConfig); await ConvertGeo2Ruleset(singboxConfig); ret.Success = true; diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs index c317ef53..15f2c43b 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs @@ -2,14 +2,14 @@ namespace ServiceLib.Services.CoreConfig; public partial class CoreConfigSingboxService { - private async Task GenDns(SingboxConfig singboxConfig) + private async Task GenDns(ProfileItem? node, SingboxConfig singboxConfig) { try { var item = await AppManager.Instance.GetDNSItem(ECoreType.sing_box); if (item != null && item.Enabled == true) { - return await GenDnsCompatible(singboxConfig); + return await GenDnsCompatible(node, singboxConfig); } var simpleDNSItem = _config.SimpleDNSItem; @@ -19,6 +19,7 @@ public partial class CoreConfigSingboxService singboxConfig.dns ??= new Dns4Sbox(); singboxConfig.dns.independent_cache = true; + // final dns var routing = await ConfigHandler.GetDefaultRouting(_config); var useDirectDns = false; if (routing != null) @@ -32,6 +33,17 @@ public partial class CoreConfigSingboxService lastRule.Ip?.Contains("0.0.0.0/0") == true); } singboxConfig.dns.final = useDirectDns ? Global.SingboxDirectDNSTag : Global.SingboxRemoteDNSTag; + + // Tun2SocksAddress + if (node != null && Utils.IsDomain(node.Address)) + { + singboxConfig.dns.rules ??= new List(); + singboxConfig.dns.rules.Insert(0, new Rule4Sbox + { + server = Global.SingboxOutboundResolverTag, + domain = [node.Address], + }); + } } catch (Exception ex) { @@ -290,7 +302,7 @@ public partial class CoreConfigSingboxService return 0; } - private async Task GenDnsCompatible(SingboxConfig singboxConfig) + private async Task GenDnsCompatible(ProfileItem? node, SingboxConfig singboxConfig) { try { @@ -320,6 +332,17 @@ public partial class CoreConfigSingboxService { await GenDnsDomainsLegacyCompatible(singboxConfig, item); } + + // Tun2SocksAddress + if (node != null && Utils.IsDomain(node.Address)) + { + singboxConfig.dns.rules ??= new List(); + singboxConfig.dns.rules.Insert(0, new Rule4Sbox + { + server = Global.SingboxFinalResolverTag, + domain = [node.Address], + }); + } } catch (Exception ex) {