Merge branch 'master' into r
This commit is contained in:
@@ -129,6 +129,8 @@ class Routing(private val caller: Any, private val downstream: String,
|
||||
private val hostSubnet = "${hostAddress.address.hostAddress}/${hostAddress.networkPrefixLength}"
|
||||
private val transaction = RootSession.beginTransaction()
|
||||
|
||||
@Volatile
|
||||
private var stopped = false
|
||||
private var masqueradeMode = MasqueradeMode.None
|
||||
|
||||
private val upstreams = HashSet<String>()
|
||||
@@ -164,6 +166,7 @@ class Routing(private val caller: Any, private val downstream: String,
|
||||
var dns: List<InetAddress> = emptyList()
|
||||
|
||||
override fun onAvailable(ifname: String, properties: LinkProperties) = synchronized(this@Routing) {
|
||||
if (stopped) return
|
||||
val subrouting = subrouting
|
||||
when {
|
||||
subrouting != null -> check(subrouting.upstream == ifname) { "${subrouting.upstream} != $ifname" }
|
||||
@@ -181,6 +184,7 @@ class Routing(private val caller: Any, private val downstream: String,
|
||||
}
|
||||
|
||||
override fun onLost() = synchronized(this@Routing) {
|
||||
if (stopped) return
|
||||
val subrouting = subrouting ?: return
|
||||
// we could be removing fallback subrouting which no collision could ever happen, check before removing
|
||||
subrouting.upstream?.let { check(upstreams.remove(it)) }
|
||||
@@ -193,6 +197,7 @@ class Routing(private val caller: Any, private val downstream: String,
|
||||
private val fallbackUpstream = object : Upstream(RULE_PRIORITY_UPSTREAM_FALLBACK) {
|
||||
var fallbackInactive = true
|
||||
override fun onFallback() = synchronized(this@Routing) {
|
||||
if (stopped) return
|
||||
fallbackInactive = false
|
||||
check(subrouting == null)
|
||||
subrouting = try {
|
||||
@@ -231,6 +236,7 @@ class Routing(private val caller: Any, private val downstream: String,
|
||||
}
|
||||
private val clients = mutableMapOf<InetAddress, Client>()
|
||||
override fun onIpNeighbourAvailable(neighbours: Collection<IpNeighbour>) = synchronized(this) {
|
||||
if (stopped) return
|
||||
val toRemove = HashSet(clients.keys)
|
||||
for (neighbour in neighbours) {
|
||||
if (neighbour.dev != downstream || neighbour.ip !is Inet4Address ||
|
||||
@@ -328,9 +334,11 @@ class Routing(private val caller: Any, private val downstream: String,
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
stopped = true
|
||||
IpNeighbourMonitor.unregisterCallback(this)
|
||||
FallbackUpstreamMonitor.unregisterCallback(fallbackUpstream)
|
||||
UpstreamMonitor.unregisterCallback(upstream)
|
||||
Timber.i("Stopped routing for $downstream by $caller")
|
||||
}
|
||||
|
||||
fun commit() {
|
||||
@@ -345,7 +353,6 @@ class Routing(private val caller: Any, private val downstream: String,
|
||||
}
|
||||
fun revert() {
|
||||
stop()
|
||||
Timber.i("Stopped routing for $downstream by $caller")
|
||||
TrafficRecorder.update() // record stats before exiting to prevent stats losing
|
||||
synchronized(this) { clients.values.forEach { it.close() } }
|
||||
currentDns?.transaction?.revert()
|
||||
|
||||
@@ -70,7 +70,7 @@ abstract class IpMonitor : Runnable {
|
||||
}
|
||||
try {
|
||||
process.inputStream.bufferedReader().forEachLine {
|
||||
if (errorMatcher.matches(it)) {
|
||||
if (errorMatcher.containsMatchIn(it)) {
|
||||
Timber.w(it)
|
||||
process.destroy() // move on to next mode
|
||||
} else processLine(it)
|
||||
@@ -119,7 +119,7 @@ abstract class IpMonitor : Runnable {
|
||||
}
|
||||
process.inputStream.bufferedReader().useLines {
|
||||
processLines(it.map { line ->
|
||||
if (errorMatcher.matches(line)) throw IOException(line)
|
||||
if (errorMatcher.containsMatchIn(line)) throw IOException(line)
|
||||
line
|
||||
})
|
||||
}
|
||||
@@ -134,15 +134,17 @@ abstract class IpMonitor : Runnable {
|
||||
}
|
||||
try {
|
||||
val command = "ip $monitoredObject"
|
||||
RootSession.use {
|
||||
val result = it.execQuiet(command)
|
||||
RootSession.use { shell ->
|
||||
val result = shell.execQuiet(command)
|
||||
RootSession.checkOutput(command, result, false)
|
||||
if (result.out.any { errorMatcher.matches(it) }) throw IOException(result.out.joinToString("\n"))
|
||||
if (result.out.any { errorMatcher.containsMatchIn(it) }) {
|
||||
throw IOException(result.out.joinToString("\n"))
|
||||
}
|
||||
processLines(result.out.asSequence())
|
||||
}
|
||||
} catch (e: RuntimeException) {
|
||||
app.logEvent("ip_su_poll_failure")
|
||||
Timber.w(e)
|
||||
app.logEvent("ip_su_poll_failure") { param("cause", e.message.toString()) }
|
||||
Timber.d(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user