Fix netd mode on Android 6 with repeater

This commit is contained in:
Mygod
2019-02-17 12:58:22 +08:00
parent 0be1116121
commit 3933e9bf64

View File

@@ -115,15 +115,16 @@ class Routing(private val caller: Any, private val downstream: String) : IpNeigh
// by the time stopScript is called, table entry for upstream may already get removed // by the time stopScript is called, table entry for upstream may already get removed
"ip rule del from all iif $downstream priority $priority") "ip rule del from all iif $downstream priority $priority")
} }
fun simpleMasquerade() {
// note: specifying -i wouldn't work for POSTROUTING
iptablesAdd(if (upstream == null) "vpnhotspot_masquerade -s $hostSubnet -j MASQUERADE" else
"vpnhotspot_masquerade -s $hostSubnet -o $upstream -j MASQUERADE", "nat")
}
when (masqueradeMode) { when (masqueradeMode) {
MasqueradeMode.None -> { } // nothing to be done here MasqueradeMode.None -> { } // nothing to be done here
// note: specifying -i wouldn't work for POSTROUTING MasqueradeMode.Simple -> simpleMasquerade()
MasqueradeMode.Simple -> { // fallback is only needed for repeater on API 23
iptablesAdd(if (upstream == null) "vpnhotspot_masquerade -s $hostSubnet -j MASQUERADE" else MasqueradeMode.Netd -> if (upstream == null) simpleMasquerade() else {
"vpnhotspot_masquerade -s $hostSubnet -o $upstream -j MASQUERADE", "nat")
}
MasqueradeMode.Netd -> {
check(upstream != null)
/** /**
* 0 means that there are no interface addresses coming after, which is unused anyway. * 0 means that there are no interface addresses coming after, which is unused anyway.
* *