Fix route range
This commit is contained in:
@@ -8,6 +8,7 @@ import android.os.Build
|
|||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import io.nekohasekai.libbox.TunOptions
|
import io.nekohasekai.libbox.TunOptions
|
||||||
import io.nekohasekai.sfa.database.Settings
|
import io.nekohasekai.sfa.database.Settings
|
||||||
|
import io.nekohasekai.sfa.ktx.toIpPrefix
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -61,42 +62,64 @@ class VPNService : VpnService(), PlatformInterfaceWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val inet4Address = options.inet4Address
|
val inet4Address = options.inet4Address
|
||||||
if (inet4Address.hasNext()) {
|
while (inet4Address.hasNext()) {
|
||||||
while (inet4Address.hasNext()) {
|
val address = inet4Address.next()
|
||||||
val address = inet4Address.next()
|
builder.addAddress(address.address(), address.prefix())
|
||||||
builder.addAddress(address.address, address.prefix)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val inet6Address = options.inet6Address
|
val inet6Address = options.inet6Address
|
||||||
if (inet6Address.hasNext()) {
|
while (inet6Address.hasNext()) {
|
||||||
while (inet6Address.hasNext()) {
|
val address = inet6Address.next()
|
||||||
val address = inet6Address.next()
|
builder.addAddress(address.address(), address.prefix())
|
||||||
builder.addAddress(address.address, address.prefix)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.autoRoute) {
|
if (options.autoRoute) {
|
||||||
builder.addDnsServer(options.dnsServerAddress)
|
builder.addDnsServer(options.dnsServerAddress)
|
||||||
|
|
||||||
val inet4RouteAddress = options.inet4RouteAddress
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
if (inet4RouteAddress.hasNext()) {
|
val inet4RouteAddress = options.inet4RouteAddress
|
||||||
while (inet4RouteAddress.hasNext()) {
|
if (inet4RouteAddress.hasNext()) {
|
||||||
val address = inet4RouteAddress.next()
|
while (inet4RouteAddress.hasNext()) {
|
||||||
builder.addRoute(address.address, address.prefix)
|
builder.addRoute(inet4RouteAddress.next().toIpPrefix())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
builder.addRoute("0.0.0.0", 0)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
builder.addRoute("0.0.0.0", 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
val inet6RouteAddress = options.inet6RouteAddress
|
val inet6RouteAddress = options.inet6RouteAddress
|
||||||
if (inet6RouteAddress.hasNext()) {
|
if (inet6RouteAddress.hasNext()) {
|
||||||
while (inet6RouteAddress.hasNext()) {
|
while (inet6RouteAddress.hasNext()) {
|
||||||
val address = inet6RouteAddress.next()
|
builder.addRoute(inet6RouteAddress.next().toIpPrefix())
|
||||||
builder.addRoute(address.address, address.prefix)
|
}
|
||||||
|
} else {
|
||||||
|
builder.addRoute("::", 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val inet4RouteExcludeAddress = options.inet4RouteExcludeAddress
|
||||||
|
while (inet4RouteExcludeAddress.hasNext()) {
|
||||||
|
builder.excludeRoute(inet4RouteExcludeAddress.next().toIpPrefix())
|
||||||
|
}
|
||||||
|
|
||||||
|
val inet6RouteExcludeAddress = options.inet6RouteExcludeAddress
|
||||||
|
while (inet6RouteExcludeAddress.hasNext()) {
|
||||||
|
builder.excludeRoute(inet6RouteExcludeAddress.next().toIpPrefix())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
builder.addRoute("::", 0)
|
val inet4RouteAddress = options.inet4RouteRange
|
||||||
|
if (inet4RouteAddress.hasNext()) {
|
||||||
|
while (inet4RouteAddress.hasNext()) {
|
||||||
|
val address = inet4RouteAddress.next()
|
||||||
|
builder.addRoute(address.address(), address.prefix())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val inet6RouteAddress = options.inet6RouteRange
|
||||||
|
if (inet6RouteAddress.hasNext()) {
|
||||||
|
while (inet6RouteAddress.hasNext()) {
|
||||||
|
val address = inet6RouteAddress.next()
|
||||||
|
builder.addRoute(address.address(), address.prefix())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.perAppProxyEnabled) {
|
if (Settings.perAppProxyEnabled) {
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package io.nekohasekai.sfa.ktx
|
package io.nekohasekai.sfa.ktx
|
||||||
|
|
||||||
|
import android.net.IpPrefix
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
import io.nekohasekai.libbox.RoutePrefix
|
||||||
import io.nekohasekai.libbox.StringIterator
|
import io.nekohasekai.libbox.StringIterator
|
||||||
|
import java.net.InetAddress
|
||||||
|
|
||||||
fun Iterable<String>.toStringIterator(): StringIterator {
|
fun Iterable<String>.toStringIterator(): StringIterator {
|
||||||
return object : StringIterator {
|
return object : StringIterator {
|
||||||
@@ -22,4 +27,7 @@ fun StringIterator.toList(): List<String> {
|
|||||||
add(next())
|
add(next())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||||
|
fun RoutePrefix.toIpPrefix() = IpPrefix(InetAddress.getByName(address()), prefix())
|
||||||
Reference in New Issue
Block a user