mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2026-05-09 18:11:26 +08:00
Refactor: migrate to tun2socket
This commit is contained in:
@@ -207,8 +207,8 @@ class TunService : VpnService(), CoroutineScope by CoroutineScope(Dispatchers.De
|
||||
TunModule.TunDevice(
|
||||
fd = establish()?.detachFd()
|
||||
?: throw NullPointerException("Establish VPN rejected by system"),
|
||||
mtu = TUN_MTU,
|
||||
blocking = blocking.joinToString(";"),
|
||||
gateway = TUN_GATEWAY,
|
||||
portal = TUN_PORTAL,
|
||||
dns = if (store.dnsHijacking) NET_ANY else TUN_DNS,
|
||||
)
|
||||
}
|
||||
@@ -220,7 +220,8 @@ class TunService : VpnService(), CoroutineScope by CoroutineScope(Dispatchers.De
|
||||
private const val TUN_MTU = 9000
|
||||
private const val TUN_SUBNET_PREFIX = 30
|
||||
private const val TUN_GATEWAY = "172.19.0.1"
|
||||
private const val TUN_DNS = "172.19.0.2"
|
||||
private const val TUN_PORTAL = "172.19.0.2"
|
||||
private const val TUN_DNS = TUN_PORTAL
|
||||
private const val NET_ANY = "0.0.0.0"
|
||||
private const val NET_SUBNET_LOOPBACK = "127.0.0.0/8"
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ import java.security.SecureRandom
|
||||
class TunModule(private val vpn: VpnService) : Module<Unit>(vpn) {
|
||||
data class TunDevice(
|
||||
val fd: Int,
|
||||
val mtu: Int,
|
||||
val blocking: String,
|
||||
val gateway: String,
|
||||
val portal: String,
|
||||
val dns: String,
|
||||
)
|
||||
|
||||
@@ -56,9 +56,9 @@ class TunModule(private val vpn: VpnService) : Module<Unit>(vpn) {
|
||||
fun attach(device: TunDevice) {
|
||||
Clash.startTun(
|
||||
fd = device.fd,
|
||||
mtu = device.mtu,
|
||||
gateway = device.gateway,
|
||||
portal = device.portal,
|
||||
dns = device.dns,
|
||||
blocking = device.blocking,
|
||||
markSocket = vpn::protect,
|
||||
querySocketUid = this::queryUid
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user