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

Commit 56b91157 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

Merged-In: Ifd06b8d18ce570b1aa424ad215111c80f094ca97
(cherry picked from commit a6aba532)

Change-Id: I0c8c1ed1646ab12bc30da2b7f8e5819d2d9495ba
parent 9b105a99
Loading
Loading
Loading
Loading
+11 −8
Original line number Original line Diff line number Diff line
@@ -765,14 +765,6 @@ public class IpClient extends StateMachine {
            return;
            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));
        sendMessage(CMD_START, new android.net.shared.ProvisioningConfiguration(req));
    }
    }


@@ -1636,6 +1628,17 @@ public class IpClient extends StateMachine {
                // tethering or during an IpClient restart.
                // tethering or during an IpClient restart.
                stopAllIP();
                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
        @Override
+34 −3
Original line number Original line Diff line number Diff line
@@ -524,7 +524,6 @@ public class IpClientIntegrationTest {
        mDependencies.setHostnameConfiguration(isHostnameConfigurationEnabled, hostname);
        mDependencies.setHostnameConfiguration(isHostnameConfigurationEnabled, hostname);
        mIpc.setL2KeyAndGroupHint(TEST_L2KEY, TEST_GROUPHINT);
        mIpc.setL2KeyAndGroupHint(TEST_L2KEY, TEST_GROUPHINT);
        mIpc.startProvisioning(builder.build());
        mIpc.startProvisioning(builder.build());
        verify(mCb).setNeighborDiscoveryOffload(true);
        if (!isPreconnectionEnabled) {
        if (!isPreconnectionEnabled) {
            verify(mCb, timeout(TEST_TIMEOUT_MS)).setFallbackMulticastFilter(false);
            verify(mCb, timeout(TEST_TIMEOUT_MS)).setFallbackMulticastFilter(false);
        }
        }
@@ -642,7 +641,6 @@ public class IpClientIntegrationTest {
                            ArgumentCaptor.forClass(LinkProperties.class);
                            ArgumentCaptor.forClass(LinkProperties.class);
                    verifyProvisioningSuccess(captor, Collections.singletonList(CLIENT_ADDR));
                    verifyProvisioningSuccess(captor, Collections.singletonList(CLIENT_ADDR));
                }
                }

                return packetList;
                return packetList;
            }
            }
        }
        }
@@ -725,6 +723,12 @@ public class IpClientIntegrationTest {
            assertEquals(NetworkInterface.getByName(mIfaceName).getMTU(), mtu);
            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);
        if (shouldRemoveTapInterface) removeTapInterface(mTapFd);
        try {
        try {
            mIpc.shutdown();
            mIpc.shutdown();
@@ -1081,10 +1085,37 @@ public class IpClientIntegrationTest {
                .build();
                .build();


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


        ipc.startProvisioning(config);
        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, timeout(TEST_TIMEOUT_MS).times(1)).setFallbackMulticastFilter(false);


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


        ipc.startProvisioning(config);
        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, timeout(TEST_TIMEOUT_MS).times(1)).setFallbackMulticastFilter(false);
        verify(mCb, never()).onProvisioningFailure(any());
        verify(mCb, never()).onProvisioningFailure(any());
        ipc.setL2KeyAndGroupHint(l2Key, groupHint);
        ipc.setL2KeyAndGroupHint(l2Key, groupHint);