Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 83c9f5b9 authored by Sarah Chin's avatar Sarah Chin Committed by Automerger Merge Worker
Browse files

Merge "Use lower of IPv4/IPv6 MTU values based on config" am: 86540511

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1402264

Change-Id: I71acbb88945b52a17235e83b1392bdbfcf38b111
parents b8a85972 86540511
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -127,6 +127,8 @@ public class DataConnection extends StateMachine {
    private static final String RAT_NAME_5G = "nr";
    private static final String RAT_NAME_EVDO = "evdo";

    private static final int MIN_V6_MTU = 1280;

    /**
     * The data connection is not being or been handovered. Note this is the state for the source
     * data connection, not destination data connection
@@ -1603,9 +1605,31 @@ public class DataConnection extends StateMachine {
                    }
                }

                boolean useLowerMtuValue = false;
                CarrierConfigManager configManager = (CarrierConfigManager)
                        mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
                if (configManager != null) {
                    PersistableBundle bundle = configManager.getConfigForSubId(mSubId);
                    if (bundle != null) {
                        useLowerMtuValue = bundle.getBoolean(
                                CarrierConfigManager.KEY_USE_LOWER_MTU_VALUE_IF_BOTH_RECEIVED)
                                && response.getMtuV4() != PhoneConstants.UNSET_MTU
                                && response.getMtuV6() != PhoneConstants.UNSET_MTU;
                    }
                }

                int interfaceMtu = response.getMtu();
                for (InetAddress gateway : response.getGatewayAddresses()) {
                    int mtu = gateway instanceof java.net.Inet6Address ? response.getMtuV6()
                            : response.getMtuV4();
                    if (useLowerMtuValue) {
                        mtu = Math.min(response.getMtuV4(), response.getMtuV6());
                        // Never set an MTU below MIN_V6_MTU on a network that has IPv6.
                        if (mtu < MIN_V6_MTU) {
                            mtu = MIN_V6_MTU;
                        }
                        interfaceMtu = mtu;
                    }
                    // Allow 0.0.0.0 or :: as a gateway;
                    // this indicates a point-to-point interface.
                    linkProperties.addRoute(new RouteInfo(null, gateway, null,
@@ -1615,7 +1639,7 @@ public class DataConnection extends StateMachine {
                // set interface MTU
                // this may clobber the setting read from the APN db, but that's ok
                // TODO: remove once LinkProperties#setMtu is deprecated
                linkProperties.setMtu(response.getMtu());
                linkProperties.setMtu(interfaceMtu);

                result = SetupResult.SUCCESS;
            } catch (UnknownHostException e) {