Fix tun (#7802)
Some checks are pending
release Linux / build (Release) (push) Waiting to run
release macOS / build (Release) (push) Waiting to run
release Windows desktop (Avalonia UI) / build (Release) (push) Waiting to run
release Windows / build (Release) (push) Waiting to run

This commit is contained in:
DHR60 2025-08-19 09:10:54 +08:00 committed by GitHub
parent 4a40b87bba
commit dc94962900
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 5 deletions

View file

@ -64,7 +64,7 @@ public partial class CoreConfigSingboxService(Config config)
await GenRouting(singboxConfig); await GenRouting(singboxConfig);
await GenDns(singboxConfig); await GenDns(node, singboxConfig);
await GenExperimental(singboxConfig); await GenExperimental(singboxConfig);
@ -421,7 +421,7 @@ public partial class CoreConfigSingboxService(Config config)
} }
await GenOutboundsList(proxyProfiles, singboxConfig); await GenOutboundsList(proxyProfiles, singboxConfig);
await GenDns(singboxConfig); await GenDns(null, singboxConfig);
await ConvertGeo2Ruleset(singboxConfig); await ConvertGeo2Ruleset(singboxConfig);
ret.Success = true; ret.Success = true;

View file

@ -2,14 +2,14 @@ namespace ServiceLib.Services.CoreConfig;
public partial class CoreConfigSingboxService public partial class CoreConfigSingboxService
{ {
private async Task<int> GenDns(SingboxConfig singboxConfig) private async Task<int> GenDns(ProfileItem? node, SingboxConfig singboxConfig)
{ {
try try
{ {
var item = await AppManager.Instance.GetDNSItem(ECoreType.sing_box); var item = await AppManager.Instance.GetDNSItem(ECoreType.sing_box);
if (item != null && item.Enabled == true) if (item != null && item.Enabled == true)
{ {
return await GenDnsCompatible(singboxConfig); return await GenDnsCompatible(node, singboxConfig);
} }
var simpleDNSItem = _config.SimpleDNSItem; var simpleDNSItem = _config.SimpleDNSItem;
@ -19,6 +19,7 @@ public partial class CoreConfigSingboxService
singboxConfig.dns ??= new Dns4Sbox(); singboxConfig.dns ??= new Dns4Sbox();
singboxConfig.dns.independent_cache = true; singboxConfig.dns.independent_cache = true;
// final dns
var routing = await ConfigHandler.GetDefaultRouting(_config); var routing = await ConfigHandler.GetDefaultRouting(_config);
var useDirectDns = false; var useDirectDns = false;
if (routing != null) if (routing != null)
@ -32,6 +33,17 @@ public partial class CoreConfigSingboxService
lastRule.Ip?.Contains("0.0.0.0/0") == true); lastRule.Ip?.Contains("0.0.0.0/0") == true);
} }
singboxConfig.dns.final = useDirectDns ? Global.SingboxDirectDNSTag : Global.SingboxRemoteDNSTag; singboxConfig.dns.final = useDirectDns ? Global.SingboxDirectDNSTag : Global.SingboxRemoteDNSTag;
// Tun2SocksAddress
if (node != null && Utils.IsDomain(node.Address))
{
singboxConfig.dns.rules ??= new List<Rule4Sbox>();
singboxConfig.dns.rules.Insert(0, new Rule4Sbox
{
server = Global.SingboxOutboundResolverTag,
domain = [node.Address],
});
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -290,7 +302,7 @@ public partial class CoreConfigSingboxService
return 0; return 0;
} }
private async Task<int> GenDnsCompatible(SingboxConfig singboxConfig) private async Task<int> GenDnsCompatible(ProfileItem? node, SingboxConfig singboxConfig)
{ {
try try
{ {
@ -320,6 +332,17 @@ public partial class CoreConfigSingboxService
{ {
await GenDnsDomainsLegacyCompatible(singboxConfig, item); await GenDnsDomainsLegacyCompatible(singboxConfig, item);
} }
// Tun2SocksAddress
if (node != null && Utils.IsDomain(node.Address))
{
singboxConfig.dns.rules ??= new List<Rule4Sbox>();
singboxConfig.dns.rules.Insert(0, new Rule4Sbox
{
server = Global.SingboxFinalResolverTag,
domain = [node.Address],
});
}
} }
catch (Exception ex) catch (Exception ex)
{ {