From 7a43b0f7cf87c269e7d69a5d521ec627ce5811a0 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 8 Mar 2013 12:30:44 -0800 Subject: [PATCH] Always specify an interface for host routes. Change-Id: I05b4d87e7d7e8237c6f4a70f1fedae00f416f581 --- core/java/android/net/RouteInfo.java | 10 +++++----- .../com/android/server/ConnectivityService.java | 13 ++++++++----- .../android/server/ConnectivityServiceTest.java | 16 ++++++++++------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/core/java/android/net/RouteInfo.java b/core/java/android/net/RouteInfo.java index 46b6cbb557..9a3fcb0974 100644 --- a/core/java/android/net/RouteInfo.java +++ b/core/java/android/net/RouteInfo.java @@ -117,17 +117,17 @@ public class RouteInfo implements Parcelable { this(host, null, null); } - public static RouteInfo makeHostRoute(InetAddress host) { - return makeHostRoute(host, null); + public static RouteInfo makeHostRoute(InetAddress host, String iface) { + return makeHostRoute(host, null, iface); } - public static RouteInfo makeHostRoute(InetAddress host, InetAddress gateway) { + public static RouteInfo makeHostRoute(InetAddress host, InetAddress gateway, String iface) { if (host == null) return null; if (host instanceof Inet4Address) { - return new RouteInfo(new LinkAddress(host, 32), gateway); + return new RouteInfo(new LinkAddress(host, 32), gateway, iface); } else { - return new RouteInfo(new LinkAddress(host, 128), gateway); + return new RouteInfo(new LinkAddress(host, 128), gateway, iface); } } diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 3257d2cb3b..027f0f39a8 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -1430,17 +1430,18 @@ public class ConnectivityService extends IConnectivityManager.Stub { private boolean modifyRouteToAddress(LinkProperties lp, InetAddress addr, boolean doAdd, boolean toDefaultTable) { + String iface = lp.getInterfaceName(); RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getRoutes(), addr); if (bestRoute == null) { - bestRoute = RouteInfo.makeHostRoute(addr); + bestRoute = RouteInfo.makeHostRoute(addr, iface); } else { if (bestRoute.getGateway().equals(addr)) { // if there is no better route, add the implied hostroute for our gateway - bestRoute = RouteInfo.makeHostRoute(addr); + bestRoute = RouteInfo.makeHostRoute(addr, iface); } else { // if we will connect to this through another route, add a direct route // to it's gateway - bestRoute = RouteInfo.makeHostRoute(addr, bestRoute.getGateway()); + bestRoute = RouteInfo.makeHostRoute(addr, bestRoute.getGateway(), iface); } } return modifyRoute(lp.getInterfaceName(), lp, bestRoute, 0, doAdd, toDefaultTable); @@ -1463,11 +1464,13 @@ public class ConnectivityService extends IConnectivityManager.Stub { if (bestRoute != null) { if (bestRoute.getGateway().equals(r.getGateway())) { // if there is no better route, add the implied hostroute for our gateway - bestRoute = RouteInfo.makeHostRoute(r.getGateway()); + bestRoute = RouteInfo.makeHostRoute(r.getGateway(), ifaceName); } else { // if we will connect to our gateway through another route, add a direct // route to it's gateway - bestRoute = RouteInfo.makeHostRoute(r.getGateway(), bestRoute.getGateway()); + bestRoute = RouteInfo.makeHostRoute(r.getGateway(), + bestRoute.getGateway(), + ifaceName); } modifyRoute(ifaceName, lp, bestRoute, cycleCount+1, doAdd, toDefaultTable); } diff --git a/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java b/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java index 4ae013bad1..f955f4fd57 100644 --- a/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java @@ -62,13 +62,17 @@ public class ConnectivityServiceTest extends AndroidTestCase { private static final String MOBILE_IFACE = "rmnet3"; private static final String WIFI_IFACE = "wlan6"; - private static final RouteInfo MOBILE_ROUTE_V4 = RouteInfo.makeHostRoute(parse("10.0.0.33")); - private static final RouteInfo MOBILE_ROUTE_V6 = RouteInfo.makeHostRoute(parse("fd00::33")); + private static final RouteInfo MOBILE_ROUTE_V4 = RouteInfo.makeHostRoute(parse("10.0.0.33"), + MOBILE_IFACE); + private static final RouteInfo MOBILE_ROUTE_V6 = RouteInfo.makeHostRoute(parse("fd00::33"), + MOBILE_IFACE); - private static final RouteInfo WIFI_ROUTE_V4 = RouteInfo.makeHostRoute( - parse("192.168.0.66"), parse("192.168.0.1")); - private static final RouteInfo WIFI_ROUTE_V6 = RouteInfo.makeHostRoute( - parse("fd00::66"), parse("fd00::")); + private static final RouteInfo WIFI_ROUTE_V4 = RouteInfo.makeHostRoute(parse("192.168.0.66"), + parse("192.168.0.1"), + WIFI_IFACE); + private static final RouteInfo WIFI_ROUTE_V6 = RouteInfo.makeHostRoute(parse("fd00::66"), + parse("fd00::"), + WIFI_IFACE); private INetworkManagementService mNetManager; private INetworkStatsService mStatsService;