update tun2socket & remove ipv6 for VpnService
This commit is contained in:
15 files changed
+49
-62
No files matched your search
@@ -1,5 +1,5 @@
|
||||
package com.github.kr328.clash.pipeline
|
||||
|
||||
import com.github.kr328.clash.service.settings.BaseSettings
|
||||
import com.github.kr328.clash.common.settings.BaseSettings
|
||||
|
||||
data class Pipeline<T>(val input: T, val settings: BaseSettings)
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.github.kr328.clash.preference
|
||||
|
||||
import android.content.Context
|
||||
import com.github.kr328.clash.service.settings.BaseSettings
|
||||
import com.github.kr328.clash.common.settings.BaseSettings
|
||||
|
||||
class UiSettings(context: Context) :
|
||||
BaseSettings(context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)) {
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.github.kr328.clash.service.util.intent
|
||||
class NetworkFragment : BaseSettingFragment() {
|
||||
companion object {
|
||||
private const val KEY_ENABLE_VPN_SERVICE = "enable_vpn_service"
|
||||
private const val KEY_IPV6 = "ipv6"
|
||||
private const val BYPASS_PRIVATE_NETWORK = "bypass_private_network"
|
||||
private const val KEY_DNS_HIJACKING = "dns_hijacking"
|
||||
private const val KEY_DNS_OVERRIDE = "dns_override"
|
||||
@@ -34,7 +33,6 @@ class NetworkFragment : BaseSettingFragment() {
|
||||
override fun onCreateDataStore(): SettingsDataStore {
|
||||
return SettingsDataStore().apply {
|
||||
on(KEY_ENABLE_VPN_SERVICE, UiSettings.ENABLE_VPN.asSource(ui))
|
||||
on(KEY_IPV6, ServiceSettings.IPV6_SUPPORT.asSource(service))
|
||||
on(BYPASS_PRIVATE_NETWORK, ServiceSettings.BYPASS_PRIVATE_NETWORK.asSource(service))
|
||||
on(KEY_DNS_HIJACKING, ServiceSettings.DNS_HIJACKING.asSource(service))
|
||||
on(KEY_DNS_OVERRIDE, ServiceSettings.OVERRIDE_DNS.asSource(service))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.github.kr328.clash.settings
|
||||
|
||||
import com.github.kr328.clash.service.settings.BaseSettings
|
||||
import com.github.kr328.clash.common.settings.BaseSettings
|
||||
import moe.shizuku.preference.PreferenceDataStore
|
||||
|
||||
class SettingsDataStore : PreferenceDataStore() {
|
||||
|
||||
@@ -7,11 +7,6 @@
|
||||
android:summary="@string/routing_via_vpn_service"
|
||||
android:defaultValue="true" />
|
||||
<PreferenceCategory android:title="@string/vpn_service" android:dependency="enable_vpn_service">
|
||||
<SwitchPreference
|
||||
android:key="ipv6"
|
||||
android:title="@string/ipv6"
|
||||
android:summary="@string/enable_ipv6"
|
||||
android:defaultValue="false"/>
|
||||
<SwitchPreference
|
||||
android:key="bypass_private_network"
|
||||
android:title="@string/bypass_private_network"
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:4.0.0-beta03")
|
||||
classpath("com.android.tools.build:gradle:4.0.0-beta04")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
|
||||
classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,4 +1,4 @@
|
||||
package com.github.kr328.clash.service.settings
|
||||
package com.github.kr328.clash.common.settings
|
||||
|
||||
import android.content.SharedPreferences
|
||||
|
||||
@@ -8,7 +8,8 @@ abstract class BaseSettings(private val preferences: SharedPreferences) {
|
||||
fun put(editor: SharedPreferences.Editor, value: T)
|
||||
}
|
||||
|
||||
class StringEntry(private val key: String, private val defaultValue: String) : Entry<String> {
|
||||
class StringEntry(private val key: String, private val defaultValue: String) :
|
||||
Entry<String> {
|
||||
override fun get(preferences: SharedPreferences): String {
|
||||
return preferences.getString(key, defaultValue)!!
|
||||
}
|
||||
@@ -4,7 +4,7 @@ go 1.13
|
||||
|
||||
require (
|
||||
github.com/Dreamacro/clash v0.0.0 // local
|
||||
github.com/kr328/tun2socket v0.0.0-20200329184923-76cc473668aa
|
||||
github.com/kr328/tun2socket v0.0.0-20200408030108-2c2effd1201d
|
||||
github.com/miekg/dns v1.1.29
|
||||
)
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr328/tun2socket v0.0.0-20200329184923-76cc473668aa h1:WO6oDyis1HjzAYwv1Eu+wYmo6qzN8ph9ZllUpO3oQfE=
|
||||
github.com/kr328/tun2socket v0.0.0-20200329184923-76cc473668aa/go.mod h1:FWfSixjrLgtK+dHkDoN6lHMNhvER24gnjUZd/wt8Z9o=
|
||||
github.com/kr328/tun2socket v0.0.0-20200408030108-2c2effd1201d h1:+IU9AD+eA0tbMdl9TdxAqvbOWU8SnOQtbsPAMYqeXtU=
|
||||
github.com/kr328/tun2socket v0.0.0-20200408030108-2c2effd1201d/go.mod h1:FWfSixjrLgtK+dHkDoN6lHMNhvER24gnjUZd/wt8Z9o=
|
||||
github.com/miekg/dns v1.1.29 h1:xHBEhR+t5RzcFJjBLJlax2daXOrTYtr9z4WdKEfWFzg=
|
||||
github.com/miekg/dns v1.1.29/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||
github.com/oschwald/geoip2-golang v1.4.0 h1:5RlrjCgRyIGDz/mBmPfnAF4h8k0IAcRv9PvrpOfz+Ug=
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package tun
|
||||
|
||||
import "github.com/Dreamacro/clash/log"
|
||||
|
||||
type ClashLogger struct {}
|
||||
|
||||
func (c *ClashLogger) D(format string, args ...interface{}) {
|
||||
log.Debugln(format, args)
|
||||
}
|
||||
|
||||
func (c *ClashLogger) I(format string, args ...interface{}) {
|
||||
log.Infoln(format, args)
|
||||
}
|
||||
|
||||
func (c *ClashLogger) W(format string, args ...interface{}) {
|
||||
log.Warnln(format, args)
|
||||
}
|
||||
|
||||
func (c *ClashLogger) E(format string, args ...interface{}) {
|
||||
log.Errorln(format, args)
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ func StartTunDevice(fd, mtu int, gateway, mirror, dnsAddress string) error {
|
||||
|
||||
adapter = tun2socket.NewTun2Socket(file, mtu, gatewayIP, mirrorIP.To4())
|
||||
|
||||
adapter.SetLogger(&ClashLogger{})
|
||||
adapter.SetClosedHandler(func() {
|
||||
StopTunDevice()
|
||||
})
|
||||
adapter.SetAllocator(func(length int) []byte {
|
||||
if length <= maxUdpPacketSize {
|
||||
return udpPool.Get().([]byte)[:length]
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.github.kr328.clash.core.model.Traffic
|
||||
import com.github.kr328.clash.core.transact.DoneCallbackImpl
|
||||
import com.github.kr328.clash.core.transact.ProxyCollectionImpl
|
||||
import com.github.kr328.clash.core.transact.ProxyGroupCollectionImpl
|
||||
import com.github.kr328.clash.core.utils.Log
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
@@ -51,8 +50,6 @@ object Clash {
|
||||
onNewSocket: (Int) -> Boolean,
|
||||
onTunStop: () -> Unit
|
||||
) {
|
||||
Log.d("$gateway $mirror $dns")
|
||||
|
||||
Bridge.startTunDevice(fd.toLong(), mtu.toLong(), gateway, mirror, dns, object: TunCallback {
|
||||
override fun onCreateSocket(fd: Long) {
|
||||
onNewSocket(fd.toInt())
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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