summaryrefslogtreecommitdiff
path: root/src/android/net/ip/IpClient.java
diff options
context:
space:
mode:
authorXiao Ma <xiaom@google.com>2019-07-16 19:16:39 +0900
committerXiao Ma <xiaom@google.com>2019-08-01 11:52:40 +0900
commit98ed332579d20a8304b5cdbba761d49bcad75fd3 (patch)
tree7a86cc20fbd26a81bb09d7bb28d7c25619bfddb8 /src/android/net/ip/IpClient.java
parent03886222d30b70068f16c63f95d573d25ce6df4a (diff)
Restore the default interface MTU when disconnecting from Wi-Fi AP.
Bug: 113350007 Test: atest FrameworksNetTests NetworkStackTests Test: atest NetworkStackIntegrationTests Test: manual test Change-Id: I4b0ecdb63df567f0cbbb13d2b48bbfaaa7aee4d9
Diffstat (limited to 'src/android/net/ip/IpClient.java')
-rw-r--r--src/android/net/ip/IpClient.java39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/android/net/ip/IpClient.java b/src/android/net/ip/IpClient.java
index 799184e..bff30b6 100644
--- a/src/android/net/ip/IpClient.java
+++ b/src/android/net/ip/IpClient.java
@@ -19,6 +19,7 @@ package android.net.ip;
import static android.net.RouteInfo.RTN_UNICAST;
import static android.net.shared.IpConfigurationParcelableUtil.toStableParcelable;
+import static com.android.server.util.NetworkStackConstants.ETHER_MTU;
import static com.android.server.util.PermissionUtil.checkNetworkStackCallingPermission;
import android.annotation.NonNull;
@@ -48,6 +49,7 @@ import android.os.ConditionVariable;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
+import android.os.ServiceSpecificException;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.LocalLog;
@@ -69,6 +71,8 @@ import com.android.server.NetworkStackService.NetworkStackServiceManager;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
@@ -380,6 +384,8 @@ public class IpClient extends StateMachine {
private final ConditionVariable mApfDataSnapshotComplete = new ConditionVariable();
public static class Dependencies {
+ private static final String TAG = "IpClient.Dependencies";
+
/**
* Get interface parameters for the specified interface.
*/
@@ -388,6 +394,18 @@ public class IpClient extends StateMachine {
}
/**
+ * Get the current MTU for the specified interface.
+ */
+ public int getInterfaceMtu(String ifname) {
+ try {
+ return NetworkInterface.getByName(ifname).getMTU();
+ } catch (SocketException e) {
+ Log.e(TAG, "unexpected failure to get the interface MTU");
+ return ETHER_MTU;
+ }
+ }
+
+ /**
* Get a INetd connector.
*/
public INetd getNetd(Context context) {
@@ -850,10 +868,14 @@ public class IpClient extends StateMachine {
return shouldLog;
}
- private void logError(String fmt, Object... args) {
+ private void logError(String fmt, Throwable e, Object... args) {
final String msg = "ERROR " + String.format(fmt, args);
- Log.e(mTag, msg);
- mLog.log(msg);
+ Log.e(mTag, msg, e);
+ mLog.e(msg, e);
+ }
+
+ private void logError(String fmt, Object... args) {
+ logError(fmt, null, args);
}
// This needs to be called with care to ensure that our LinkProperties
@@ -1351,6 +1373,17 @@ public class IpClient extends StateMachine {
// There's no DHCPv4 for which to wait; proceed to stopped.
deferMessage(obtainMessage(CMD_JUMP_STOPPING_TO_STOPPED));
}
+
+ // Restore the interface MTU to initial value if it has changed.
+ final int mtu = mDependencies.getInterfaceMtu(mInterfaceName);
+ try {
+ if (mtu != mInterfaceParams.defaultMtu) {
+ mNetd.interfaceSetMtu(mInterfaceName, mInterfaceParams.defaultMtu);
+ }
+ } catch (RemoteException | ServiceSpecificException e) {
+ logError("Couldn't reset MTU from "
+ + mtu + " to " + mInterfaceParams.defaultMtu + ": " + e);
+ }
}
@Override