mirror of https://github.com/2dust/v2rayN
fix
parent
dff67e9d78
commit
97bd64ee9a
|
@ -245,7 +245,7 @@ public class CoreConfigSingboxService
|
|||
singboxConfig.route.rules.Add(rule);
|
||||
}
|
||||
|
||||
await GenDns(singboxConfig);
|
||||
await GenDnsDomains(singboxConfig, _config.DNSItem);
|
||||
//var dnsServer = singboxConfig.dns?.servers.FirstOrDefault();
|
||||
//if (dnsServer != null)
|
||||
//{
|
||||
|
@ -317,7 +317,7 @@ public class CoreConfigSingboxService
|
|||
await GenOutbound(node, singboxConfig.outbounds.First());
|
||||
}
|
||||
await GenMoreOutbounds(node, singboxConfig);
|
||||
await GenDns(singboxConfig);
|
||||
await GenDnsDomains(singboxConfig, _config.DNSItem);
|
||||
|
||||
singboxConfig.route.rules.Clear();
|
||||
singboxConfig.inbounds.Clear();
|
||||
|
@ -1230,8 +1230,7 @@ public class CoreConfigSingboxService
|
|||
{
|
||||
server = "outbound_resolver",
|
||||
strategy = item.SingboxStrategy4Direct
|
||||
}
|
||||
;
|
||||
};
|
||||
|
||||
if (_config.TunModeItem.EnableTun)
|
||||
{
|
||||
|
@ -1582,7 +1581,7 @@ public class CoreConfigSingboxService
|
|||
|
||||
singboxConfig.dns ??= new Dns4Sbox();
|
||||
singboxConfig.dns.independent_cache = true;
|
||||
singboxConfig.dns.final = "dns_remote"; // TODO
|
||||
singboxConfig.dns.final = "dns_remote"; // TODO: Select fallback DNS server based on routing rules
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -1593,8 +1592,7 @@ public class CoreConfigSingboxService
|
|||
|
||||
private async Task<int> GenDnsServers(SingboxConfig singboxConfig, DNSItem dNSItem)
|
||||
{
|
||||
var finalDns = ParseDnsAddress(dNSItem.SingboxFinalResolveDNS);
|
||||
finalDns.tag = "final_resolver";
|
||||
var finalDns = await GenDnsDomains(singboxConfig, dNSItem);
|
||||
|
||||
var directDns = ParseDnsAddress(dNSItem.DirectDNS);
|
||||
directDns.tag = "dns_direct";
|
||||
|
@ -1668,7 +1666,6 @@ public class CoreConfigSingboxService
|
|||
singboxConfig.dns.servers ??= new List<Server4Sbox>();
|
||||
singboxConfig.dns.servers.Add(remoteDns);
|
||||
singboxConfig.dns.servers.Add(directDns);
|
||||
singboxConfig.dns.servers.Add(finalDns);
|
||||
singboxConfig.dns.servers.Add(resolverDns);
|
||||
singboxConfig.dns.servers.Add(hostsDns);
|
||||
|
||||
|
@ -1688,6 +1685,16 @@ public class CoreConfigSingboxService
|
|||
return await Task.FromResult(0);
|
||||
}
|
||||
|
||||
private async Task<Server4Sbox> GenDnsDomains(SingboxConfig singboxConfig, DNSItem? dNSItem)
|
||||
{
|
||||
var finalDns = ParseDnsAddress(dNSItem.SingboxFinalResolveDNS);
|
||||
finalDns.tag = "final_resolver";
|
||||
singboxConfig.dns ??= new Dns4Sbox();
|
||||
singboxConfig.dns.servers ??= new List<Server4Sbox>();
|
||||
singboxConfig.dns.servers.Add(finalDns);
|
||||
return await Task.FromResult(finalDns);
|
||||
}
|
||||
|
||||
private async Task<int> GenDnsRules(SingboxConfig singboxConfig, DNSItem dNSItem)
|
||||
{
|
||||
singboxConfig.dns ??= new Dns4Sbox();
|
||||
|
@ -1778,41 +1785,42 @@ public class CoreConfigSingboxService
|
|||
|
||||
private static Server4Sbox? ParseDnsAddress(string address)
|
||||
{
|
||||
if (string.IsNullOrEmpty(address))
|
||||
var addressFirst = address?.Split(address.Contains(',') ? ',' : ';').FirstOrDefault()?.Trim();
|
||||
if (string.IsNullOrEmpty(addressFirst))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var server = new Server4Sbox();
|
||||
|
||||
if (address is "local" or "localhost")
|
||||
if (addressFirst is "local" or "localhost")
|
||||
{
|
||||
server.type = "local";
|
||||
return server;
|
||||
}
|
||||
|
||||
if (address.StartsWith("dhcp://", StringComparison.OrdinalIgnoreCase))
|
||||
if (addressFirst.StartsWith("dhcp://", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var interface_name = address.Substring(7);
|
||||
var interface_name = addressFirst.Substring(7);
|
||||
server.type = "dhcp";
|
||||
server.Interface = interface_name == "auto" ? null : interface_name;
|
||||
return server;
|
||||
}
|
||||
|
||||
if (!address.Contains("://"))
|
||||
if (!addressFirst.Contains("://"))
|
||||
{
|
||||
// udp dns
|
||||
server.type = "udp";
|
||||
server.server = address;
|
||||
server.server = addressFirst;
|
||||
return server;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var protocolEndIndex = address.IndexOf("://", StringComparison.Ordinal);
|
||||
server.type = address.Substring(0, protocolEndIndex).ToLower();
|
||||
var protocolEndIndex = addressFirst.IndexOf("://", StringComparison.Ordinal);
|
||||
server.type = addressFirst.Substring(0, protocolEndIndex).ToLower();
|
||||
|
||||
var uri = new Uri(address);
|
||||
var uri = new Uri(addressFirst);
|
||||
server.server = uri.Host;
|
||||
|
||||
if (!uri.IsDefaultPort)
|
||||
|
@ -1827,11 +1835,11 @@ public class CoreConfigSingboxService
|
|||
}
|
||||
catch (UriFormatException)
|
||||
{
|
||||
var protocolEndIndex = address.IndexOf("://", StringComparison.Ordinal);
|
||||
var protocolEndIndex = addressFirst.IndexOf("://", StringComparison.Ordinal);
|
||||
if (protocolEndIndex > 0)
|
||||
{
|
||||
server.type = address.Substring(0, protocolEndIndex).ToLower();
|
||||
var remaining = address.Substring(protocolEndIndex + 3);
|
||||
server.type = addressFirst.Substring(0, protocolEndIndex).ToLower();
|
||||
var remaining = addressFirst.Substring(protocolEndIndex + 3);
|
||||
|
||||
var portIndex = remaining.IndexOf(':');
|
||||
var pathIndex = remaining.IndexOf('/');
|
||||
|
@ -1884,7 +1892,8 @@ public class CoreConfigSingboxService
|
|||
singboxConfig.experimental.cache_file = new CacheFile4Sbox()
|
||||
{
|
||||
enabled = true,
|
||||
path = Utils.GetBinPath("cache.db")
|
||||
path = Utils.GetBinPath("cache.db"),
|
||||
store_fakeip = _config.DNSItem.FakeIP == true
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1164,6 +1164,32 @@ public class CoreConfigV2rayService
|
|||
|
||||
private async Task<int> GenDnsServers(ProfileItem? node, V2rayConfig v2rayConfig, DNSItem dNSItem)
|
||||
{
|
||||
var directDNSAddress = dNSItem?.DirectDNS?
|
||||
.Split(dNSItem.DirectDNS?.Contains(',') == true ? ',' : ';')
|
||||
.Select(addr => addr.Trim())
|
||||
.Where(addr => !string.IsNullOrEmpty(addr))
|
||||
.Select(addr => addr.StartsWith("dhcp", StringComparison.OrdinalIgnoreCase) ? "localhost" : addr)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
if (directDNSAddress != null && directDNSAddress.Count == 0)
|
||||
{
|
||||
directDNSAddress = new() { Global.DomainDirectDNSAddress.FirstOrDefault() };
|
||||
}
|
||||
|
||||
var remoteDNSAddress = dNSItem?.RemoteDNS?
|
||||
.Split(dNSItem.RemoteDNS?.Contains(',') == true ? ',' : ';')
|
||||
.Select(addr => addr.Trim())
|
||||
.Where(addr => !string.IsNullOrEmpty(addr))
|
||||
.Select(addr => addr.StartsWith("dhcp", StringComparison.OrdinalIgnoreCase) ? "localhost" : addr)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
if (remoteDNSAddress != null && remoteDNSAddress.Count == 0)
|
||||
{
|
||||
remoteDNSAddress = new() { Global.DomainRemoteDNSAddress.FirstOrDefault() };
|
||||
}
|
||||
|
||||
var directDomainList = new List<string>();
|
||||
var directGeositeList = new List<string>();
|
||||
var proxyDomainList = new List<string>();
|
||||
|
@ -1258,45 +1284,63 @@ public class CoreConfigV2rayService
|
|||
|
||||
if (proxyDomainList.Count > 0)
|
||||
{
|
||||
var dnsServer = new DnsServer4Ray()
|
||||
foreach (var dnsDomain in remoteDNSAddress)
|
||||
{
|
||||
address = dNSItem.RemoteDNS,
|
||||
skipFallback = true,
|
||||
domains = proxyDomainList
|
||||
};
|
||||
v2rayConfig.dns.servers.Add(JsonUtils.SerializeToNode(dnsServer));
|
||||
}
|
||||
if (proxyGeositeList.Count > 0)
|
||||
{
|
||||
var dnsServer = new DnsServer4Ray()
|
||||
{
|
||||
address = dNSItem.RemoteDNS,
|
||||
skipFallback = true,
|
||||
domains = proxyGeositeList
|
||||
};
|
||||
v2rayConfig.dns.servers.Add(JsonUtils.SerializeToNode(dnsServer));
|
||||
var dnsServer = new DnsServer4Ray()
|
||||
{
|
||||
address = dnsDomain,
|
||||
skipFallback = true,
|
||||
domains = proxyDomainList
|
||||
};
|
||||
v2rayConfig.dns.servers.Add(JsonUtils.SerializeToNode(dnsServer));
|
||||
}
|
||||
}
|
||||
if (directDomainList.Count > 0)
|
||||
{
|
||||
var dnsServer = new DnsServer4Ray()
|
||||
foreach (var dnsDomain in directDNSAddress)
|
||||
{
|
||||
address = dNSItem.DirectDNS,
|
||||
skipFallback = true,
|
||||
domains = directDomainList
|
||||
};
|
||||
v2rayConfig.dns.servers.Add(JsonUtils.SerializeToNode(dnsServer));
|
||||
var dnsServer = new DnsServer4Ray()
|
||||
{
|
||||
address = dnsDomain,
|
||||
skipFallback = true,
|
||||
domains = directDomainList
|
||||
};
|
||||
v2rayConfig.dns.servers.Add(JsonUtils.SerializeToNode(dnsServer));
|
||||
}
|
||||
}
|
||||
if (proxyGeositeList.Count > 0)
|
||||
{
|
||||
foreach (var dnsDomain in remoteDNSAddress)
|
||||
{
|
||||
var dnsServer = new DnsServer4Ray()
|
||||
{
|
||||
address = dnsDomain,
|
||||
skipFallback = true,
|
||||
domains = proxyGeositeList
|
||||
};
|
||||
v2rayConfig.dns.servers.Add(JsonUtils.SerializeToNode(dnsServer));
|
||||
}
|
||||
}
|
||||
if (directGeositeList.Count > 0)
|
||||
{
|
||||
var dnsServer = new DnsServer4Ray()
|
||||
foreach (var dnsDomain in directDNSAddress)
|
||||
{
|
||||
address = dNSItem.DirectDNS,
|
||||
skipFallback = true,
|
||||
domains = directGeositeList
|
||||
};
|
||||
v2rayConfig.dns.servers.Add(JsonUtils.SerializeToNode(dnsServer));
|
||||
var dnsServer = new DnsServer4Ray()
|
||||
{
|
||||
address = dnsDomain,
|
||||
skipFallback = true,
|
||||
domains = directGeositeList
|
||||
};
|
||||
v2rayConfig.dns.servers.Add(JsonUtils.SerializeToNode(dnsServer));
|
||||
}
|
||||
}
|
||||
|
||||
// fallback DNS server
|
||||
// TODO: Select fallback DNS server based on routing rules
|
||||
foreach (var dnsDomain in remoteDNSAddress)
|
||||
{
|
||||
v2rayConfig.dns.servers.Add(dnsDomain);
|
||||
}
|
||||
v2rayConfig.dns.servers.Add(dNSItem.RemoteDNS); // fallback DNS server
|
||||
return await Task.FromResult(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ public partial class DNSSettingWindow : WindowBase<DNSSettingViewModel>
|
|||
cmbSBDirectDNSStrategy.ItemsSource = Global.SingboxDomainStrategy4Out;
|
||||
cmbSBRemoteDNSStrategy.ItemsSource = Global.SingboxDomainStrategy4Out;
|
||||
cmbDirectDNS.ItemsSource = Global.DomainDirectDNSAddress;
|
||||
cmbSBResolverDNS.ItemsSource = Global.DomainDirectDNSAddress.Concat(new[] { "dhcp://auto" });
|
||||
cmbSBResolverDNS.ItemsSource = Global.DomainDirectDNSAddress.Concat(new[] { "dhcp://auto,localhost" });
|
||||
cmbRemoteDNS.ItemsSource = Global.DomainRemoteDNSAddress;
|
||||
cmbSBFinalResolverDNS.ItemsSource = Global.DomainPureIPDNSAddress;
|
||||
cmbSBFinalResolverDNS.ItemsSource = Global.DomainPureIPDNSAddress.Concat(new[] { "dhcp://auto,localhost" });
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
|
|
|
@ -21,9 +21,9 @@ public partial class DNSSettingWindow
|
|||
cmbSBDirectDNSStrategy.ItemsSource = Global.SingboxDomainStrategy4Out;
|
||||
cmbSBRemoteDNSStrategy.ItemsSource = Global.SingboxDomainStrategy4Out;
|
||||
cmbDirectDNS.ItemsSource = Global.DomainDirectDNSAddress;
|
||||
cmbSBResolverDNS.ItemsSource = Global.DomainDirectDNSAddress.Concat(new[] { "dhcp://auto" });
|
||||
cmbSBResolverDNS.ItemsSource = Global.DomainDirectDNSAddress.Concat(new[] { "dhcp://auto,localhost" });
|
||||
cmbRemoteDNS.ItemsSource = Global.DomainRemoteDNSAddress;
|
||||
cmbSBFinalResolverDNS.ItemsSource = Global.DomainPureIPDNSAddress;
|
||||
cmbSBFinalResolverDNS.ItemsSource = Global.DomainPureIPDNSAddress.Concat(new[] { "dhcp://auto,localhost" });
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue