mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-19 13:42:24 +00:00
Refactors DNS address parsing
This commit is contained in:
parent
2365012670
commit
9d95143d85
1 changed files with 36 additions and 31 deletions
|
@ -1453,45 +1453,50 @@ public class CoreConfigSingboxService
|
||||||
var localDnsAddress = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress;
|
var localDnsAddress = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress;
|
||||||
string? localDnsType = null;
|
string? localDnsType = null;
|
||||||
string? dhcpDnsInterface = null;
|
string? dhcpDnsInterface = null;
|
||||||
|
var dnsProtocols = new List<string>
|
||||||
|
{
|
||||||
|
"dhcp",
|
||||||
|
"https",
|
||||||
|
"tcp",
|
||||||
|
"tls",
|
||||||
|
"quic",
|
||||||
|
"h3",
|
||||||
|
"udp"
|
||||||
|
};
|
||||||
if (localDnsAddress == "local")
|
if (localDnsAddress == "local")
|
||||||
{
|
{
|
||||||
localDnsType = "local";
|
localDnsType = "local";
|
||||||
localDnsAddress = null;
|
localDnsAddress = null;
|
||||||
}
|
}
|
||||||
else if (localDnsAddress.StartsWith("dhcp") && localDnsAddress.Length > 7)
|
else if (dnsProtocols.Any(protocol => localDnsAddress.StartsWith(protocol)))
|
||||||
{
|
{
|
||||||
localDnsType = "dhcp";
|
var protocol = dnsProtocols.First(p => localDnsAddress.StartsWith(p));
|
||||||
// dhcp://
|
localDnsType = protocol;
|
||||||
dhcpDnsInterface = localDnsAddress.Substring(7);
|
// +3 for "://"
|
||||||
if (dhcpDnsInterface == "auto")
|
if (localDnsAddress.Length > protocol.Length + 3)
|
||||||
{
|
{
|
||||||
dhcpDnsInterface = null;
|
localDnsAddress = localDnsAddress.Substring(protocol.Length + 3);
|
||||||
|
if (protocol == "dhcp")
|
||||||
|
{
|
||||||
|
dhcpDnsInterface = localDnsAddress;
|
||||||
|
if (dhcpDnsInterface == "auto")
|
||||||
|
{
|
||||||
|
dhcpDnsInterface = null;
|
||||||
|
}
|
||||||
|
localDnsAddress = null;
|
||||||
|
}
|
||||||
|
else if (protocol is "https" or "h3")
|
||||||
|
{
|
||||||
|
if (localDnsAddress.Contains('/'))
|
||||||
|
{
|
||||||
|
localDnsAddress = localDnsAddress.Substring(0, localDnsAddress.IndexOf('/'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
localDnsAddress = null;
|
||||||
}
|
}
|
||||||
localDnsAddress = null;
|
|
||||||
}
|
|
||||||
else if (localDnsAddress.StartsWith("tcp") && localDnsAddress.Length > 6)
|
|
||||||
{
|
|
||||||
localDnsType = "tcp";
|
|
||||||
// tcp://
|
|
||||||
localDnsAddress = localDnsAddress.Substring(6);
|
|
||||||
}
|
|
||||||
else if (localDnsAddress.StartsWith("tls") && localDnsAddress.Length > 6)
|
|
||||||
{
|
|
||||||
localDnsType = "tls";
|
|
||||||
// tls://
|
|
||||||
localDnsAddress = localDnsAddress.Substring(6);
|
|
||||||
}
|
|
||||||
else if (localDnsAddress.StartsWith("https") && localDnsAddress.Length > 8)
|
|
||||||
{
|
|
||||||
localDnsType = "https";
|
|
||||||
// https://
|
|
||||||
localDnsAddress = localDnsAddress.Substring(8);
|
|
||||||
}
|
|
||||||
else if (localDnsAddress.StartsWith("quic") && localDnsAddress.Length > 7)
|
|
||||||
{
|
|
||||||
localDnsType = "quic";
|
|
||||||
// quic://
|
|
||||||
localDnsAddress = localDnsAddress.Substring(7);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue