From 59070cfd32323f38a3e5b6f38a7365f971afe851 Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Thu, 11 Apr 2013 13:48:16 -0700 Subject: [PATCH] Add new route.hasGateway() api Fixes issues brought in by change to isHostRoute. isHostRoute was technically correct, but the callers really wanted hasNextHop behavior. bug:8597268 Change-Id: I360761ccfa98b2ba34642f717a78fa71ec1bae4f --- core/java/android/net/RouteInfo.java | 7 +++++++ services/java/com/android/server/ConnectivityService.java | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/java/android/net/RouteInfo.java b/core/java/android/net/RouteInfo.java index cc3c5f7cff..1d051dde49 100644 --- a/core/java/android/net/RouteInfo.java +++ b/core/java/android/net/RouteInfo.java @@ -60,6 +60,7 @@ public class RouteInfo implements Parcelable { private final boolean mIsDefault; private final boolean mIsHost; + private final boolean mHasGateway; /** * Constructs a RouteInfo object. @@ -97,6 +98,8 @@ public class RouteInfo implements Parcelable { gateway = Inet6Address.ANY; } } + mHasGateway = (!gateway.isAnyLocalAddress()); + mDestination = new LinkAddress(NetworkUtils.getNetworkPart(destination.getAddress(), destination.getNetworkPrefixLength()), destination.getNetworkPrefixLength()); mGateway = gateway; @@ -171,6 +174,10 @@ public class RouteInfo implements Parcelable { return mIsHost; } + public boolean hasGateway() { + return mHasGateway; + } + public String toString() { String val = ""; if (mDestination != null) val = mDestination.toString(); diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index f320562d8a..01625dd1eb 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -1470,8 +1470,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { loge("Error modifying route - no interface name"); return false; } - - if (r.isHostRoute() == false) { + if (r.hasGateway()) { RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getAllRoutes(), r.getGateway()); if (bestRoute != null) { if (bestRoute.getGateway().equals(r.getGateway())) {