From d5824b5d2bfe8c2cd598a576597447bf755e6758 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Tue, 20 Jan 2015 15:53:02 +0900 Subject: [PATCH] Support connecting to networks with misconfigured subnet masks. In K and earlier, we would connect to a network where the gateway was not covered by the subnet mask of the IP address. This is an invalid configuration, but it used to work, and other OSes appear to accept it too, so support it. Bug: 19067207 (cherry picked from commit d2a878d730785495c9584430b1d20666801c4a4a) Change-Id: I80088f291466dbd5a47f360dcc1620acee5cf57e --- core/java/android/net/StaticIpConfiguration.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/core/java/android/net/StaticIpConfiguration.java b/core/java/android/net/StaticIpConfiguration.java index 5a273cfaa6..8bf8f2ebaf 100644 --- a/core/java/android/net/StaticIpConfiguration.java +++ b/core/java/android/net/StaticIpConfiguration.java @@ -76,15 +76,22 @@ public class StaticIpConfiguration implements Parcelable { /** * Returns the network routes specified by this object. Will typically include a - * directly-connected route for the IP address's local subnet and a default route. + * directly-connected route for the IP address's local subnet and a default route. If the + * default gateway is not covered by the directly-connected route, it will also contain a host + * route to the gateway as well. This configuration is arguably invalid, but it used to work + * in K and earlier, and other OSes appear to accept it. */ public List getRoutes(String iface) { - List routes = new ArrayList(2); + List routes = new ArrayList(3); if (ipAddress != null) { - routes.add(new RouteInfo(ipAddress, null, iface)); + RouteInfo connectedRoute = new RouteInfo(ipAddress, null, iface); + routes.add(connectedRoute); + if (gateway != null && !connectedRoute.matches(gateway)) { + routes.add(RouteInfo.makeHostRoute(gateway, iface)); + } } if (gateway != null) { - routes.add(new RouteInfo((LinkAddress) null, gateway, iface)); + routes.add(new RouteInfo((IpPrefix) null, gateway, iface)); } return routes; }