fix: fakedns rule conflict

This commit is contained in:
arm64v8a 2023-05-01 15:31:35 +09:00
parent c3aafbfdc9
commit d4fb7c614c

View File

@ -214,6 +214,7 @@ fun buildConfig(
IPv6Mode.DISABLE -> { IPv6Mode.DISABLE -> {
strategy = "ipv4_only" strategy = "ipv4_only"
} }
IPv6Mode.ONLY -> { IPv6Mode.ONLY -> {
strategy = "ipv6_only" strategy = "ipv6_only"
} }
@ -234,9 +235,11 @@ fun buildConfig(
IPv6Mode.DISABLE -> { IPv6Mode.DISABLE -> {
inet4_address = listOf(VpnService.PRIVATE_VLAN4_CLIENT + "/28") inet4_address = listOf(VpnService.PRIVATE_VLAN4_CLIENT + "/28")
} }
IPv6Mode.ONLY -> { IPv6Mode.ONLY -> {
inet6_address = listOf(VpnService.PRIVATE_VLAN6_CLIENT + "/126") inet6_address = listOf(VpnService.PRIVATE_VLAN6_CLIENT + "/126")
} }
else -> { else -> {
inet4_address = listOf(VpnService.PRIVATE_VLAN4_CLIENT + "/28") inet4_address = listOf(VpnService.PRIVATE_VLAN4_CLIENT + "/28")
inet6_address = listOf(VpnService.PRIVATE_VLAN6_CLIENT + "/126") inet6_address = listOf(VpnService.PRIVATE_VLAN6_CLIENT + "/126")
@ -389,20 +392,28 @@ fun buildConfig(
currentOutbound = when (bean) { currentOutbound = when (bean) {
is ConfigBean -> is ConfigBean ->
gson.fromJson(bean.config, currentOutbound.javaClass) gson.fromJson(bean.config, currentOutbound.javaClass)
is ShadowTLSBean -> // before StandardV2RayBean is ShadowTLSBean -> // before StandardV2RayBean
buildSingBoxOutboundShadowTLSBean(bean).asMap() buildSingBoxOutboundShadowTLSBean(bean).asMap()
is StandardV2RayBean -> // http/trojan/vmess/vless is StandardV2RayBean -> // http/trojan/vmess/vless
buildSingBoxOutboundStandardV2RayBean(bean).asMap() buildSingBoxOutboundStandardV2RayBean(bean).asMap()
is HysteriaBean -> is HysteriaBean ->
buildSingBoxOutboundHysteriaBean(bean).asMap() buildSingBoxOutboundHysteriaBean(bean).asMap()
is SOCKSBean -> is SOCKSBean ->
buildSingBoxOutboundSocksBean(bean).asMap() buildSingBoxOutboundSocksBean(bean).asMap()
is ShadowsocksBean -> is ShadowsocksBean ->
buildSingBoxOutboundShadowsocksBean(bean).asMap() buildSingBoxOutboundShadowsocksBean(bean).asMap()
is WireGuardBean -> is WireGuardBean ->
buildSingBoxOutboundWireguardBean(bean).asMap() buildSingBoxOutboundWireguardBean(bean).asMap()
is SSHBean -> is SSHBean ->
buildSingBoxOutboundSSHBean(bean).asMap() buildSingBoxOutboundSSHBean(bean).asMap()
else -> throw IllegalStateException("can't reach") else -> throw IllegalStateException("can't reach")
} }
@ -752,14 +763,14 @@ fun buildConfig(
} }
if (forTest) { if (forTest) {
// Disable DNS for test // Always use system DNS for urlTest
dns.servers = listOf( dns.servers = listOf(
DNSServerOptions().apply { DNSServerOptions().apply {
address = LOCAL_DNS_SERVER address = LOCAL_DNS_SERVER
tag = "dns-local" tag = "dns-local"
detour = TAG_DIRECT detour = TAG_DIRECT
} }
) // Always use system DNS for urlTest )
dns.rules = listOf() dns.rules = listOf()
} else { } else {
// built-in DNS rules // built-in DNS rules
@ -788,7 +799,24 @@ fun buildConfig(
server = "dns-block" server = "dns-block"
disable_cache = true disable_cache = true
}) })
// force bypass // FakeDNS obj
if (useFakeDns) {
dns.servers.add(DNSServerOptions().apply {
address = "fakedns://" + VpnService.FAKEDNS_VLAN4_CLIENT + "/15"
tag = "dns-fake"
strategy = "ipv4_only"
})
dns.rules.add(0, DNSRule_DefaultOptions().apply {
auth_user = listOf("fakedns")
server = "dns-remote"
})
dns.rules.add(DNSRule_DefaultOptions().apply {
inbound = listOf("tun-in")
server = "dns-fake"
disable_cache = true
})
}
// force bypass (always top DNS rule)
if (domainListDNSDirectForce.isNotEmpty()) { if (domainListDNSDirectForce.isNotEmpty()) {
dns.rules.add(0, DNSRule_DefaultOptions().apply { dns.rules.add(0, DNSRule_DefaultOptions().apply {
makeSingBoxRule(domainListDNSDirectForce.toHashSet().toList()) makeSingBoxRule(domainListDNSDirectForce.toHashSet().toList())
@ -796,24 +824,6 @@ fun buildConfig(
}) })
} }
} }
// fakedns obj
if (useFakeDns) {
dns.servers.add(DNSServerOptions().apply {
address = "fakedns://" + VpnService.FAKEDNS_VLAN4_CLIENT + "/15"
tag = "dns-fake"
strategy = "ipv4_only"
})
dns.rules.add(0, DNSRule_DefaultOptions().apply {
auth_user = listOf("fakedns")
server = "dns-remote"
})
dns.rules.add(DNSRule_DefaultOptions().apply {
inbound = listOf("tun-in")
server = "dns-fake"
disable_cache = true
})
}
}.let { }.let {
ConfigBuildResult( ConfigBuildResult(
gson.toJson(it.asMap().apply { gson.toJson(it.asMap().apply {