Fix file exists error when enabling multiple interfaces with DHCP workaround
This commit is contained in:
@@ -11,6 +11,7 @@ import be.mygod.vpnhotspot.widget.SmartSnackbar
|
|||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.lang.RuntimeException
|
import java.lang.RuntimeException
|
||||||
import java.net.*
|
import java.net.*
|
||||||
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A transaction wrapper that helps set up routing environment.
|
* A transaction wrapper that helps set up routing environment.
|
||||||
@@ -28,6 +29,8 @@ class Routing(val downstream: String, ownerAddress: InterfaceAddress? = null) {
|
|||||||
private const val RULE_PRIORITY_UPSTREAM = 17800
|
private const val RULE_PRIORITY_UPSTREAM = 17800
|
||||||
private const val RULE_PRIORITY_UPSTREAM_FALLBACK = 17900
|
private const val RULE_PRIORITY_UPSTREAM_FALLBACK = 17900
|
||||||
|
|
||||||
|
private val dhcpWorkaroundCounter = AtomicLong()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* -w <seconds> is not supported on 7.1-.
|
* -w <seconds> is not supported on 7.1-.
|
||||||
* Fortunately there also isn't a time limit for starting a foreground service back in 7.1-.
|
* Fortunately there also isn't a time limit for starting a foreground service back in 7.1-.
|
||||||
@@ -165,8 +168,13 @@ class Routing(val downstream: String, ownerAddress: InterfaceAddress? = null) {
|
|||||||
*
|
*
|
||||||
* Source: https://android.googlesource.com/platform/system/netd/+/b9baf26/server/RouteController.cpp#57
|
* Source: https://android.googlesource.com/platform/system/netd/+/b9baf26/server/RouteController.cpp#57
|
||||||
*/
|
*/
|
||||||
fun dhcpWorkaround() = transaction.exec("ip rule add iif lo uidrange 0-0 lookup local_network priority 11000",
|
fun dhcpWorkaround() {
|
||||||
"ip rule del iif lo uidrange 0-0 lookup local_network priority 11000")
|
// workaround for adding multiple exact same rules
|
||||||
|
// if somebody decides to do this 1000 times to break this, god bless you
|
||||||
|
val priority = 11000 + dhcpWorkaroundCounter.getAndAdd(1) % 1000
|
||||||
|
transaction.exec("ip rule add iif lo uidrange 0-0 lookup local_network priority $priority",
|
||||||
|
"ip rule del iif lo uidrange 0-0 lookup local_network priority $priority")
|
||||||
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
FallbackUpstreamMonitor.unregisterCallback(fallbackUpstream)
|
FallbackUpstreamMonitor.unregisterCallback(fallbackUpstream)
|
||||||
|
|||||||
Reference in New Issue
Block a user