fix dns routing

This commit is contained in:
arm64v8a 2023-03-22 10:19:55 +09:00
parent faf964e992
commit 03c99d7482
2 changed files with 33 additions and 12 deletions

View File

@ -139,6 +139,7 @@ fun buildConfig(
val uidListDNSDirect = mutableListOf<Int>() val uidListDNSDirect = mutableListOf<Int>()
val domainListDNSRemote = mutableListOf<String>() val domainListDNSRemote = mutableListOf<String>()
val domainListDNSDirect = mutableListOf<String>() val domainListDNSDirect = mutableListOf<String>()
val domainListDNSDirectForce = mutableListOf<String>()
val domainListDNSBlock = mutableListOf<String>() val domainListDNSBlock = mutableListOf<String>()
val bypassDNSBeans = hashSetOf<AbstractBean>() val bypassDNSBeans = hashSetOf<AbstractBean>()
val isVPN = DataStore.serviceMode == Key.MODE_VPN val isVPN = DataStore.serviceMode == Key.MODE_VPN
@ -404,7 +405,7 @@ fun buildConfig(
pastEntity?.requireBean()?.apply { pastEntity?.requireBean()?.apply {
// don't loopback // don't loopback
if (currentDomainStrategy != "" && !serverAddress.isIpAddress()) { if (currentDomainStrategy != "" && !serverAddress.isIpAddress()) {
domainListDNSDirect.add("full:$serverAddress") domainListDNSDirectForce.add("full:$serverAddress")
} }
} }
if (forTest) { if (forTest) {
@ -628,7 +629,7 @@ fun buildConfig(
} }
if (!serverAddr.isIpAddress()) { if (!serverAddr.isIpAddress()) {
domainListDNSDirect.add("full:${serverAddr}") domainListDNSDirectForce.add("full:${serverAddr}")
} }
} }
@ -639,7 +640,7 @@ fun buildConfig(
} }
"https://$address".toHttpUrlOrNull()?.apply { "https://$address".toHttpUrlOrNull()?.apply {
if (!host.isIpAddress()) { if (!host.isIpAddress()) {
domainListDNSDirect.add("full:$host") domainListDNSDirectForce.add("full:$host")
} }
} }
} }
@ -675,6 +676,14 @@ fun buildConfig(
address = "rcode://success" address = "rcode://success"
tag = "dns-block" tag = "dns-block"
}) })
if (domainListDNSDirectForce.isNotEmpty()) {
dns.rules.add(
DNSRule_DefaultOptions().apply {
makeSingBoxRule(domainListDNSDirectForce.toHashSet().toList())
server = "dns-direct"
}
)
}
// dns object user rules // dns object user rules
if (enableDnsRouting) { if (enableDnsRouting) {
@ -696,15 +705,15 @@ fun buildConfig(
} }
) )
} }
} if (domainListDNSBlock.isNotEmpty()) {
if (domainListDNSBlock.isNotEmpty()) { dns.rules.add(
dns.rules.add( DNSRule_DefaultOptions().apply {
DNSRule_DefaultOptions().apply { makeSingBoxRule(domainListDNSBlock.toHashSet().toList())
makeSingBoxRule(domainListDNSBlock.toHashSet().toList()) server = "dns-block"
server = "dns-block" disable_cache = true
disable_cache = true }
} )
) }
} }
// Disable DNS for test // Disable DNS for test

View File

@ -34,6 +34,11 @@ object DNS {
domain.plusAssign(it) domain.plusAssign(it)
} }
} }
if (geosite?.isEmpty() == true) geosite = null
if (domain?.isEmpty() == true) domain = null
if (domain_suffix?.isEmpty() == true) domain_suffix = null
if (domain_regex?.isEmpty() == true) domain_regex = null
if (domain_keyword?.isEmpty() == true) domain_keyword = null
} }
fun SingBoxOptions.Rule_DefaultOptions.makeSingBoxRule(list: List<String>, isIP: Boolean) { fun SingBoxOptions.Rule_DefaultOptions.makeSingBoxRule(list: List<String>, isIP: Boolean) {
@ -70,5 +75,12 @@ object DNS {
domain.plusAssign(it) domain.plusAssign(it)
} }
} }
if (ip_cidr?.isEmpty() == true) geosite = null
if (geoip?.isEmpty() == true) geosite = null
if (geosite?.isEmpty() == true) geosite = null
if (domain?.isEmpty() == true) domain = null
if (domain_suffix?.isEmpty() == true) domain_suffix = null
if (domain_regex?.isEmpty() == true) domain_regex = null
if (domain_keyword?.isEmpty() == true) domain_keyword = null
} }
} }