mirror of
https://github.com/2dust/v2rayN.git
synced 2026-02-28 13:13:04 +00:00
Compare commits
2 commits
78e8731d17
...
eec565357a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eec565357a | ||
|
|
7128852ddb |
3 changed files with 52 additions and 19 deletions
|
|
@ -49,6 +49,7 @@ public class Global
|
||||||
public const string DirectTag = "direct";
|
public const string DirectTag = "direct";
|
||||||
public const string BlockTag = "block";
|
public const string BlockTag = "block";
|
||||||
public const string DnsTag = "dns-module";
|
public const string DnsTag = "dns-module";
|
||||||
|
public const string DirectDnsTag = "direct-dns";
|
||||||
public const string BalancerTagSuffix = "-round";
|
public const string BalancerTagSuffix = "-round";
|
||||||
public const string StreamSecurity = "tls";
|
public const string StreamSecurity = "tls";
|
||||||
public const string StreamSecurityReality = "reality";
|
public const string StreamSecurityReality = "reality";
|
||||||
|
|
|
||||||
|
|
@ -220,12 +220,6 @@ public class DnsServer4Ray
|
||||||
public List<string>? domains { get; set; }
|
public List<string>? domains { get; set; }
|
||||||
public bool? skipFallback { get; set; }
|
public bool? skipFallback { get; set; }
|
||||||
public List<string>? expectedIPs { get; set; }
|
public List<string>? expectedIPs { get; set; }
|
||||||
public List<string>? unexpectedIPs { get; set; }
|
|
||||||
public string? clientIp { get; set; }
|
|
||||||
public string? queryStrategy { get; set; }
|
|
||||||
public int? timeoutMs { get; set; }
|
|
||||||
public bool? disableCache { get; set; }
|
|
||||||
public bool? finalQuery { get; set; }
|
|
||||||
public string? tag { get; set; }
|
public string? tag { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,25 @@ public partial class CoreConfigV2rayService
|
||||||
dnsItem.enableParallelQuery = simpleDnsItem?.ParallelQuery is true ? true : null;
|
dnsItem.enableParallelQuery = simpleDnsItem?.ParallelQuery is true ? true : null;
|
||||||
|
|
||||||
// DNS routing
|
// DNS routing
|
||||||
|
var directDnsTags = dnsItem.servers
|
||||||
|
.Select(server =>
|
||||||
|
{
|
||||||
|
var tagNode = (server as JsonObject)?["tag"];
|
||||||
|
return tagNode is JsonValue value && value.TryGetValue<string>(out var tag) ? tag : null;
|
||||||
|
})
|
||||||
|
.Where(tag => tag is not null && tag.StartsWith(Global.DirectDnsTag, StringComparison.Ordinal))
|
||||||
|
.Select(tag => tag!)
|
||||||
|
.ToList();
|
||||||
|
if (directDnsTags.Count > 0)
|
||||||
|
{
|
||||||
|
_coreConfig.routing.rules.Add(new()
|
||||||
|
{
|
||||||
|
type = "field",
|
||||||
|
inboundTag = directDnsTags,
|
||||||
|
outboundTag = Global.DirectTag,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var finalRule = BuildFinalRule();
|
var finalRule = BuildFinalRule();
|
||||||
dnsItem.tag = Global.DnsTag;
|
dnsItem.tag = Global.DnsTag;
|
||||||
_coreConfig.routing.rules.Add(new()
|
_coreConfig.routing.rules.Add(new()
|
||||||
|
|
@ -78,7 +97,7 @@ public partial class CoreConfigV2rayService
|
||||||
type = "field",
|
type = "field",
|
||||||
inboundTag = [Global.DnsTag],
|
inboundTag = [Global.DnsTag],
|
||||||
outboundTag = finalRule.outboundTag,
|
outboundTag = finalRule.outboundTag,
|
||||||
balancerTag = finalRule.balancerTag
|
balancerTag = finalRule.balancerTag,
|
||||||
});
|
});
|
||||||
|
|
||||||
_coreConfig.dns = dnsItem;
|
_coreConfig.dns = dnsItem;
|
||||||
|
|
@ -212,11 +231,13 @@ public partial class CoreConfigV2rayService
|
||||||
|
|
||||||
dnsItem.servers ??= [];
|
dnsItem.servers ??= [];
|
||||||
|
|
||||||
|
var directDnsTagIndex = 1;
|
||||||
|
|
||||||
AddDnsServers(remoteDNSAddress, proxyDomainList);
|
AddDnsServers(remoteDNSAddress, proxyDomainList);
|
||||||
AddDnsServers(directDNSAddress, directDomainList);
|
AddDnsServers(directDNSAddress, directDomainList, true);
|
||||||
AddDnsServers(remoteDNSAddress, proxyGeositeList);
|
AddDnsServers(remoteDNSAddress, proxyGeositeList);
|
||||||
AddDnsServers(directDNSAddress, directGeositeList);
|
AddDnsServers(directDNSAddress, directGeositeList, true);
|
||||||
AddDnsServers(directDNSAddress, expectedDomainList, expectedIPs);
|
AddDnsServers(directDNSAddress, expectedDomainList, true, expectedIPs);
|
||||||
if (dnsServerDomains.Count > 0)
|
if (dnsServerDomains.Count > 0)
|
||||||
{
|
{
|
||||||
AddDnsServers(bootstrapDNSAddress, dnsServerDomains);
|
AddDnsServers(bootstrapDNSAddress, dnsServerDomains);
|
||||||
|
|
@ -234,8 +255,21 @@ public partial class CoreConfigV2rayService
|
||||||
useDirectDns = noDomain && noProcess && isAnyIp && isAnyPort && isAnyNetwork;
|
useDirectDns = noDomain && noProcess && isAnyIp && isAnyPort && isAnyNetwork;
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultDnsServers = useDirectDns ? directDNSAddress : remoteDNSAddress;
|
if (!useDirectDns)
|
||||||
dnsItem.servers.AddRange(defaultDnsServers);
|
{
|
||||||
|
dnsItem.servers.AddRange(remoteDNSAddress);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var dns in directDNSAddress)
|
||||||
|
{
|
||||||
|
var dnsServer = CreateDnsServer(dns, []);
|
||||||
|
dnsServer.tag = $"{Global.DirectDnsTag}-{directDnsTagIndex++}";
|
||||||
|
dnsServer.skipFallback = false;
|
||||||
|
dnsItem.servers.Add(JsonUtils.SerializeToNode(dnsServer,
|
||||||
|
new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }));
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
static List<string> ParseDnsAddresses(string? dnsInput, string defaultAddress)
|
static List<string> ParseDnsAddresses(string? dnsInput, string defaultAddress)
|
||||||
|
|
@ -249,7 +283,7 @@ public partial class CoreConfigV2rayService
|
||||||
return addresses.Count > 0 ? addresses : new List<string> { defaultAddress };
|
return addresses.Count > 0 ? addresses : new List<string> { defaultAddress };
|
||||||
}
|
}
|
||||||
|
|
||||||
static object? CreateDnsServer(string dnsAddress, List<string> domains, List<string>? expectedIPs = null)
|
static DnsServer4Ray CreateDnsServer(string dnsAddress, List<string> domains, List<string>? expectedIPs = null)
|
||||||
{
|
{
|
||||||
var (domain, scheme, port, path) = Utils.ParseUrl(dnsAddress);
|
var (domain, scheme, port, path) = Utils.ParseUrl(dnsAddress);
|
||||||
var domainFinal = dnsAddress;
|
var domainFinal = dnsAddress;
|
||||||
|
|
@ -272,13 +306,10 @@ public partial class CoreConfigV2rayService
|
||||||
domains = domains.Count > 0 ? domains : null,
|
domains = domains.Count > 0 ? domains : null,
|
||||||
expectedIPs = expectedIPs?.Count > 0 ? expectedIPs : null
|
expectedIPs = expectedIPs?.Count > 0 ? expectedIPs : null
|
||||||
};
|
};
|
||||||
return JsonUtils.SerializeToNode(dnsServer, new JsonSerializerOptions
|
return dnsServer;
|
||||||
{
|
|
||||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddDnsServers(List<string> dnsAddresses, List<string> domains, List<string>? expectedIPs = null)
|
void AddDnsServers(List<string> dnsAddresses, List<string> domains, bool isDirectDns = false, List<string>? expectedIPs = null)
|
||||||
{
|
{
|
||||||
if (domains.Count <= 0)
|
if (domains.Count <= 0)
|
||||||
{
|
{
|
||||||
|
|
@ -286,7 +317,14 @@ public partial class CoreConfigV2rayService
|
||||||
}
|
}
|
||||||
foreach (var dnsAddress in dnsAddresses)
|
foreach (var dnsAddress in dnsAddresses)
|
||||||
{
|
{
|
||||||
dnsItem.servers.Add(CreateDnsServer(dnsAddress, domains, expectedIPs));
|
var dnsServer = CreateDnsServer(dnsAddress, domains, expectedIPs);
|
||||||
|
if (isDirectDns)
|
||||||
|
{
|
||||||
|
dnsServer.tag = $"{Global.DirectDnsTag}-{directDnsTagIndex++}";
|
||||||
|
}
|
||||||
|
var dnsServerNode = JsonUtils.SerializeToNode(dnsServer,
|
||||||
|
new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull });
|
||||||
|
dnsItem.servers.Add(dnsServerNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue