Fix: refactor tun implement

This commit is contained in:
Kr328
2021-05-26 15:33:59 +08:00
parent ac35f2a5f4
commit 5e34221a09
11 changed files with 253 additions and 235 deletions

View File

@@ -217,6 +217,7 @@ class TunService : VpnService(), CoroutineScope by CoroutineScope(Dispatchers.De
fd = establish()?.detachFd()
?: throw NullPointerException("Establish VPN rejected by system"),
mtu = TUN_MTU,
gateway = "$TUN_GATEWAY/$TUN_SUBNET_PREFIX",
dns = if (store.dnsHijacking) NET_ANY else TUN_DNS,
)
}

View File

@@ -16,7 +16,8 @@ class TunModule(private val vpn: VpnService) : Module<Unit>(vpn) {
data class TunDevice(
val fd: Int,
val mtu: Int,
val dns: String
val gateway: String,
val dns: String,
)
private val connectivity = service.getSystemService<ConnectivityManager>()!!
@@ -56,6 +57,7 @@ class TunModule(private val vpn: VpnService) : Module<Unit>(vpn) {
Clash.startTun(
fd = device.fd,
mtu = device.mtu,
gateway = device.gateway,
dns = device.dns,
markSocket = vpn::protect,
querySocketUid = this::queryUid