From e714f1daa6a28749e2aaa5209b685b499afbe7a3 Mon Sep 17 00:00:00 2001 From: w19976 Date: Tue, 5 Aug 2014 15:18:11 -0700 Subject: [PATCH] Configure MTU based on network MTU parameter Add logic to obtain the mtu from the network PCO parameter and set it to kernel when the mobile data connection is established. When there is no PCO mtu configured from the network, the mtu size defined in the corresponding APN will be used. In case no mtu size is defined for an APN used for data connection, the MCC/MNC based MTU defined in the framework overaly will be applied. bug:17046179 Change-Id: I6465d4b8f2076aaa380ae3617fb3f24adbe136d4 --- core/java/android/net/LinkProperties.java | 17 +++++++++++++++++ .../com/android/server/ConnectivityService.java | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java index 47b74ab4d2..8b64250777 100644 --- a/core/java/android/net/LinkProperties.java +++ b/core/java/android/net/LinkProperties.java @@ -55,6 +55,10 @@ public final class LinkProperties implements Parcelable { private ProxyInfo mHttpProxy; private int mMtu; + private static final int MIN_MTU = 68; + private static final int MIN_MTU_V6 = 1280; + private static final int MAX_MTU = 10000; + // Stores the properties of links that are "stacked" above this link. // Indexed by interface name to allow modification and to prevent duplicates being added. private Hashtable mStackedLinks = @@ -995,4 +999,17 @@ public final class LinkProperties implements Parcelable { return new LinkProperties[size]; } }; + + /** + * Check the valid MTU range based on IPv4 or IPv6. + * @hide + */ + public static boolean isValidMtu(int mtu, boolean ipv6) { + if (ipv6) { + if ((mtu >= MIN_MTU_V6 && mtu <= MAX_MTU)) return true; + } else { + if ((mtu >= MIN_MTU && mtu <= MAX_MTU)) return true; + } + return false; + } } diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index dd5a7ea5f6..02695c5216 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -1534,11 +1534,17 @@ public class ConnectivityService extends IConnectivityManager.Stub { return; } - if (mtu < 68 || mtu > 10000) { + if (LinkProperties.isValidMtu(mtu, newLp.hasGlobalIPv6Address())) { loge("Unexpected mtu value: " + mtu + ", " + iface); return; } + // Cannot set MTU without interface name + if (TextUtils.isEmpty(iface)) { + loge("Setting MTU size with null iface."); + return; + } + try { if (VDBG) log("Setting MTU size: " + iface + ", " + mtu); mNetd.setMtu(iface, mtu);