diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt index 01ab5ed5..e8c2d823 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -11,6 +11,7 @@ import be.mygod.vpnhotspot.widget.SmartSnackbar import timber.log.Timber import java.lang.RuntimeException import java.net.* +import java.util.concurrent.atomic.AtomicLong /** * 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_FALLBACK = 17900 + private val dhcpWorkaroundCounter = AtomicLong() + /** * -w is not supported on 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 */ - fun dhcpWorkaround() = transaction.exec("ip rule add iif lo uidrange 0-0 lookup local_network priority 11000", - "ip rule del iif lo uidrange 0-0 lookup local_network priority 11000") + fun dhcpWorkaround() { + // 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() { FallbackUpstreamMonitor.unregisterCallback(fallbackUpstream)