Loading src/android/net/ip/IpClient.java +7 −7 Original line number Diff line number Diff line Loading @@ -1289,7 +1289,8 @@ public class IpClient extends StateMachine { return; } if (params.defaultMtu != mInterfaceParams.defaultMtu) { if (params.defaultMtu == mInterfaceParams.defaultMtu) return; try { mNetd.interfaceSetMtu(mInterfaceName, mInterfaceParams.defaultMtu); } catch (RemoteException | ServiceSpecificException e) { Loading @@ -1297,7 +1298,6 @@ public class IpClient extends StateMachine { + params.defaultMtu + " to " + mInterfaceParams.defaultMtu, e); } } } class StoppedState extends State { @Override Loading tests/integration/src/android/net/ip/IpClientIntegrationTest.java +60 −13 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import android.content.res.Resources; import android.net.ConnectivityManager; import android.net.INetd; import android.net.InetAddresses; import android.net.LinkProperties; import android.net.NetworkStackIpMemoryStore; import android.net.TestNetworkInterface; import android.net.TestNetworkManager; Loading @@ -69,6 +70,8 @@ import android.os.HandlerThread; import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.system.ErrnoException; import android.system.Os; import androidx.annotation.Nullable; import androidx.test.InstrumentationRegistry; Loading Loading @@ -395,8 +398,8 @@ public class IpClientIntegrationTest { mDependencies.setDhcpRapidCommitEnabled(isDhcpRapidCommitEnabled); mIpc.setL2KeyAndGroupHint(TEST_L2KEY, TEST_GROUPHINT); mIpc.startProvisioning(config); verify(mCb, times(1)).setNeighborDiscoveryOffload(true); verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).setFallbackMulticastFilter(false); verify(mCb).setNeighborDiscoveryOffload(true); verify(mCb, timeout(TEST_TIMEOUT_MS)).setFallbackMulticastFilter(false); verify(mCb, never()).onProvisioningFailure(any()); } Loading Loading @@ -478,7 +481,22 @@ public class IpClientIntegrationTest { return getNextDhcpPacket(); } private void doRestoreInitialMtuTest(final boolean shouldChangeMtu) throws Exception { private void removeTapInterface(final FileDescriptor fd) { try { Os.close(fd); } catch (ErrnoException e) { fail("Fail to close file descriptor: " + e); } } private void verifyAfterIpClientShutdown() throws RemoteException { final LinkProperties emptyLp = new LinkProperties(); emptyLp.setInterfaceName(mIfaceName); verify(mCb, timeout(TEST_TIMEOUT_MS)).onLinkPropertiesChange(emptyLp); } private void doRestoreInitialMtuTest(final boolean shouldChangeMtu, final boolean shouldRemoveTapInterface) throws Exception { final long currentTime = System.currentTimeMillis(); int mtu = TEST_DEFAULT_MTU; Loading @@ -493,11 +511,21 @@ public class IpClientIntegrationTest { assertEquals(NetworkInterface.getByName(mIfaceName).getMTU(), mtu); } if (shouldRemoveTapInterface) removeTapInterface(mPacketReader.createFd()); try { mIpc.shutdown(); HandlerUtilsKt.waitForIdle(mIpc.getHandler(), TEST_TIMEOUT_MS); if (shouldRemoveTapInterface) { verify(mMockNetd, never()).interfaceSetMtu(mIfaceName, TEST_DEFAULT_MTU); } else { // Verify that MTU indeed has been restored or not. verify(mMockNetd, times(shouldChangeMtu ? 1 : 0)).interfaceSetMtu(mIfaceName, TEST_DEFAULT_MTU); verify(mMockNetd, times(shouldChangeMtu ? 1 : 0)) .interfaceSetMtu(mIfaceName, TEST_DEFAULT_MTU); } verifyAfterIpClientShutdown(); } catch (Exception e) { fail("Exception should not have been thrown after shutdown: " + e); } } @Test Loading Loading @@ -628,20 +656,39 @@ public class IpClientIntegrationTest { @Test public void testRestoreInitialInterfaceMtu() throws Exception { doRestoreInitialMtuTest(true /* shouldChangeMtu */); doRestoreInitialMtuTest(true /* shouldChangeMtu */, false /* shouldRemoveTapInterface */); } @Test public void testRestoreInitialInterfaceMtuWithoutChange() throws Exception { doRestoreInitialMtuTest(false /* shouldChangeMtu */); public void testRestoreInitialInterfaceMtu_WithoutMtuChange() throws Exception { doRestoreInitialMtuTest(false /* shouldChangeMtu */, false /* shouldRemoveTapInterface */); } @Test public void testRestoreInitialInterfaceMtuWithException() throws Exception { public void testRestoreInitialInterfaceMtu_WithException() throws Exception { doThrow(new RemoteException("NetdNativeService::interfaceSetMtu")).when(mMockNetd) .interfaceSetMtu(mIfaceName, TEST_DEFAULT_MTU); doRestoreInitialMtuTest(true /* shouldChangeMtu */); doRestoreInitialMtuTest(true /* shouldChangeMtu */, false /* shouldRemoveTapInterface */); assertEquals(NetworkInterface.getByName(mIfaceName).getMTU(), TEST_MIN_MTU); } @Test public void testRestoreInitialInterfaceMtu_NotFoundInterfaceWhenStopping() throws Exception { doRestoreInitialMtuTest(true /* shouldChangeMtu */, true /* shouldRemoveTapInterface */); } @Test public void testRestoreInitialInterfaceMtu_NotFoundInterfaceWhenStartingProvisioning() throws Exception { removeTapInterface(mPacketReader.createFd()); ProvisioningConfiguration config = new ProvisioningConfiguration.Builder() .withoutIpReachabilityMonitor() .withoutIPv6() .build(); mIpc.startProvisioning(config); verify(mCb).onProvisioningFailure(any()); verify(mCb, never()).setNeighborDiscoveryOffload(true); } } Loading
src/android/net/ip/IpClient.java +7 −7 Original line number Diff line number Diff line Loading @@ -1289,7 +1289,8 @@ public class IpClient extends StateMachine { return; } if (params.defaultMtu != mInterfaceParams.defaultMtu) { if (params.defaultMtu == mInterfaceParams.defaultMtu) return; try { mNetd.interfaceSetMtu(mInterfaceName, mInterfaceParams.defaultMtu); } catch (RemoteException | ServiceSpecificException e) { Loading @@ -1297,7 +1298,6 @@ public class IpClient extends StateMachine { + params.defaultMtu + " to " + mInterfaceParams.defaultMtu, e); } } } class StoppedState extends State { @Override Loading
tests/integration/src/android/net/ip/IpClientIntegrationTest.java +60 −13 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import android.content.res.Resources; import android.net.ConnectivityManager; import android.net.INetd; import android.net.InetAddresses; import android.net.LinkProperties; import android.net.NetworkStackIpMemoryStore; import android.net.TestNetworkInterface; import android.net.TestNetworkManager; Loading @@ -69,6 +70,8 @@ import android.os.HandlerThread; import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.system.ErrnoException; import android.system.Os; import androidx.annotation.Nullable; import androidx.test.InstrumentationRegistry; Loading Loading @@ -395,8 +398,8 @@ public class IpClientIntegrationTest { mDependencies.setDhcpRapidCommitEnabled(isDhcpRapidCommitEnabled); mIpc.setL2KeyAndGroupHint(TEST_L2KEY, TEST_GROUPHINT); mIpc.startProvisioning(config); verify(mCb, times(1)).setNeighborDiscoveryOffload(true); verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).setFallbackMulticastFilter(false); verify(mCb).setNeighborDiscoveryOffload(true); verify(mCb, timeout(TEST_TIMEOUT_MS)).setFallbackMulticastFilter(false); verify(mCb, never()).onProvisioningFailure(any()); } Loading Loading @@ -478,7 +481,22 @@ public class IpClientIntegrationTest { return getNextDhcpPacket(); } private void doRestoreInitialMtuTest(final boolean shouldChangeMtu) throws Exception { private void removeTapInterface(final FileDescriptor fd) { try { Os.close(fd); } catch (ErrnoException e) { fail("Fail to close file descriptor: " + e); } } private void verifyAfterIpClientShutdown() throws RemoteException { final LinkProperties emptyLp = new LinkProperties(); emptyLp.setInterfaceName(mIfaceName); verify(mCb, timeout(TEST_TIMEOUT_MS)).onLinkPropertiesChange(emptyLp); } private void doRestoreInitialMtuTest(final boolean shouldChangeMtu, final boolean shouldRemoveTapInterface) throws Exception { final long currentTime = System.currentTimeMillis(); int mtu = TEST_DEFAULT_MTU; Loading @@ -493,11 +511,21 @@ public class IpClientIntegrationTest { assertEquals(NetworkInterface.getByName(mIfaceName).getMTU(), mtu); } if (shouldRemoveTapInterface) removeTapInterface(mPacketReader.createFd()); try { mIpc.shutdown(); HandlerUtilsKt.waitForIdle(mIpc.getHandler(), TEST_TIMEOUT_MS); if (shouldRemoveTapInterface) { verify(mMockNetd, never()).interfaceSetMtu(mIfaceName, TEST_DEFAULT_MTU); } else { // Verify that MTU indeed has been restored or not. verify(mMockNetd, times(shouldChangeMtu ? 1 : 0)).interfaceSetMtu(mIfaceName, TEST_DEFAULT_MTU); verify(mMockNetd, times(shouldChangeMtu ? 1 : 0)) .interfaceSetMtu(mIfaceName, TEST_DEFAULT_MTU); } verifyAfterIpClientShutdown(); } catch (Exception e) { fail("Exception should not have been thrown after shutdown: " + e); } } @Test Loading Loading @@ -628,20 +656,39 @@ public class IpClientIntegrationTest { @Test public void testRestoreInitialInterfaceMtu() throws Exception { doRestoreInitialMtuTest(true /* shouldChangeMtu */); doRestoreInitialMtuTest(true /* shouldChangeMtu */, false /* shouldRemoveTapInterface */); } @Test public void testRestoreInitialInterfaceMtuWithoutChange() throws Exception { doRestoreInitialMtuTest(false /* shouldChangeMtu */); public void testRestoreInitialInterfaceMtu_WithoutMtuChange() throws Exception { doRestoreInitialMtuTest(false /* shouldChangeMtu */, false /* shouldRemoveTapInterface */); } @Test public void testRestoreInitialInterfaceMtuWithException() throws Exception { public void testRestoreInitialInterfaceMtu_WithException() throws Exception { doThrow(new RemoteException("NetdNativeService::interfaceSetMtu")).when(mMockNetd) .interfaceSetMtu(mIfaceName, TEST_DEFAULT_MTU); doRestoreInitialMtuTest(true /* shouldChangeMtu */); doRestoreInitialMtuTest(true /* shouldChangeMtu */, false /* shouldRemoveTapInterface */); assertEquals(NetworkInterface.getByName(mIfaceName).getMTU(), TEST_MIN_MTU); } @Test public void testRestoreInitialInterfaceMtu_NotFoundInterfaceWhenStopping() throws Exception { doRestoreInitialMtuTest(true /* shouldChangeMtu */, true /* shouldRemoveTapInterface */); } @Test public void testRestoreInitialInterfaceMtu_NotFoundInterfaceWhenStartingProvisioning() throws Exception { removeTapInterface(mPacketReader.createFd()); ProvisioningConfiguration config = new ProvisioningConfiguration.Builder() .withoutIpReachabilityMonitor() .withoutIPv6() .build(); mIpc.startProvisioning(config); verify(mCb).onProvisioningFailure(any()); verify(mCb, never()).setNeighborDiscoveryOffload(true); } }