This commit is contained in:
DHR60 2026-01-31 11:44:11 +08:00
parent 57ba378072
commit 7a978bf43d
4 changed files with 17 additions and 12 deletions

View file

@ -462,6 +462,18 @@ public class Utils
return (domain, port);
}
public static string? DomainStrategy4Sbox(string? strategy)
{
return strategy switch
{
not null when strategy.StartsWith("UseIPv4") => "prefer_ipv4",
not null when strategy.StartsWith("UseIPv6") => "prefer_ipv6",
not null when strategy.StartsWith("ForceIPv4") => "ipv4_only",
not null when strategy.StartsWith("ForceIPv6") => "ipv6_only",
_ => null
};
}
#endregion Conversion Functions
#region Data Checks

View file

@ -398,13 +398,6 @@ public class Global
""
];
public static readonly Dictionary<string, string> DomainStrategy4SboxMap =
DomainStrategy
.Where(s => s.StartsWith("UseIPv4", StringComparison.Ordinal) || s.StartsWith("UseIPv6", StringComparison.Ordinal))
.ToDictionary(
key => key,
key => key.StartsWith("UseIPv4", StringComparison.Ordinal) ? "prefer_ipv4" : "prefer_ipv6");
public static readonly List<string> DomainDirectDNSAddress =
[
"https://dns.alidns.com/dns-query",

View file

@ -180,13 +180,13 @@ public partial class CoreConfigSingboxService
new Rule4Sbox
{
server = Global.SingboxRemoteDNSTag,
strategy = Global.DomainStrategy4SboxMap.GetValueOrDefault(simpleDNSItem.Strategy4Proxy),
strategy = Utils.DomainStrategy4Sbox(simpleDNSItem.Strategy4Proxy),
clash_mode = ERuleMode.Global.ToString()
},
new Rule4Sbox
{
server = Global.SingboxDirectDNSTag,
strategy = Global.DomainStrategy4SboxMap.GetValueOrDefault(simpleDNSItem.Strategy4Freedom),
strategy = Utils.DomainStrategy4Sbox(simpleDNSItem.Strategy4Freedom),
clash_mode = ERuleMode.Direct.ToString()
}
});
@ -309,7 +309,7 @@ public partial class CoreConfigSingboxService
if (item.OutboundTag == Global.DirectTag)
{
rule.server = Global.SingboxDirectDNSTag;
rule.strategy = Global.DomainStrategy4SboxMap.GetValueOrDefault(simpleDNSItem.Strategy4Freedom);
rule.strategy = Utils.DomainStrategy4Sbox(simpleDNSItem.Strategy4Freedom);
if (expectedIPsRegions.Count > 0 && rule.geosite?.Count > 0)
{
@ -343,7 +343,7 @@ public partial class CoreConfigSingboxService
singboxConfig.dns.rules.Add(rule4Fake);
}
rule.server = Global.SingboxRemoteDNSTag;
rule.strategy = Global.DomainStrategy4SboxMap.GetValueOrDefault(simpleDNSItem.Strategy4Proxy);
rule.strategy = Utils.DomainStrategy4Sbox(simpleDNSItem.Strategy4Proxy);
}
singboxConfig.dns.rules.Add(rule);

View file

@ -10,7 +10,7 @@ public partial class CoreConfigSingboxService
var simpleDnsItem = _config.SimpleDNSItem;
var defaultDomainResolverTag = Global.SingboxDirectDNSTag;
var directDnsStrategy = Global.DomainStrategy4SboxMap.GetValueOrDefault(simpleDnsItem.Strategy4Freedom);
var directDnsStrategy = Utils.DomainStrategy4Sbox(simpleDnsItem.Strategy4Freedom);
var rawDNSItem = await AppManager.Instance.GetDNSItem(ECoreType.sing_box);
if (rawDNSItem is { Enabled: true })