update tun2socket & remove ipv6 for VpnService
This commit is contained in:
15 files changed
+49
-62
No files matched your search
@@ -17,11 +17,8 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
|
||||
// from https://github.com/shadowsocks/shadowsocks-android/blob/master/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
|
||||
private const val VPN_MTU = 65535
|
||||
private const val PRIVATE_VLAN4_SUBNET = 30
|
||||
private const val PRIVATE_VLAN6_SUBNET = 126
|
||||
private const val PRIVATE_VLAN4_CLIENT = "172.31.255.253"
|
||||
private const val PRIVATE_VLAN6_CLIENT = "fdfe:dcba:9876::1"
|
||||
private const val PRIVATE_VLAN4_MIRROR = "172.31.255.254"
|
||||
private const val PRIVATE_VLAN6_MIRROR = "fdfe:dcba:9876::2"
|
||||
private const val PRIVATE_VLAN_DNS = "198.18.0.1"
|
||||
}
|
||||
|
||||
@@ -125,36 +122,17 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
|
||||
get() = Builder()
|
||||
override val mtu: Int
|
||||
get() = VPN_MTU
|
||||
override val gateway4: String
|
||||
override val gateway: String
|
||||
get() = "$PRIVATE_VLAN4_CLIENT/$PRIVATE_VLAN4_SUBNET"
|
||||
override val mirror4: String
|
||||
override val mirror: String
|
||||
get() = PRIVATE_VLAN4_MIRROR
|
||||
override val route4: List<String>
|
||||
override val route: List<String>
|
||||
get() {
|
||||
return if (settings.get(ServiceSettings.BYPASS_PRIVATE_NETWORK))
|
||||
resources.getStringArray(R.array.bypass_private_route).toList()
|
||||
else
|
||||
listOf("0.0.0.0/0")
|
||||
}
|
||||
override val gateway6: String?
|
||||
get() {
|
||||
return if (settings.get(ServiceSettings.IPV6_SUPPORT))
|
||||
"$PRIVATE_VLAN6_CLIENT/$PRIVATE_VLAN6_SUBNET"
|
||||
else null
|
||||
}
|
||||
override val mirror6: String?
|
||||
get() {
|
||||
return if (settings.get(ServiceSettings.IPV6_SUPPORT))
|
||||
PRIVATE_VLAN6_MIRROR
|
||||
else null
|
||||
}
|
||||
override val route6: List<String>?
|
||||
get() {
|
||||
// from https://github.com/shadowsocks/shadowsocks-android/commit/cc840c9fddb3f4f6677005de18f1fcb387b84064#diff-e089fe63dcb3674c0a1e459a95508e3e
|
||||
return if (settings.get(ServiceSettings.IPV6_SUPPORT))
|
||||
listOf("2000::/3")
|
||||
else null
|
||||
}
|
||||
override val dnsAddress: String
|
||||
get() = PRIVATE_VLAN_DNS
|
||||
override val dnsHijacking: Boolean
|
||||
|
||||
@@ -14,12 +14,9 @@ class TunModule(private val service: VpnService) : Module() {
|
||||
interface Configure {
|
||||
val builder: VpnService.Builder
|
||||
val mtu: Int
|
||||
val gateway4: String
|
||||
val mirror4: String
|
||||
val route4: List<String>
|
||||
val gateway6: String?
|
||||
val mirror6: String?
|
||||
val route6: List<String>?
|
||||
val gateway: String
|
||||
val mirror: String
|
||||
val route: List<String>
|
||||
val dnsAddress: String
|
||||
val dnsHijacking: Boolean
|
||||
val allowApplications: List<String>
|
||||
@@ -40,16 +37,10 @@ class TunModule(private val service: VpnService) : Module() {
|
||||
|
||||
val builder = c.builder
|
||||
|
||||
parseCIDR(c.gateway4).let {
|
||||
parseCIDR(c.gateway).let {
|
||||
builder.addAddress(it.ip, it.prefix)
|
||||
}
|
||||
c.route4.map { parseCIDR(it) }.forEach {
|
||||
builder.addRoute(it.ip, it.prefix)
|
||||
}
|
||||
c.gateway6?.let { parseCIDR(it) }?.let {
|
||||
builder.addAddress(it.ip, it.prefix)
|
||||
}
|
||||
c.route6?.map { parseCIDR(it) }?.forEach {
|
||||
c.route.map { parseCIDR(it) }.forEach {
|
||||
builder.addRoute(it.ip, it.prefix)
|
||||
}
|
||||
c.allowApplications.forEach {
|
||||
@@ -82,8 +73,8 @@ class TunModule(private val service: VpnService) : Module() {
|
||||
Clash.startTunDevice(
|
||||
fd.detachFd(),
|
||||
c.mtu,
|
||||
c.gateway4,
|
||||
c.mirror4,
|
||||
c.gateway,
|
||||
c.mirror,
|
||||
IPV4_ANY,
|
||||
service::protect,
|
||||
service::stopSelf
|
||||
@@ -92,8 +83,8 @@ class TunModule(private val service: VpnService) : Module() {
|
||||
Clash.startTunDevice(
|
||||
fd.detachFd(),
|
||||
c.mtu,
|
||||
c.gateway4,
|
||||
c.mirror4,
|
||||
c.gateway,
|
||||
c.mirror,
|
||||
c.dnsAddress,
|
||||
service::protect,
|
||||
service::stopSelf
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.github.kr328.clash.service.settings
|
||||
|
||||
import android.content.SharedPreferences
|
||||
|
||||
abstract class BaseSettings(private val preferences: SharedPreferences) {
|
||||
interface Entry<T> {
|
||||
fun get(preferences: SharedPreferences): T
|
||||
fun put(editor: SharedPreferences.Editor, value: T)
|
||||
}
|
||||
|
||||
class StringEntry(private val key: String, private val defaultValue: String) : Entry<String> {
|
||||
override fun get(preferences: SharedPreferences): String {
|
||||
return preferences.getString(key, defaultValue)!!
|
||||
}
|
||||
|
||||
override fun put(editor: SharedPreferences.Editor, value: String) {
|
||||
editor.putString(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
class BooleanEntry(private val key: String, private val defaultValue: Boolean) :
|
||||
Entry<Boolean> {
|
||||
override fun get(preferences: SharedPreferences): Boolean {
|
||||
return preferences.getBoolean(key, defaultValue)
|
||||
}
|
||||
|
||||
override fun put(editor: SharedPreferences.Editor, value: Boolean) {
|
||||
editor.putBoolean(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
class StringSetEntry(private val key: String, private val defaultValue: Set<String>) :
|
||||
Entry<Set<String>> {
|
||||
override fun get(preferences: SharedPreferences): Set<String> {
|
||||
return preferences.getStringSet(key, defaultValue)!!
|
||||
}
|
||||
|
||||
override fun put(editor: SharedPreferences.Editor, value: Set<String>) {
|
||||
editor.putStringSet(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
class Editor(private val editor: SharedPreferences.Editor) {
|
||||
fun <T> put(entry: Entry<T>, value: T) {
|
||||
entry.put(editor, value)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> get(entry: Entry<T>): T {
|
||||
return entry.get(preferences)
|
||||
}
|
||||
|
||||
fun commit(async: Boolean = true, block: Editor.() -> Unit) {
|
||||
val editor = preferences.edit()
|
||||
|
||||
Editor(editor).apply(block)
|
||||
|
||||
if (async)
|
||||
editor.apply()
|
||||
else
|
||||
editor.commit()
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.github.kr328.clash.service.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.github.kr328.clash.common.settings.BaseSettings
|
||||
import com.github.kr328.clash.service.ServiceSettingsProvider
|
||||
|
||||
class ServiceSettings(preference: SharedPreferences) :
|
||||
@@ -17,8 +18,6 @@ class ServiceSettings(preference: SharedPreferences) :
|
||||
|
||||
val LANGUAGE =
|
||||
StringEntry("language", "")
|
||||
val IPV6_SUPPORT =
|
||||
BooleanEntry("ipv6_support", false)
|
||||
val BYPASS_PRIVATE_NETWORK =
|
||||
BooleanEntry("bypass_private_network", true)
|
||||
val ACCESS_CONTROL_MODE =
|
||||
|
||||
Reference in new issue
Block a user