net: distinguish unreachable VPN routes from exclusions

Only RTN_THROW continues routing onto the physical LAN. RTN_UNICAST and RTN_UNREACHABLE do not, including for .local names and IPv6-only unreachable routes. Regression tests failed against the previous predicate and now pass.
This commit is contained in:
austinried
2026-11-15 00:14:48 +00:00
parent 0e1cede0f3
commit 78905dd587
2 changed files with 32 additions and 7 deletions
@@ -37,7 +37,7 @@ class LocalNetworkAccess(
vpnRoutes.mayFallThroughToLan(linkAddresses)
} else {
resolved.any { candidate ->
linkAddresses.any { it.contains(candidate) } && !vpnRoutes.routesThroughVpn(candidate)
linkAddresses.any { it.contains(candidate) } && vpnRoutes.fallsThroughToLan(candidate)
}
}
}
@@ -65,17 +65,17 @@ internal fun isLocalHostname(host: String): Boolean {
private fun LinkAddress.contains(address: InetAddress): Boolean = IpPrefix(this.address, prefixLength).contains(address)
@RequiresApi(37)
private fun List<RouteInfo>.routesThroughVpn(address: InetAddress): Boolean =
private fun List<RouteInfo>.fallsThroughToLan(address: InetAddress): Boolean =
filter { it.matches(address) }
.maxByOrNull { it.destination.prefixLength }
?.type == RouteInfo.RTN_UNICAST
?.let { it.type == RouteInfo.RTN_THROW } ?: true
@RequiresApi(37)
private fun List<RouteInfo>.mayFallThroughToLan(linkAddresses: List<LinkAddress>): Boolean =
any { route ->
route.type != RouteInfo.RTN_UNICAST &&
route.type == RouteInfo.RTN_THROW &&
linkAddresses.any { link -> route.matches(link.address) || link.contains(route.destination.address) }
} || linkAddresses.any { !routesThroughVpn(it.address) }
} || linkAddresses.any { fallsThroughToLan(it.address) }
private val NetworkCapabilities.isPhysicalLan: Boolean
get() =