From 3933e9bf649a4cd04f8b51aa40f8285614936d66 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 17 Feb 2019 12:58:22 +0800 Subject: [PATCH] Fix netd mode on Android 6 with repeater --- .../main/java/be/mygod/vpnhotspot/net/Routing.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 7b5ba78d..7f2b9dac 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -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 "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) { MasqueradeMode.None -> { } // nothing to be done here - // note: specifying -i wouldn't work for POSTROUTING - MasqueradeMode.Simple -> { - iptablesAdd(if (upstream == null) "vpnhotspot_masquerade -s $hostSubnet -j MASQUERADE" else - "vpnhotspot_masquerade -s $hostSubnet -o $upstream -j MASQUERADE", "nat") - } - MasqueradeMode.Netd -> { - check(upstream != null) + MasqueradeMode.Simple -> simpleMasquerade() + // fallback is only needed for repeater on API 23 + MasqueradeMode.Netd -> if (upstream == null) simpleMasquerade() else { /** * 0 means that there are no interface addresses coming after, which is unused anyway. *