Only apply VPN isolation if it's fully routed

VPN is considered fully routed if both IPv4 and IPv6 have
either a default route or a prohibit route.

Bug: 145332510
Test: atest FrameworksNetTests
Change-Id: I59cf48552bca98092d1212e3d718fd420add5458
This commit is contained in:
Rubin Xu
2020-03-30 14:37:05 +01:00
parent 3402ee64ed
commit ab8cf306ea
6 changed files with 146 additions and 1 deletions

View File

@@ -1073,6 +1073,21 @@ public final class LinkProperties implements Parcelable {
return false;
}
/**
* Returns true if this link has an IPv4 unreachable default route.
*
* @return {@code true} if there is an IPv4 unreachable default route, {@code false} otherwise.
* @hide
*/
public boolean hasIpv4UnreachableDefaultRoute() {
for (RouteInfo r : mRoutes) {
if (r.isIPv4UnreachableDefault()) {
return true;
}
}
return false;
}
/**
* For backward compatibility.
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
@@ -1101,6 +1116,21 @@ public final class LinkProperties implements Parcelable {
return false;
}
/**
* Returns true if this link has an IPv6 unreachable default route.
*
* @return {@code true} if there is an IPv6 unreachable default route, {@code false} otherwise.
* @hide
*/
public boolean hasIpv6UnreachableDefaultRoute() {
for (RouteInfo r : mRoutes) {
if (r.isIPv6UnreachableDefault()) {
return true;
}
}
return false;
}
/**
* For backward compatibility.
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely

View File

@@ -425,6 +425,16 @@ public final class RouteInfo implements Parcelable {
return mType == RTN_UNICAST && mDestination.getPrefixLength() == 0;
}
/**
* Indicates if this route is an unreachable default route.
*
* @return {@code true} if it's an unreachable route with prefix length of 0.
* @hide
*/
private boolean isUnreachableDefaultRoute() {
return mType == RTN_UNREACHABLE && mDestination.getPrefixLength() == 0;
}
/**
* Indicates if this route is an IPv4 default route.
* @hide
@@ -433,6 +443,14 @@ public final class RouteInfo implements Parcelable {
return isDefaultRoute() && mDestination.getAddress() instanceof Inet4Address;
}
/**
* Indicates if this route is an IPv4 unreachable default route.
* @hide
*/
public boolean isIPv4UnreachableDefault() {
return isUnreachableDefaultRoute() && mDestination.getAddress() instanceof Inet4Address;
}
/**
* Indicates if this route is an IPv6 default route.
* @hide
@@ -441,6 +459,14 @@ public final class RouteInfo implements Parcelable {
return isDefaultRoute() && mDestination.getAddress() instanceof Inet6Address;
}
/**
* Indicates if this route is an IPv6 unreachable default route.
* @hide
*/
public boolean isIPv6UnreachableDefault() {
return isUnreachableDefaultRoute() && mDestination.getAddress() instanceof Inet6Address;
}
/**
* Indicates if this route is a host route (ie, matches only a single host address).
*