From 2bb7653770fdb8d0487c25b46c0455f71461c1a6 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:13:41 +0800 Subject: [PATCH] fix(Routing): Fix routing rules --- app/src/main/assets/custom_routing_black | 16 ++++++++-------- app/src/main/assets/custom_routing_global | 16 ++++++++-------- app/src/main/assets/custom_routing_white | 16 ++++++++-------- app/src/main/kotlin/com/neko/v2ray/AppConfig.kt | 5 ++++- .../com/neko/v2ray/util/SettingsManager.kt | 9 ++++++++- .../com/neko/v2ray/util/V2rayConfigUtil.kt | 14 ++++++++++---- 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/app/src/main/assets/custom_routing_black b/app/src/main/assets/custom_routing_black index 747e281e..757fc441 100644 --- a/app/src/main/assets/custom_routing_black +++ b/app/src/main/assets/custom_routing_black @@ -15,7 +15,7 @@ ] }, { - "remarks": "Block udp443", + "remarks": "Blocking udp 443", "outboundTag": "block", "port": "443", "network": "udp" @@ -28,17 +28,17 @@ ] }, { - "remarks": "Bypass LAN domain name", + "remarks": "Bypass LAN IP", "outboundTag": "direct", - "domain": [ - "geosite:private" + "ip": [ + "geoip:private" ] }, { - "remarks": "Bypass LAN IP", + "remarks": "Bypass LAN domain name", "outboundTag": "direct", - "ip": [ - "geoip:private" + "domain": [ + "geosite:private" ] }, { @@ -70,4 +70,4 @@ "port": "0-65535", "outboundTag": "direct" } -] \ No newline at end of file +] diff --git a/app/src/main/assets/custom_routing_global b/app/src/main/assets/custom_routing_global index 536b9ca5..b04900a6 100644 --- a/app/src/main/assets/custom_routing_global +++ b/app/src/main/assets/custom_routing_global @@ -1,6 +1,6 @@ [ { - "remarks": "Block udp443", + "remarks": "Block udp 443", "outboundTag": "block", "port": "443", "network": "udp" @@ -13,17 +13,17 @@ ] }, { - "remarks": "Bypass LAN domain name", + "remarks": "Bypass LAN IP", "outboundTag": "direct", - "domain": [ - "geosite:private" + "ip": [ + "geoip:private" ] }, { - "remarks": "Bypass LAN IP", + "remarks": "Bypass LAN domain name", "outboundTag": "direct", - "ip": [ - "geoip:private" + "domain": [ + "geosite:private" ] }, { @@ -31,4 +31,4 @@ "port": "0-65535", "outboundTag": "proxy" } -] \ No newline at end of file +] diff --git a/app/src/main/assets/custom_routing_white b/app/src/main/assets/custom_routing_white index 3cb8ea73..ccd331f2 100644 --- a/app/src/main/assets/custom_routing_white +++ b/app/src/main/assets/custom_routing_white @@ -8,7 +8,7 @@ ] }, { - "remarks": "Block udp443", + "remarks": "Block udp 443", "outboundTag": "block", "port": "443", "network": "udp" @@ -21,17 +21,17 @@ ] }, { - "remarks": "Bypass LAN domain name", + "remarks": "Bypass LAN IP", "outboundTag": "direct", - "domain": [ - "geosite:private" + "ip": [ + "geoip:private" ] }, { - "remarks": "Bypass LAN IP", + "remarks": "Bypass LAN domain name", "outboundTag": "direct", - "ip": [ - "geoip:private" + "domain": [ + "geosite:private" ] }, { @@ -78,4 +78,4 @@ "port": "0-65535", "outboundTag": "proxy" } -] \ No newline at end of file +] diff --git a/app/src/main/kotlin/com/neko/v2ray/AppConfig.kt b/app/src/main/kotlin/com/neko/v2ray/AppConfig.kt index 7b9f3f95..8cbe9c4c 100644 --- a/app/src/main/kotlin/com/neko/v2ray/AppConfig.kt +++ b/app/src/main/kotlin/com/neko/v2ray/AppConfig.kt @@ -108,7 +108,10 @@ object AppConfig { const val DNS_PROXY = "1.1.1.1" const val DNS_DIRECT = "223.5.5.5" const val DNS_VPN = "1.1.1.1" - + const val GEOSITE_PRIVATE = "geosite:private" + const val GEOSITE_CN = "geosite:cn" + const val GEOIP_PRIVATE = "geoip:private" + const val GEOIP_CN = "geoip:cn" /** Ports and addresses for various services. */ const val PORT_LOCAL_DNS = "10853" diff --git a/app/src/main/kotlin/com/neko/v2ray/util/SettingsManager.kt b/app/src/main/kotlin/com/neko/v2ray/util/SettingsManager.kt index 1a2348d5..615b5dd7 100644 --- a/app/src/main/kotlin/com/neko/v2ray/util/SettingsManager.kt +++ b/app/src/main/kotlin/com/neko/v2ray/util/SettingsManager.kt @@ -2,7 +2,10 @@ package com.neko.v2ray.util import android.content.Context import android.text.TextUtils + import com.neko.v2ray.AppConfig +import com.neko.v2ray.AppConfig.GEOIP_PRIVATE +import com.neko.v2ray.AppConfig.GEOSITE_PRIVATE import com.neko.v2ray.dto.RulesetItem import com.neko.v2ray.dto.ServerConfig import com.neko.v2ray.util.MmkvManager.decodeProfileConfig @@ -108,7 +111,11 @@ object SettingsManager { fun routingRulesetsBypassLan(): Boolean { val rulesetItems = MmkvManager.decodeRoutingRulesets() - val exist = rulesetItems?.any { it.enabled && it.domain?.contains(":private") == true } + val exist = rulesetItems?.any { + it.enabled + && (it.domain?.contains(GEOSITE_PRIVATE) == true + || it.ip?.contains(GEOIP_PRIVATE) == true) + } return exist == true } diff --git a/app/src/main/kotlin/com/neko/v2ray/util/V2rayConfigUtil.kt b/app/src/main/kotlin/com/neko/v2ray/util/V2rayConfigUtil.kt index c7993449..dd6bbebb 100644 --- a/app/src/main/kotlin/com/neko/v2ray/util/V2rayConfigUtil.kt +++ b/app/src/main/kotlin/com/neko/v2ray/util/V2rayConfigUtil.kt @@ -3,9 +3,13 @@ package com.neko.v2ray.util import android.content.Context import android.text.TextUtils import android.util.Log + import com.neko.v2ray.AppConfig import com.neko.v2ray.AppConfig.ANG_PACKAGE +import com.neko.v2ray.AppConfig.GEOIP_CN +import com.neko.v2ray.AppConfig.GEOSITE_CN import com.neko.v2ray.AppConfig.LOOPBACK +import com.neko.v2ray.AppConfig.GEOSITE_PRIVATE import com.neko.v2ray.AppConfig.PROTOCOL_FREEDOM import com.neko.v2ray.AppConfig.TAG_BLOCKED import com.neko.v2ray.AppConfig.TAG_DIRECT @@ -221,7 +225,9 @@ object V2rayConfigUtil { rulesetItems?.forEach { key -> if (key != null && key.enabled && key.outboundTag == tag && !key.domain.isNullOrEmpty()) { key.domain?.forEach { - if (it.startsWith("geosite:") || it.startsWith("domain:")) { + if (it != GEOSITE_PRIVATE + && (it.startsWith("geosite:") || it.startsWith("domain:")) + ) { domain.add(it) } } @@ -234,7 +240,7 @@ object V2rayConfigUtil { private fun customLocalDns(v2rayConfig: V2rayConfig): Boolean { try { if (settingsStorage?.decodeBool(AppConfig.PREF_FAKE_DNS_ENABLED) == true) { - val geositeCn = arrayListOf("geosite:cn") + val geositeCn = arrayListOf(GEOSITE_CN) val proxyDomain = userRule2Domain(TAG_PROXY) val directDomain = userRule2Domain(TAG_DIRECT) // fakedns with all domains to make it always top priority @@ -325,8 +331,8 @@ object V2rayConfigUtil { // domestic DNS val domesticDns = Utils.getDomesticDnsServers() val directDomain = userRule2Domain(TAG_DIRECT) - val isCnRoutingMode = directDomain.contains("geosite:cn") - val geoipCn = arrayListOf("geoip:cn") + val isCnRoutingMode = directDomain.contains(GEOSITE_CN) + val geoipCn = arrayListOf(GEOIP_CN) if (directDomain.size > 0) { servers.add( V2rayConfig.DnsBean.ServersBean(