Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f210bd0 authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Fail fast if somebody is adding default routes

bug:2655011
Change-Id: I25da940e024825bc6e1d1ac5fe7b0d951609c1c1
parent 555fddb0
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -2306,6 +2306,20 @@ public class ConnectivityService extends IConnectivityManager.Stub {

        boolean routesChanged = (routeDiff.removed.size() != 0 || routeDiff.added.size() != 0);

        // look for a radio-added default route (v4-only for now TODO)
        RouteInfo[] routes = new RouteInfo[0];
        try {
            routes = mNetd.getRoutes(newLp.getInterfaceName());
        } catch (Exception e) {}

        for (RouteInfo route : routes) {
            if (route.isDefaultRoute() && route.getGateway() instanceof Inet4Address &&
                    mAddedRoutes.contains(route) == false) {
                throw new IllegalStateException("Unexpected default route found for interface "
                        + newLp.getInterfaceName());
            }
        }

        for (RouteInfo r : routeDiff.removed) {
            if (isLinkDefault || ! r.isDefaultRoute()) {
                removeRoute(curLp, r, TO_DEFAULT_TABLE);
+2 −2
Original line number Diff line number Diff line
@@ -711,7 +711,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
                        InetAddress gatewayAddr =
                                NetworkUtils.intToInetAddress((int)Long.parseLong(gate, 16));

                        RouteInfo route = new RouteInfo(linkAddress, gatewayAddr);
                        RouteInfo route = new RouteInfo(linkAddress, gatewayAddr, iface);
                        routes.add(route);
                    } catch (Exception e) {
                        Log.e(TAG, "Error parsing route " + s + " : " + e);
@@ -743,7 +743,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub

                        InetAddress gateAddr = NetworkUtils.hexToInet6Address(gate);

                        RouteInfo route = new RouteInfo(linkAddress, gateAddr);
                        RouteInfo route = new RouteInfo(linkAddress, gateAddr, iface);
                        routes.add(route);
                    } catch (Exception e) {
                        Log.e(TAG, "Error parsing route " + s + " : " + e);