Always specify an interface for host routes.

Change-Id: I05b4d87e7d7e8237c6f4a70f1fedae00f416f581
This commit is contained in:
Lorenzo Colitti
2013-03-08 12:30:44 -08:00
parent 73b9785a15
commit 7a43b0f7cf
3 changed files with 23 additions and 16 deletions

View File

@@ -117,17 +117,17 @@ public class RouteInfo implements Parcelable {
this(host, null, null); this(host, null, null);
} }
public static RouteInfo makeHostRoute(InetAddress host) { public static RouteInfo makeHostRoute(InetAddress host, String iface) {
return makeHostRoute(host, null); 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 == null) return null;
if (host instanceof Inet4Address) { if (host instanceof Inet4Address) {
return new RouteInfo(new LinkAddress(host, 32), gateway); return new RouteInfo(new LinkAddress(host, 32), gateway, iface);
} else { } else {
return new RouteInfo(new LinkAddress(host, 128), gateway); return new RouteInfo(new LinkAddress(host, 128), gateway, iface);
} }
} }

View File

@@ -1430,17 +1430,18 @@ public class ConnectivityService extends IConnectivityManager.Stub {
private boolean modifyRouteToAddress(LinkProperties lp, InetAddress addr, boolean doAdd, private boolean modifyRouteToAddress(LinkProperties lp, InetAddress addr, boolean doAdd,
boolean toDefaultTable) { boolean toDefaultTable) {
String iface = lp.getInterfaceName();
RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getRoutes(), addr); RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getRoutes(), addr);
if (bestRoute == null) { if (bestRoute == null) {
bestRoute = RouteInfo.makeHostRoute(addr); bestRoute = RouteInfo.makeHostRoute(addr, iface);
} else { } else {
if (bestRoute.getGateway().equals(addr)) { if (bestRoute.getGateway().equals(addr)) {
// if there is no better route, add the implied hostroute for our gateway // if there is no better route, add the implied hostroute for our gateway
bestRoute = RouteInfo.makeHostRoute(addr); bestRoute = RouteInfo.makeHostRoute(addr, iface);
} else { } else {
// if we will connect to this through another route, add a direct route // if we will connect to this through another route, add a direct route
// to it's gateway // 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); return modifyRoute(lp.getInterfaceName(), lp, bestRoute, 0, doAdd, toDefaultTable);
@@ -1463,11 +1464,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
if (bestRoute != null) { if (bestRoute != null) {
if (bestRoute.getGateway().equals(r.getGateway())) { if (bestRoute.getGateway().equals(r.getGateway())) {
// if there is no better route, add the implied hostroute for our gateway // 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 { } else {
// if we will connect to our gateway through another route, add a direct // if we will connect to our gateway through another route, add a direct
// route to it's gateway // 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); modifyRoute(ifaceName, lp, bestRoute, cycleCount+1, doAdd, toDefaultTable);
} }

View File

@@ -62,13 +62,17 @@ public class ConnectivityServiceTest extends AndroidTestCase {
private static final String MOBILE_IFACE = "rmnet3"; private static final String MOBILE_IFACE = "rmnet3";
private static final String WIFI_IFACE = "wlan6"; 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_V4 = RouteInfo.makeHostRoute(parse("10.0.0.33"),
private static final RouteInfo MOBILE_ROUTE_V6 = RouteInfo.makeHostRoute(parse("fd00::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( private static final RouteInfo WIFI_ROUTE_V4 = RouteInfo.makeHostRoute(parse("192.168.0.66"),
parse("192.168.0.66"), parse("192.168.0.1")); parse("192.168.0.1"),
private static final RouteInfo WIFI_ROUTE_V6 = RouteInfo.makeHostRoute( WIFI_IFACE);
parse("fd00::66"), parse("fd00::")); private static final RouteInfo WIFI_ROUTE_V6 = RouteInfo.makeHostRoute(parse("fd00::66"),
parse("fd00::"),
WIFI_IFACE);
private INetworkManagementService mNetManager; private INetworkManagementService mNetManager;
private INetworkStatsService mStatsService; private INetworkStatsService mStatsService;