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

Commit 5c11021f authored by Xiao Ma's avatar Xiao Ma
Browse files

Getting interface params in ClearingIpAddressState#enter.

In case of wifi might stop IpClient and then restart prov immediately
to avoid wifi disconnection especially when roaming happens, this
might cause getting interface params with incorrect interface mtu when
starting provisioning again before interface mtu hasn't been restored.

Moving getting interface params to ClearingIpAddressState#enter ensures
that interface parameters are fetched on the handler thread so they are
properly ordered with other events, such as restoring the interface MTU
on teardown.

Bug: 152169857
Test: atest NetworkStackIntegrationTests NetworkStackTests

Change-Id: I5e98d59488f24bcfdb673fcb2877e27d81432a13
parent 153ed4f4
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -772,14 +772,6 @@ public class IpClient extends StateMachine {
            return;
        }

        mInterfaceParams = mDependencies.getInterfaceParams(mInterfaceName);
        if (mInterfaceParams == null) {
            logError("Failed to find InterfaceParams for " + mInterfaceName);
            doImmediateProvisioningFailure(IpManagerEvent.ERROR_INTERFACE_NOT_FOUND);
            return;
        }

        mCallback.setNeighborDiscoveryOffload(true);
        sendMessage(CMD_START, new android.net.shared.ProvisioningConfiguration(req));
    }

@@ -1650,6 +1642,17 @@ public class IpClient extends StateMachine {
                // tethering or during an IpClient restart.
                stopAllIP();
            }

            // Ensure that interface parameters are fetched on the handler thread so they are
            // properly ordered with other events, such as restoring the interface MTU on teardown.
            mInterfaceParams = mDependencies.getInterfaceParams(mInterfaceName);
            if (mInterfaceParams == null) {
                logError("Failed to find InterfaceParams for " + mInterfaceName);
                doImmediateProvisioningFailure(IpManagerEvent.ERROR_INTERFACE_NOT_FOUND);
                transitionTo(mStoppedState);
                return;
            }
            mCallback.setNeighborDiscoveryOffload(true);
        }

        @Override
+34 −3
Original line number Diff line number Diff line
@@ -524,7 +524,6 @@ public class IpClientIntegrationTest {
        mDependencies.setHostnameConfiguration(isHostnameConfigurationEnabled, hostname);
        mIpc.setL2KeyAndGroupHint(TEST_L2KEY, TEST_GROUPHINT);
        mIpc.startProvisioning(builder.build());
        verify(mCb).setNeighborDiscoveryOffload(true);
        if (!isPreconnectionEnabled) {
            verify(mCb, timeout(TEST_TIMEOUT_MS)).setFallbackMulticastFilter(false);
        }
@@ -642,7 +641,6 @@ public class IpClientIntegrationTest {
                            ArgumentCaptor.forClass(LinkProperties.class);
                    verifyProvisioningSuccess(captor, Collections.singletonList(CLIENT_ADDR));
                }

                return packetList;
            }
        }
@@ -725,6 +723,12 @@ public class IpClientIntegrationTest {
            assertEquals(NetworkInterface.getByName(mIfaceName).getMTU(), mtu);
        }

        // Sometimes, IpClient receives an update with an empty LinkProperties during startup,
        // when the link-local address is deleted after interface bringup. Reset expectations
        // here to ensure that verifyAfterIpClientShutdown does not fail because it sees two
        // empty LinkProperties changes instead of one.
        reset(mCb);

        if (shouldRemoveTapInterface) removeTapInterface(mTapFd);
        try {
            mIpc.shutdown();
@@ -1081,10 +1085,37 @@ public class IpClientIntegrationTest {
                .build();

        mIpc.startProvisioning(config);
        verify(mCb).onProvisioningFailure(any());
        verify(mCb, timeout(TEST_TIMEOUT_MS)).onProvisioningFailure(any());
        verify(mCb, never()).setNeighborDiscoveryOffload(true);
    }

    @Test
    public void testRestoreInitialInterfaceMtu_stopIpClientAndRestart() throws Exception {
        long currentTime = System.currentTimeMillis();

        performDhcpHandshake(true /* isSuccessLease */, TEST_LEASE_DURATION_S,
                true /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */,
                TEST_MIN_MTU, false /* isDhcpIpConflictDetectEnabled */);
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_MIN_MTU);

        // Pretend that ConnectivityService set the MTU.
        mNetd.interfaceSetMtu(mIfaceName, TEST_MIN_MTU);
        assertEquals(NetworkInterface.getByName(mIfaceName).getMTU(), TEST_MIN_MTU);

        reset(mCb);
        reset(mIpMemoryStore);

        // Stop IpClient and then restart provisioning immediately.
        mIpc.stop();
        currentTime = System.currentTimeMillis();
        // Intend to set mtu option to 0, then verify that won't influence interface mtu restore.
        performDhcpHandshake(true /* isSuccessLease */, TEST_LEASE_DURATION_S,
                true /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */,
                0 /* mtu */, false /* isDhcpIpConflictDetectEnabled */);
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, 0 /* mtu */);
        assertEquals(NetworkInterface.getByName(mIfaceName).getMTU(), TEST_DEFAULT_MTU);
    }

    private boolean isRouterSolicitation(final byte[] packetBytes) {
        ByteBuffer packet = ByteBuffer.wrap(packetBytes);
        return packet.getShort(ETHER_TYPE_OFFSET) == (short) ETH_P_IPV6
+3 −3
Original line number Diff line number Diff line
@@ -221,7 +221,7 @@ public class IpClientTest {
        final IpClient ipc = new IpClient(mContext, TEST_IFNAME, mCb, mObserverRegistry,
                mNetworkStackServiceManager, mDependencies);
        ipc.startProvisioning(new ProvisioningConfiguration());
        verify(mCb, times(1)).onProvisioningFailure(any());
        verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).onProvisioningFailure(any());
        verify(mIpMemoryStore, never()).storeNetworkAttributes(any(), any(), any());
        ipc.shutdown();
    }
@@ -249,7 +249,7 @@ public class IpClientTest {
                .build();

        ipc.startProvisioning(config);
        verify(mCb, times(1)).setNeighborDiscoveryOffload(true);
        verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).setNeighborDiscoveryOffload(true);
        verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).setFallbackMulticastFilter(false);

        final LinkProperties lp = makeIPv6ProvisionedLinkProperties();
@@ -364,7 +364,7 @@ public class IpClientTest {
                .build();

        ipc.startProvisioning(config);
        verify(mCb, times(1)).setNeighborDiscoveryOffload(true);
        verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).setNeighborDiscoveryOffload(true);
        verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).setFallbackMulticastFilter(false);
        verify(mCb, never()).onProvisioningFailure(any());
        ipc.setL2KeyAndGroupHint(l2Key, groupHint);