Clean up legacy fallback rules
This commit is contained in:
@@ -150,35 +150,24 @@ class Routing(private val caller: Any, private val downstream: String) : IpNeigh
|
|||||||
private val upstreams = HashSet<String>()
|
private val upstreams = HashSet<String>()
|
||||||
private class InterfaceGoneException(upstream: String) : IOException("Interface $upstream not found")
|
private class InterfaceGoneException(upstream: String) : IOException("Interface $upstream not found")
|
||||||
private open inner class Upstream(val priority: Int) : UpstreamMonitor.Callback {
|
private open inner class Upstream(val priority: Int) : UpstreamMonitor.Callback {
|
||||||
/**
|
|
||||||
* The only case when upstream is null is on API 23- and we are using system default rules.
|
|
||||||
*/
|
|
||||||
inner class Subrouting(priority: Int, val upstream: String) {
|
inner class Subrouting(priority: Int, val upstream: String) {
|
||||||
val ifindex = if (upstream.isEmpty()) 0 else Os.if_nametoindex(upstream).also {
|
val ifindex = Os.if_nametoindex(upstream).also {
|
||||||
if (it <= 0) throw InterfaceGoneException(upstream)
|
if (it <= 0) throw InterfaceGoneException(upstream)
|
||||||
}
|
}
|
||||||
val transaction = RootSession.beginTransaction().safeguard {
|
val transaction = RootSession.beginTransaction().safeguard {
|
||||||
if (upstream.isEmpty()) {
|
ipRuleLookup(ifindex, priority)
|
||||||
ipRule("goto $RULE_PRIORITY_TETHERING", priority) // skip unreachable rule
|
|
||||||
} else ipRuleLookup(ifindex, priority)
|
|
||||||
when (masqueradeMode) {
|
when (masqueradeMode) {
|
||||||
MasqueradeMode.None -> { } // nothing to be done here
|
MasqueradeMode.None -> { } // nothing to be done here
|
||||||
MasqueradeMode.Simple -> {
|
// note: specifying -i wouldn't work for POSTROUTING
|
||||||
// note: specifying -i wouldn't work for POSTROUTING
|
MasqueradeMode.Simple -> iptablesAdd(
|
||||||
iptablesAdd(if (upstream.isEmpty()) {
|
"vpnhotspot_masquerade -s $hostSubnet -o $upstream -j MASQUERADE", "nat")
|
||||||
"vpnhotspot_masquerade -s $hostSubnet -j MASQUERADE"
|
/**
|
||||||
} else "vpnhotspot_masquerade -s $hostSubnet -o $upstream -j MASQUERADE", "nat")
|
* 0 means that there are no interface addresses coming after, which is unused anyway.
|
||||||
}
|
*
|
||||||
MasqueradeMode.Netd -> {
|
* https://android.googlesource.com/platform/frameworks/base/+/android-5.0.0_r1/services/core/java/com/android/server/NetworkManagementService.java#1251
|
||||||
check(upstream.isNotEmpty()) // fallback is only needed for repeater on API 23 < 28
|
* https://android.googlesource.com/platform/system/netd/+/android-5.0.0_r1/server/CommandListener.cpp#638
|
||||||
/**
|
*/
|
||||||
* 0 means that there are no interface addresses coming after, which is unused anyway.
|
MasqueradeMode.Netd -> ndc("Nat", "ndc nat enable $downstream $upstream 0")
|
||||||
*
|
|
||||||
* https://android.googlesource.com/platform/frameworks/base/+/android-5.0.0_r1/services/core/java/com/android/server/NetworkManagementService.java#1251
|
|
||||||
* https://android.googlesource.com/platform/system/netd/+/android-5.0.0_r1/server/CommandListener.cpp#638
|
|
||||||
*/
|
|
||||||
ndc("Nat", "ndc nat enable $downstream $upstream 0")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user