summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/android/net/ip/IpClient.java14
-rw-r--r--tests/integration/src/android/net/ip/IpClientIntegrationTest.java73
2 files changed, 67 insertions, 20 deletions
diff --git a/src/android/net/ip/IpClient.java b/src/android/net/ip/IpClient.java
index 08a9c5c..98e1e49 100644
--- a/src/android/net/ip/IpClient.java
+++ b/src/android/net/ip/IpClient.java
@@ -1289,13 +1289,13 @@ public class IpClient extends StateMachine {
return;
}
- if (params.defaultMtu != mInterfaceParams.defaultMtu) {
- try {
- mNetd.interfaceSetMtu(mInterfaceName, mInterfaceParams.defaultMtu);
- } catch (RemoteException | ServiceSpecificException e) {
- logError("Couldn't reset MTU on " + mInterfaceName + " from "
- + params.defaultMtu + " to " + mInterfaceParams.defaultMtu, e);
- }
+ if (params.defaultMtu == mInterfaceParams.defaultMtu) return;
+
+ try {
+ mNetd.interfaceSetMtu(mInterfaceName, mInterfaceParams.defaultMtu);
+ } catch (RemoteException | ServiceSpecificException e) {
+ logError("Couldn't reset MTU on " + mInterfaceName + " from "
+ + params.defaultMtu + " to " + mInterfaceParams.defaultMtu, e);
}
}
diff --git a/tests/integration/src/android/net/ip/IpClientIntegrationTest.java b/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
index 400bd51..cb7d418 100644
--- a/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
+++ b/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
@@ -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;
@@ -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;
@@ -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());
}
@@ -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;
@@ -493,11 +511,21 @@ public class IpClientIntegrationTest {
assertEquals(NetworkInterface.getByName(mIfaceName).getMTU(), mtu);
}
- mIpc.shutdown();
- HandlerUtilsKt.waitForIdle(mIpc.getHandler(), TEST_TIMEOUT_MS);
- // Verify that MTU indeed has been restored or not.
- verify(mMockNetd, times(shouldChangeMtu ? 1 : 0)).interfaceSetMtu(mIfaceName,
- TEST_DEFAULT_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);
+ }
+ verifyAfterIpClientShutdown();
+ } catch (Exception e) {
+ fail("Exception should not have been thrown after shutdown: " + e);
+ }
}
@Test
@@ -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);
+ }
}