Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
fix(Routing): Fix routing rules
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust authored and AnGgIt86 committed Oct 2, 2024
1 parent 77e8101 commit 2bb7653
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 30 deletions.
16 changes: 8 additions & 8 deletions app/src/main/assets/custom_routing_black
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
},
{
"remarks": "Block udp443",
"remarks": "Blocking udp 443",
"outboundTag": "block",
"port": "443",
"network": "udp"
Expand All @@ -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"
]
},
{
Expand Down Expand Up @@ -70,4 +70,4 @@
"port": "0-65535",
"outboundTag": "direct"
}
]
]
16 changes: 8 additions & 8 deletions app/src/main/assets/custom_routing_global
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"remarks": "Block udp443",
"remarks": "Block udp 443",
"outboundTag": "block",
"port": "443",
"network": "udp"
Expand All @@ -13,22 +13,22 @@
]
},
{
"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"
]
},
{
"remarks": "Final Agent",
"port": "0-65535",
"outboundTag": "proxy"
}
]
]
16 changes: 8 additions & 8 deletions app/src/main/assets/custom_routing_white
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
]
},
{
"remarks": "Block udp443",
"remarks": "Block udp 443",
"outboundTag": "block",
"port": "443",
"network": "udp"
Expand All @@ -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"
]
},
{
Expand Down Expand Up @@ -78,4 +78,4 @@
"port": "0-65535",
"outboundTag": "proxy"
}
]
]
5 changes: 4 additions & 1 deletion app/src/main/kotlin/com/neko/v2ray/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/kotlin/com/neko/v2ray/util/SettingsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
14 changes: 10 additions & 4 deletions app/src/main/kotlin/com/neko/v2ray/util/V2rayConfigUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2bb7653

Please sign in to comment.