support set tun stack

This commit is contained in:
wwqgtxx
2024-09-11 19:41:19 +08:00
parent bb2c5283f8
commit 3cc77c7c95
10 changed files with 46 additions and 8 deletions

View File

@@ -218,6 +218,7 @@ class TunService : VpnService(), CoroutineScope by CoroutineScope(Dispatchers.De
TunModule.TunDevice(
fd = establish()?.detachFd()
?: throw NullPointerException("Establish VPN rejected by system"),
stack = store.tunStackMode,
gateway = "$TUN_GATEWAY/$TUN_SUBNET_PREFIX" + if (store.allowIpv6) ",$TUN_GATEWAY6/$TUN_SUBNET_PREFIX6" else "",
portal = TUN_PORTAL + if (store.allowIpv6) ",$TUN_PORTAL6" else "",
dns = if (store.dnsHijacking) NET_ANY else (TUN_DNS + if (store.allowIpv6) ",$TUN_DNS6" else ""),

View File

@@ -15,6 +15,7 @@ import java.security.SecureRandom
class TunModule(private val vpn: VpnService) : Module<Unit>(vpn) {
data class TunDevice(
val fd: Int,
var stack: String,
val gateway: String,
val portal: String,
val dns: String,
@@ -56,6 +57,7 @@ class TunModule(private val vpn: VpnService) : Module<Unit>(vpn) {
fun attach(device: TunDevice) {
Clash.startTun(
fd = device.fd,
stack = device.stack,
gateway = device.gateway,
portal = device.portal,
dns = device.dns,

View File

@@ -56,6 +56,11 @@ class ServiceStore(context: Context) {
defaultValue = false
)
var tunStackMode by store.string(
key = "tun_stack_mode",
defaultValue = "system"
)
var dynamicNotification by store.boolean(
key = "dynamic_notification",
defaultValue = true