Fix node domain resolve in TUN mode

This commit is contained in:
Wydy 2025-09-20 23:34:47 +08:00
parent 403b0bcf12
commit bc90eb7eba

View file

@ -44,16 +44,30 @@ public partial class CoreConfigSingboxService
} }
// Tun2SocksAddress // Tun2SocksAddress
if (node != null && Utils.IsDomain(node.Address)) if (node != null)
{
string? domainToAdd = null;
if (Utils.IsDomain(node.Address))
{
domainToAdd = node.Address;
}
else if (node.Sni != null && Utils.IsDomain(node.Sni))
{
domainToAdd = node.Sni;
}
if (domainToAdd != null)
{ {
singboxConfig.dns.rules ??= new List<Rule4Sbox>(); singboxConfig.dns.rules ??= new List<Rule4Sbox>();
singboxConfig.dns.rules.Insert(0, new Rule4Sbox singboxConfig.dns.rules.Insert(0, new Rule4Sbox
{ {
server = Global.SingboxOutboundResolverTag, server = Global.SingboxDirectDNSTag,
domain = [node.Address], domain = [domainToAdd],
}); });
} }
} }
}
catch (Exception ex) catch (Exception ex)
{ {
Logging.SaveLog(_tag, ex); Logging.SaveLog(_tag, ex);
@ -347,16 +361,30 @@ public partial class CoreConfigSingboxService
} }
// Tun2SocksAddress // Tun2SocksAddress
if (node != null && Utils.IsDomain(node.Address)) if (node != null)
{
string? domainToAdd = null;
if (Utils.IsDomain(node.Address))
{
domainToAdd = node.Address;
}
else if (node.Sni != null && Utils.IsDomain(node.Sni))
{
domainToAdd = node.Sni;
}
if (domainToAdd != null)
{ {
singboxConfig.dns.rules ??= new List<Rule4Sbox>(); singboxConfig.dns.rules ??= new List<Rule4Sbox>();
singboxConfig.dns.rules.Insert(0, new Rule4Sbox singboxConfig.dns.rules.Insert(0, new Rule4Sbox
{ {
server = Global.SingboxFinalResolverTag, server = Global.SingboxDirectDNSTag,
domain = [node.Address], domain = [domainToAdd],
}); });
} }
} }
}
catch (Exception ex) catch (Exception ex)
{ {
Logging.SaveLog(_tag, ex); Logging.SaveLog(_tag, ex);