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

Commit f5600618 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Fix IP address cleanup on network disconnect

We used to bring down the interface on network disconnect
which would in turn clean up all the IP addresses.

The interface bringup/shutdown is now handled by wpa_supplicant.
Add netd interface for clearing all IP addresses

Bug: 4676254
Change-Id: I7e24c0ab2e4a412b8d61e9c33ce028966913aaf6
parent ad4c9ed7
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -58,6 +58,11 @@ interface INetworkManagementService
     */
    void setInterfaceConfig(String iface, in InterfaceConfiguration cfg);

    /**
     * Clear all IP addresses on the specified interface
     */
    void clearInterfaceAddresses(String iface);

    /**
     * Retrieves the network routes currently configured on the specified
     * interface
+12 −0
Original line number Diff line number Diff line
@@ -311,6 +311,18 @@ class NetworkManagementService extends INetworkManagementService.Stub {
        }
    }

    /* TODO: This is right now a IPv4 only function. Works for wifi which loses its
       IPv6 addresses on interface down, but we need to do full clean up here */
    public void clearInterfaceAddresses(String iface) throws IllegalStateException {
         String cmd = String.format("interface clearaddrs %s", iface);
        try {
            mConnector.doCommand(cmd);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException(
                    "Unable to communicate with native daemon to interface clearallips - " + e);
        }
    }

    public void addRoute(String interfaceName, RouteInfo route) {
        modifyRoute(interfaceName, ADD, route);
    }
+10 −9
Original line number Diff line number Diff line
@@ -1028,9 +1028,6 @@ public class WifiStateMachine extends StateMachine {
        boolean wifiTethered = false;
        boolean wifiAvailable = false;

        IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
        INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);

        if (mCm == null) {
            mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        }
@@ -1043,14 +1040,14 @@ public class WifiStateMachine extends StateMachine {

                    InterfaceConfiguration ifcg = null;
                    try {
                        ifcg = service.getInterfaceConfig(intf);
                        ifcg = nwService.getInterfaceConfig(intf);
                        if (ifcg != null) {
                            /* IP/netmask: 192.168.43.1/255.255.255.0 */
                            ifcg.addr = new LinkAddress(NetworkUtils.numericToInetAddress(
                                    "192.168.43.1"), 24);
                            ifcg.interfaceFlags = "[up]";

                            service.setInterfaceConfig(intf, ifcg);
                            nwService.setInterfaceConfig(intf, ifcg);
                        }
                    } catch (Exception e) {
                        Log.e(TAG, "Error configuring interface " + intf + ", :" + e);
@@ -1451,7 +1448,7 @@ public class WifiStateMachine extends StateMachine {
     * using the interface, stopping DHCP & disabling interface
     */
    private void handleNetworkDisconnect() {
        Log.d(TAG, "Reset connections and stopping DHCP");
        Log.d(TAG, "Stopping DHCP and clearing IP");

        /*
         * stop DHCP
@@ -1462,6 +1459,12 @@ public class WifiStateMachine extends StateMachine {
            mDhcpStateMachine = null;
        }

        try {
            nwService.clearInterfaceAddresses(mInterfaceName);
        } catch (Exception e) {
            Log.e(TAG, "Failed to clear IP addresses on disconnect" + e);
        }

        /* Reset data structures */
        mWifiInfo.setInetAddress(null);
        mWifiInfo.setBSSID(null);
@@ -2657,13 +2660,11 @@ public class WifiStateMachine extends StateMachine {
            } else {
                DhcpInfoInternal dhcpInfoInternal = WifiConfigStore.getIpConfiguration(
                        mLastNetworkId);
                IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
                INetworkManagementService netd = INetworkManagementService.Stub.asInterface(b);
                InterfaceConfiguration ifcg = new InterfaceConfiguration();
                ifcg.addr = dhcpInfoInternal.makeLinkAddress();
                ifcg.interfaceFlags = "[up]";
                try {
                    netd.setInterfaceConfig(mInterfaceName, ifcg);
                    nwService.setInterfaceConfig(mInterfaceName, ifcg);
                    Log.v(TAG, "Static IP configuration succeeded");
                    sendMessage(CMD_STATIC_IP_SUCCESS, dhcpInfoInternal);
                } catch (RemoteException re) {