Experimental support for VPN tethering over multiple interfaces

This commit is contained in:
Mygod
2018-01-13 23:15:10 +08:00
parent 9486941fc6
commit 6f43369ca1
2 changed files with 6 additions and 6 deletions

View File

@@ -11,10 +11,10 @@ class Routing(private val upstream: String, val downstream: String, ownerAddress
companion object { companion object {
fun clean() = noisySu( fun clean() = noisySu(
"iptables -w 1 -t nat -F PREROUTING", "iptables -w 1 -t nat -F PREROUTING",
"while iptables -w 1 -D FORWARD -j vpnhotspot_fwd; do done", "quiet while iptables -w 1 -D FORWARD -j vpnhotspot_fwd; do done",
"iptables -w 1 -F vpnhotspot_fwd", "iptables -w 1 -F vpnhotspot_fwd",
"iptables -w 1 -X vpnhotspot_fwd", "iptables -w 1 -X vpnhotspot_fwd",
"while ip rule del priority 17900; do done") "quiet while ip rule del priority 17900; do done")
} }
class InterfaceNotFoundException : IOException() { class InterfaceNotFoundException : IOException() {
@@ -46,12 +46,12 @@ class Routing(private val upstream: String, val downstream: String, ownerAddress
} }
fun forward(): Routing { fun forward(): Routing {
startScript.add("iptables -w 1 -N vpnhotspot_fwd") startScript.add("quiet iptables -w 1 -N vpnhotspot_fwd 2>/dev/null")
startScript.add("iptables -w 1 -A vpnhotspot_fwd -i $upstream -o $downstream -m state --state ESTABLISHED,RELATED -j ACCEPT") startScript.add("iptables -w 1 -A vpnhotspot_fwd -i $upstream -o $downstream -m state --state ESTABLISHED,RELATED -j ACCEPT")
startScript.add("iptables -w 1 -A vpnhotspot_fwd -i $downstream -o $upstream -j ACCEPT") startScript.add("iptables -w 1 -A vpnhotspot_fwd -i $downstream -o $upstream -j ACCEPT")
startScript.add("iptables -w 1 -I FORWARD -j vpnhotspot_fwd") startScript.add("iptables -w 1 -I FORWARD -j vpnhotspot_fwd")
stopScript.addFirst("iptables -w 1 -X vpnhotspot_fwd") stopScript.addFirst("iptables -w 1 -D vpnhotspot_fwd -i $upstream -o $downstream -m state --state ESTABLISHED,RELATED -j ACCEPT")
stopScript.addFirst("iptables -w 1 -F vpnhotspot_fwd") stopScript.addFirst("iptables -w 1 -D vpnhotspot_fwd -i $downstream -o $upstream -j ACCEPT")
stopScript.addFirst("iptables -w 1 -D FORWARD -j vpnhotspot_fwd") stopScript.addFirst("iptables -w 1 -D FORWARD -j vpnhotspot_fwd")
return this return this
} }

View File

@@ -46,7 +46,7 @@ fun loggerSu(command: String): String? = try {
} }
fun noisySu(commands: Iterable<String>): Boolean { fun noisySu(commands: Iterable<String>): Boolean {
var out = loggerSu("""function noisy() { "$@" || echo "$@" exited with $?; } var out = loggerSu("""function noisy() { "$@" || echo "$@" exited with $?; }
${commands.joinToString("\n") { if (it.startsWith("while ")) it else "noisy $it" }} ${commands.joinToString("\n") { if (it.startsWith("quiet ")) it.substring(6) else "noisy $it" }}
echo $NOISYSU_SUFFIX""") echo $NOISYSU_SUFFIX""")
val result = out == NOISYSU_SUFFIX val result = out == NOISYSU_SUFFIX
out = out?.removeSuffix(NOISYSU_SUFFIX) out = out?.removeSuffix(NOISYSU_SUFFIX)