Refine RootSession.Transaction.iptables
This commit is contained in:
@@ -14,7 +14,6 @@ import be.mygod.vpnhotspot.util.RootSession
|
||||
import be.mygod.vpnhotspot.util.computeIfAbsentCompat
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import timber.log.Timber
|
||||
import java.lang.RuntimeException
|
||||
import java.net.*
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
|
||||
@@ -61,10 +60,15 @@ class Routing(val downstream: String, ownerAddress: InterfaceAddress? = null) :
|
||||
}
|
||||
}
|
||||
|
||||
private fun RootSession.Transaction.iptables(command: String, revert: String) {
|
||||
val result = execQuiet(command, revert)
|
||||
val message = RootSession.checkOutput(command, result, err = false)
|
||||
if (result.err.isNotEmpty()) Timber.i(message) // busy wait message
|
||||
}
|
||||
private fun RootSession.Transaction.iptablesAdd(content: String, table: String = "filter") =
|
||||
exec("$IPTABLES -t $table -A $content", "$IPTABLES -t $table -D $content", true)
|
||||
iptables("$IPTABLES -t $table -A $content", "$IPTABLES -t $table -D $content")
|
||||
private fun RootSession.Transaction.iptablesInsert(content: String, table: String = "filter") =
|
||||
exec("$IPTABLES -t $table -I $content", "$IPTABLES -t $table -D $content", true)
|
||||
iptables("$IPTABLES -t $table -I $content", "$IPTABLES -t $table -D $content")
|
||||
}
|
||||
|
||||
class InterfaceNotFoundException : SocketException() {
|
||||
|
||||
@@ -67,7 +67,7 @@ object TrafficRecorder {
|
||||
loop@ for (line in RootSession.use {
|
||||
val command = "$IPTABLES -nvx -L vpnhotspot_fwd"
|
||||
val result = it.execQuiet(command)
|
||||
val message = it.checkOutput(command, result, false, false)
|
||||
val message = RootSession.checkOutput(command, result, false, false)
|
||||
if (result.err.isNotEmpty()) Timber.i(message)
|
||||
result.out.drop(2)
|
||||
}) {
|
||||
|
||||
@@ -49,7 +49,7 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
||||
var target: NetworkBlock? = null
|
||||
val command = "cat $CONF_PATH_TREBLE || cat $CONF_PATH_LEGACY"
|
||||
val shell = it.execQuiet(command)
|
||||
it.checkOutput(command, shell, false, false)
|
||||
RootSession.checkOutput(command, shell, false, false)
|
||||
val parser = Parser(shell.out)
|
||||
try {
|
||||
val bssid = group.owner.deviceAddress ?: ownerAddress
|
||||
|
||||
Reference in New Issue
Block a user