OSDN Git Service

Support connecting to networks with misconfigured subnet masks.
authorLorenzo Colitti <lorenzo@google.com>
Tue, 20 Jan 2015 06:53:02 +0000 (15:53 +0900)
committerLorenzo Colitti <lorenzo@google.com>
Fri, 23 Jan 2015 12:10:34 +0000 (21:10 +0900)
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
Change-Id: I822e1d754b336691b675438eefa959a3d75fd07b

core/java/android/net/StaticIpConfiguration.java

index 598a503..365f2b6 100644 (file)
@@ -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<RouteInfo> getRoutes(String iface) {
-        List<RouteInfo> routes = new ArrayList<RouteInfo>(2);
+        List<RouteInfo> routes = new ArrayList<RouteInfo>(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;
     }