Suppress expected ip errors
This commit is contained in:
@@ -34,11 +34,7 @@ object DhcpWorkaround : SharedPreferences.OnSharedPreferenceChangeListener {
|
|||||||
try {
|
try {
|
||||||
it.exec("ip rule $action iif lo uidrange 0-0 lookup local_network priority 11000")
|
it.exec("ip rule $action iif lo uidrange 0-0 lookup local_network priority 11000")
|
||||||
} catch (e: RoutingCommands.UnexpectedOutputException) {
|
} catch (e: RoutingCommands.UnexpectedOutputException) {
|
||||||
if (e.result.out.isEmpty() && (e.result.exit == 2 || e.result.exit == 254) && if (enabled) {
|
if (Routing.shouldSuppressIpError(e)) return@use
|
||||||
e.result.err == "RTNETLINK answers: File exists\n"
|
|
||||||
} else {
|
|
||||||
e.result.err == "RTNETLINK answers: No such file or directory\n"
|
|
||||||
}) return@use
|
|
||||||
Timber.w(IOException("Failed to tweak dhcp workaround rule", e))
|
Timber.w(IOException("Failed to tweak dhcp workaround rule", e))
|
||||||
SmartSnackbar.make(e).show()
|
SmartSnackbar.make(e).show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,11 +91,23 @@ class Routing(private val caller: Any, private val downstream: String,
|
|||||||
result.check(listOf(command), !result.out.endsWith(suffix))
|
result.check(listOf(command), !result.out.endsWith(suffix))
|
||||||
if (result.out.length > suffix.length) Timber.i(result.message(listOf(command), true))
|
if (result.out.length > suffix.length) Timber.i(result.message(listOf(command), true))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun shouldSuppressIpError(e: RoutingCommands.UnexpectedOutputException, isAdd: Boolean = true) =
|
||||||
|
e.result.out.isEmpty() && (e.result.exit == 2 || e.result.exit == 254) && e.result.err == if (isAdd) {
|
||||||
|
"RTNETLINK answers: File exists\n"
|
||||||
|
} else {
|
||||||
|
"RTNETLINK answers: No such file or directory\n"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun RootSession.Transaction.ipRule(add: String, priority: Int, rule: String = "", del: String = add) =
|
private fun RootSession.Transaction.ipRule(add: String, priority: Int, rule: String = "", del: String = add) {
|
||||||
|
try {
|
||||||
exec("ip rule add $rule iif $downstream $add priority $priority",
|
exec("ip rule add $rule iif $downstream $add priority $priority",
|
||||||
"ip rule del $rule iif $downstream $del priority $priority")
|
"ip rule del $rule iif $downstream $del priority $priority")
|
||||||
|
} catch (e: RoutingCommands.UnexpectedOutputException) {
|
||||||
|
if (!shouldSuppressIpError(e)) throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
private fun RootSession.Transaction.ipRuleLookup(upstream: String, priority: Int, rule: String = "") =
|
private fun RootSession.Transaction.ipRuleLookup(upstream: String, priority: Int, rule: String = "") =
|
||||||
// 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
|
||||||
ipRule("lookup $upstream", priority, rule, "")
|
ipRule("lookup $upstream", priority, rule, "")
|
||||||
|
|||||||
Reference in New Issue
Block a user