From 04252031522382efb7bb56566898a69ea25739da Mon Sep 17 00:00:00 2001 From: Hansen Kurli Date: Wed, 7 Dec 2022 11:21:49 +0000 Subject: [PATCH] Ensure MTU is set for new interfaces. Setting the MTU for an interface should not be skipped when the interface names are different. This occurs when a VPN network creates a new interface with identical MTU. Bug: 246398088 Test: atest ConnectivityServiceTest Test: Manual test: Connect to VPN network and switch networks Test: Confirm MTU of interface is set correctly with `adb shell ip addr` Change-Id: I811a01feca2fb2130c57c6c924145314180434c5 --- .../com/android/server/ConnectivityService.java | 17 +++++++++-------- .../android/server/ConnectivityServiceTest.java | 3 +-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index a44494cabd..80ec8ae206 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -3116,22 +3116,23 @@ public class ConnectivityService extends IConnectivityManager.Stub private void updateMtu(@NonNull LinkProperties newLp, @Nullable LinkProperties oldLp) { final String iface = newLp.getInterfaceName(); final int mtu = newLp.getMtu(); - if (oldLp == null && mtu == 0) { + if (mtu == 0) { // Silently ignore unset MTU value. return; } - if (oldLp != null && newLp.isIdenticalMtu(oldLp)) { - if (VDBG) log("identical MTU - not setting"); + if (oldLp != null && newLp.isIdenticalMtu(oldLp) + && TextUtils.equals(oldLp.getInterfaceName(), iface)) { + if (VDBG) log("identical MTU and iface - not setting"); return; } - if (!LinkProperties.isValidMtu(mtu, newLp.hasGlobalIpv6Address())) { - if (mtu != 0) loge("Unexpected mtu value: " + mtu + ", " + iface); + // Cannot set MTU without interface name + if (TextUtils.isEmpty(iface)) { + if (VDBG) log("Setting MTU size with null iface."); return; } - // Cannot set MTU without interface name - if (TextUtils.isEmpty(iface)) { - loge("Setting MTU size with null iface."); + if (!LinkProperties.isValidMtu(mtu, newLp.hasGlobalIpv6Address())) { + loge("Unexpected mtu value: " + mtu + ", " + iface); return; } diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java index 16f7039ee6..3d6ee099c5 100755 --- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java @@ -17155,7 +17155,6 @@ public class ConnectivityServiceTest { mWiFiNetworkAgent.sendLinkProperties(new LinkProperties(lp2)); waitForIdle(); - // TODO(b/246398088): the MTU should be set on the new interface. - verify(mMockNetd, never()).interfaceSetMtu(eq(ifaceName2), eq(mtu)); + verify(mMockNetd).interfaceSetMtu(eq(ifaceName2), eq(mtu)); } }