From 90b055e364e4e07a0cdd6a98dea11219b133670b Mon Sep 17 00:00:00 2001 From: DHR60 Date: Mon, 20 Apr 2026 10:58:56 +0000 Subject: [PATCH] Remove legacy sing-box dns compatibility (#9163) --- v2rayN/ServiceLib/Models/SingboxConfig.cs | 8 ------ .../CoreConfig/Singbox/SingboxDnsService.cs | 27 +------------------ .../ViewModels/DNSSettingViewModel.cs | 12 ++++++--- 3 files changed, 9 insertions(+), 38 deletions(-) diff --git a/v2rayN/ServiceLib/Models/SingboxConfig.cs b/v2rayN/ServiceLib/Models/SingboxConfig.cs index 000097bb..06449224 100644 --- a/v2rayN/ServiceLib/Models/SingboxConfig.cs +++ b/v2rayN/ServiceLib/Models/SingboxConfig.cs @@ -261,14 +261,6 @@ public class Server4Sbox : BaseServer4Sbox // public List? path { get; set; } // hosts public Dictionary>? predefined { get; set; } - - // Deprecated in sing-box 1.12.0 , kept for backward compatibility - public string? address { get; set; } - - public string? address_resolver { get; set; } - public string? address_strategy { get; set; } - public string? strategy { get; set; } - // Deprecated End } public class Experimental4Sbox diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs index f09d3ee9..a0d172ba 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs @@ -429,15 +429,7 @@ public partial class CoreConfigSingboxService return; } _coreConfig.dns = dns4Sbox; - if (dns4Sbox.servers?.Count > 0 && - dns4Sbox.servers.First().address.IsNullOrEmpty()) - { - GenDnsProtectCustom(); - } - else - { - GenDnsProtectCustomLegacy(); - } + GenDnsProtectCustom(); } catch (Exception ex) { @@ -479,23 +471,6 @@ public partial class CoreConfigSingboxService _coreConfig.dns = dns4Sbox; } - private void GenDnsProtectCustomLegacy() - { - GenDnsProtectCustom(); - - _coreConfig.dns?.servers?.RemoveAll(s => s.tag == Global.SingboxLocalDNSTag); - var dnsItem = context.RawDnsItem; - var localDnsServer = new Server4Sbox() - { - address = string.IsNullOrEmpty(dnsItem?.DomainDNSAddress) - ? Global.DomainPureIPDNSAddress.FirstOrDefault() - : dnsItem?.DomainDNSAddress, - tag = Global.SingboxLocalDNSTag, - detour = Global.DirectTag, - }; - _coreConfig.dns?.servers?.Add(localDnsServer); - } - private Rule4Sbox? BuildProtectDomainRule() { if (context.ProtectDomainList.Count == 0) diff --git a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs index 25fbe4b9..13571616 100644 --- a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs @@ -145,7 +145,9 @@ public class DNSSettingViewModel : MyReactiveObject if (NormalDNS2Compatible.IsNotEmpty()) { var obj2 = JsonUtils.Deserialize(NormalDNS2Compatible); - if (obj2 == null) + if (obj2 == null + || obj2.servers.Count == 0 + || obj2.servers.Any(s => s.type.IsNullOrEmpty())) { NoticeManager.Instance.Enqueue(ResUI.FillCorrectDNSText); return; @@ -154,7 +156,9 @@ public class DNSSettingViewModel : MyReactiveObject if (TunDNS2Compatible.IsNotEmpty()) { var obj2 = JsonUtils.Deserialize(TunDNS2Compatible); - if (obj2 == null) + if (obj2 == null + || obj2.servers.Count == 0 + || obj2.servers.Any(s => s.type.IsNullOrEmpty())) { NoticeManager.Instance.Enqueue(ResUI.FillCorrectDNSText); return; @@ -174,8 +178,8 @@ public class DNSSettingViewModel : MyReactiveObject item2.Enabled = SBCustomDNSEnableCompatible; item2.DomainStrategy4Freedom = DomainStrategy4Freedom2Compatible; item2.DomainDNSAddress = DomainDNSAddress2Compatible; - item2.NormalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(NormalDNS2Compatible)); - item2.TunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(TunDNS2Compatible)); + item2.NormalDNS = JsonUtils.Serialize(JsonUtils.Deserialize(NormalDNS2Compatible)); + item2.TunDNS = JsonUtils.Serialize(JsonUtils.Deserialize(TunDNS2Compatible)); await ConfigHandler.SaveDNSItems(_config, item2); await ConfigHandler.SaveConfig(_config);