Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1 | /* |
Wink Saville | 6e80997 | 2010-09-21 09:15:35 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.net; |
| 18 | |
Jeff Sharkey | eb2c2c7 | 2014-08-11 15:22:51 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 22 | import android.annotation.UnsupportedAppUsage; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 23 | import android.os.Parcel; |
Rubin Xu | 1bb5c08 | 2017-09-05 18:40:49 +0100 | [diff] [blame] | 24 | import android.os.Parcelable; |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 25 | import android.text.TextUtils; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 26 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 27 | import java.net.Inet4Address; |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 28 | import java.net.Inet6Address; |
Rubin Xu | 1bb5c08 | 2017-09-05 18:40:49 +0100 | [diff] [blame] | 29 | import java.net.InetAddress; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 30 | import java.net.UnknownHostException; |
| 31 | import java.util.ArrayList; |
| 32 | import java.util.Collection; |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 33 | import java.util.Collections; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 34 | import java.util.Hashtable; |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 35 | import java.util.List; |
Lorenzo Colitti | c17a1b9 | 2014-06-12 23:10:17 +0900 | [diff] [blame] | 36 | import java.util.Objects; |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 37 | import java.util.StringJoiner; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 40 | * Describes the properties of a network link. |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 41 | * |
| 42 | * A link represents a connection to a network. |
| 43 | * It may have multiple addresses and multiple gateways, |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 44 | * multiple dns servers but only one http proxy and one |
| 45 | * network interface. |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 46 | * |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 47 | * Note that this is just a holder of data. Modifying it |
| 48 | * does not affect live networks. |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 49 | * |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 50 | */ |
Robert Greenwalt | e595b97 | 2014-06-12 16:24:38 -0700 | [diff] [blame] | 51 | public final class LinkProperties implements Parcelable { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 52 | // The interface described by the network link. |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 53 | @UnsupportedAppUsage |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 54 | private String mIfaceName; |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 55 | private ArrayList<LinkAddress> mLinkAddresses = new ArrayList<>(); |
| 56 | private ArrayList<InetAddress> mDnses = new ArrayList<>(); |
| 57 | private ArrayList<InetAddress> mValidatedPrivateDnses = new ArrayList<>(); |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 58 | private boolean mUsePrivateDns; |
| 59 | private String mPrivateDnsServerName; |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 60 | private String mDomains; |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 61 | private ArrayList<RouteInfo> mRoutes = new ArrayList<>(); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 62 | private ProxyInfo mHttpProxy; |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 63 | private int mMtu; |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 64 | // in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max" |
| 65 | private String mTcpBufferSizes; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 66 | |
w19976 | 15afd81 | 2014-08-05 15:18:11 -0700 | [diff] [blame] | 67 | private static final int MIN_MTU = 68; |
| 68 | private static final int MIN_MTU_V6 = 1280; |
| 69 | private static final int MAX_MTU = 10000; |
| 70 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 71 | // Stores the properties of links that are "stacked" above this link. |
| 72 | // Indexed by interface name to allow modification and to prevent duplicates being added. |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 73 | private Hashtable<String, LinkProperties> mStackedLinks = new Hashtable<>(); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 74 | |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 75 | /** |
| 76 | * @hide |
| 77 | */ |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 78 | public static class CompareResult<T> { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 79 | public final List<T> removed = new ArrayList<>(); |
| 80 | public final List<T> added = new ArrayList<>(); |
Rubin Xu | 2fc72f7 | 2017-08-22 16:35:52 +0100 | [diff] [blame] | 81 | |
| 82 | public CompareResult() {} |
| 83 | |
| 84 | public CompareResult(Collection<T> oldItems, Collection<T> newItems) { |
| 85 | if (oldItems != null) { |
| 86 | removed.addAll(oldItems); |
| 87 | } |
| 88 | if (newItems != null) { |
| 89 | for (T newItem : newItems) { |
| 90 | if (!removed.remove(newItem)) { |
| 91 | added.add(newItem); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 96 | |
| 97 | @Override |
| 98 | public String toString() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 99 | return "removed=[" + TextUtils.join(",", removed) |
| 100 | + "] added=[" + TextUtils.join(",", added) |
| 101 | + "]"; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Sreeram Ramachandran | cc91c7b | 2014-06-03 18:41:43 -0700 | [diff] [blame] | 105 | /** |
| 106 | * @hide |
| 107 | */ |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 108 | public enum ProvisioningChange { |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 109 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 110 | STILL_NOT_PROVISIONED, |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 111 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 112 | LOST_PROVISIONING, |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 113 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 114 | GAINED_PROVISIONING, |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 115 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 116 | STILL_PROVISIONED, |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Compare the provisioning states of two LinkProperties instances. |
| 121 | * |
| 122 | * @hide |
| 123 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 124 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 125 | public static ProvisioningChange compareProvisioning( |
| 126 | LinkProperties before, LinkProperties after) { |
| 127 | if (before.isProvisioned() && after.isProvisioned()) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 128 | // On dual-stack networks, DHCPv4 renewals can occasionally fail. |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 129 | // When this happens, IPv6-reachable services continue to function |
| 130 | // normally but IPv4-only services (naturally) fail. |
| 131 | // |
| 132 | // When an application using an IPv4-only service reports a bad |
| 133 | // network condition to the framework, attempts to re-validate |
| 134 | // the network succeed (since we support IPv6-only networks) and |
| 135 | // nothing is changed. |
| 136 | // |
| 137 | // For users, this is confusing and unexpected behaviour, and is |
| 138 | // not necessarily easy to diagnose. Therefore, we treat changing |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 139 | // from a dual-stack network to an IPv6-only network equivalent to |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 140 | // a total loss of provisioning. |
| 141 | // |
| 142 | // For one such example of this, see b/18867306. |
| 143 | // |
Erik Kline | 1ad4e22 | 2015-08-14 12:16:55 +0900 | [diff] [blame] | 144 | // Additionally, losing IPv6 provisioning can result in TCP |
| 145 | // connections getting stuck until timeouts fire and other |
| 146 | // baffling failures. Therefore, loss of either IPv4 or IPv6 on a |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 147 | // previously dual-stack network is deemed a lost of provisioning. |
Erik Kline | 1ad4e22 | 2015-08-14 12:16:55 +0900 | [diff] [blame] | 148 | if ((before.isIPv4Provisioned() && !after.isIPv4Provisioned()) || |
| 149 | (before.isIPv6Provisioned() && !after.isIPv6Provisioned())) { |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 150 | return ProvisioningChange.LOST_PROVISIONING; |
| 151 | } |
| 152 | return ProvisioningChange.STILL_PROVISIONED; |
| 153 | } else if (before.isProvisioned() && !after.isProvisioned()) { |
| 154 | return ProvisioningChange.LOST_PROVISIONING; |
| 155 | } else if (!before.isProvisioned() && after.isProvisioned()) { |
| 156 | return ProvisioningChange.GAINED_PROVISIONING; |
| 157 | } else { // !before.isProvisioned() && !after.isProvisioned() |
| 158 | return ProvisioningChange.STILL_NOT_PROVISIONED; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * @hide |
| 164 | */ |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 165 | @SystemApi |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 166 | public LinkProperties() { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Sreeram Ramachandran | cc91c7b | 2014-06-03 18:41:43 -0700 | [diff] [blame] | 169 | /** |
| 170 | * @hide |
| 171 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 172 | @UnsupportedAppUsage |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 173 | public LinkProperties(LinkProperties source) { |
Irfan Sheriff | ef6c143 | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 174 | if (source != null) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 175 | mIfaceName = source.mIfaceName; |
| 176 | mLinkAddresses.addAll(source.mLinkAddresses); |
| 177 | mDnses.addAll(source.mDnses); |
| 178 | mValidatedPrivateDnses.addAll(source.mValidatedPrivateDnses); |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 179 | mUsePrivateDns = source.mUsePrivateDns; |
| 180 | mPrivateDnsServerName = source.mPrivateDnsServerName; |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 181 | mDomains = source.mDomains; |
| 182 | mRoutes.addAll(source.mRoutes); |
| 183 | mHttpProxy = (source.mHttpProxy == null) ? null : new ProxyInfo(source.mHttpProxy); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 184 | for (LinkProperties l: source.mStackedLinks.values()) { |
| 185 | addStackedLink(l); |
| 186 | } |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 187 | setMtu(source.mMtu); |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 188 | mTcpBufferSizes = source.mTcpBufferSizes; |
Irfan Sheriff | ef6c143 | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 189 | } |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 192 | /** |
| 193 | * Sets the interface name for this link. All {@link RouteInfo} already set for this |
| 194 | * will have their interface changed to match this new value. |
| 195 | * |
| 196 | * @param iface The name of the network interface used for this link. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 197 | * @hide |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 198 | */ |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 199 | @SystemApi |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 200 | public void setInterfaceName(String iface) { |
| 201 | mIfaceName = iface; |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 202 | ArrayList<RouteInfo> newRoutes = new ArrayList<>(mRoutes.size()); |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 203 | for (RouteInfo route : mRoutes) { |
| 204 | newRoutes.add(routeWithInterface(route)); |
| 205 | } |
| 206 | mRoutes = newRoutes; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 209 | /** |
| 210 | * Gets the interface name for this link. May be {@code null} if not set. |
| 211 | * |
| 212 | * @return The interface name set for this link or {@code null}. |
| 213 | */ |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 214 | public @Nullable String getInterfaceName() { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 215 | return mIfaceName; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 216 | } |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 217 | |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 218 | /** |
| 219 | * @hide |
| 220 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 221 | @UnsupportedAppUsage |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 222 | public List<String> getAllInterfaceNames() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 223 | List<String> interfaceNames = new ArrayList<>(mStackedLinks.size() + 1); |
| 224 | if (mIfaceName != null) interfaceNames.add(mIfaceName); |
Lorenzo Colitti | 4aa9bcf | 2013-03-20 19:22:58 +0900 | [diff] [blame] | 225 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 226 | interfaceNames.addAll(stacked.getAllInterfaceNames()); |
| 227 | } |
| 228 | return interfaceNames; |
| 229 | } |
| 230 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 231 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 232 | * Returns all the addresses on this link. We often think of a link having a single address, |
| 233 | * however, particularly with Ipv6 several addresses are typical. Note that the |
| 234 | * {@code LinkProperties} actually contains {@link LinkAddress} objects which also include |
| 235 | * prefix lengths for each address. This is a simplified utility alternative to |
| 236 | * {@link LinkProperties#getLinkAddresses}. |
| 237 | * |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 238 | * @return An unmodifiable {@link List} of {@link InetAddress} for this link. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 239 | * @hide |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 240 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 241 | @UnsupportedAppUsage |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 242 | public List<InetAddress> getAddresses() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 243 | List<InetAddress> addresses = new ArrayList<>(); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 244 | for (LinkAddress linkAddress : mLinkAddresses) { |
| 245 | addresses.add(linkAddress.getAddress()); |
| 246 | } |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 247 | return Collections.unmodifiableList(addresses); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 250 | /** |
| 251 | * Returns all the addresses on this link and all the links stacked above it. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 252 | * @hide |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 253 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 254 | @UnsupportedAppUsage |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 255 | public List<InetAddress> getAllAddresses() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 256 | List<InetAddress> addresses = new ArrayList<>(); |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 257 | for (LinkAddress linkAddress : mLinkAddresses) { |
| 258 | addresses.add(linkAddress.getAddress()); |
| 259 | } |
| 260 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 261 | addresses.addAll(stacked.getAllAddresses()); |
| 262 | } |
| 263 | return addresses; |
| 264 | } |
| 265 | |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 266 | private int findLinkAddressIndex(LinkAddress address) { |
| 267 | for (int i = 0; i < mLinkAddresses.size(); i++) { |
| 268 | if (mLinkAddresses.get(i).isSameAddressAs(address)) { |
| 269 | return i; |
| 270 | } |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 271 | } |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 272 | return -1; |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 276 | * Adds a {@link LinkAddress} to this {@code LinkProperties} if a {@link LinkAddress} of the |
| 277 | * same address/prefix does not already exist. If it does exist it is replaced. |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 278 | * @param address The {@code LinkAddress} to add. |
| 279 | * @return true if {@code address} was added or updated, false otherwise. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 280 | * @hide |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 281 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 282 | @UnsupportedAppUsage |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 283 | public boolean addLinkAddress(LinkAddress address) { |
| 284 | if (address == null) { |
| 285 | return false; |
| 286 | } |
| 287 | int i = findLinkAddressIndex(address); |
| 288 | if (i < 0) { |
| 289 | // Address was not present. Add it. |
| 290 | mLinkAddresses.add(address); |
| 291 | return true; |
| 292 | } else if (mLinkAddresses.get(i).equals(address)) { |
| 293 | // Address was present and has same properties. Do nothing. |
| 294 | return false; |
| 295 | } else { |
| 296 | // Address was present and has different properties. Update it. |
| 297 | mLinkAddresses.set(i, address); |
| 298 | return true; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 303 | * Removes a {@link LinkAddress} from this {@code LinkProperties}. Specifically, matches |
| 304 | * and {@link LinkAddress} with the same address and prefix. |
| 305 | * |
| 306 | * @param toRemove A {@link LinkAddress} specifying the address to remove. |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 307 | * @return true if the address was removed, false if it did not exist. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 308 | * @hide |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 309 | */ |
| 310 | public boolean removeLinkAddress(LinkAddress toRemove) { |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 311 | int i = findLinkAddressIndex(toRemove); |
| 312 | if (i >= 0) { |
| 313 | mLinkAddresses.remove(i); |
| 314 | return true; |
| 315 | } |
| 316 | return false; |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 319 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 320 | * Returns all the {@link LinkAddress} on this link. Typically a link will have |
| 321 | * one IPv4 address and one or more IPv6 addresses. |
| 322 | * |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 323 | * @return An unmodifiable {@link List} of {@link LinkAddress} for this link. |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 324 | */ |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 325 | public List<LinkAddress> getLinkAddresses() { |
| 326 | return Collections.unmodifiableList(mLinkAddresses); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 329 | /** |
| 330 | * Returns all the addresses on this link and all the links stacked above it. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 331 | * @hide |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 332 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 333 | @UnsupportedAppUsage |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 334 | public List<LinkAddress> getAllLinkAddresses() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 335 | List<LinkAddress> addresses = new ArrayList<>(mLinkAddresses); |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 336 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 337 | addresses.addAll(stacked.getAllLinkAddresses()); |
| 338 | } |
| 339 | return addresses; |
| 340 | } |
| 341 | |
Lorenzo Colitti | 22f407b | 2013-08-23 20:54:49 +0900 | [diff] [blame] | 342 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 343 | * Replaces the {@link LinkAddress} in this {@code LinkProperties} with |
| 344 | * the given {@link Collection} of {@link LinkAddress}. |
| 345 | * |
| 346 | * @param addresses The {@link Collection} of {@link LinkAddress} to set in this |
| 347 | * object. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 348 | * @hide |
Lorenzo Colitti | 22f407b | 2013-08-23 20:54:49 +0900 | [diff] [blame] | 349 | */ |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 350 | @SystemApi |
Lorenzo Colitti | 22f407b | 2013-08-23 20:54:49 +0900 | [diff] [blame] | 351 | public void setLinkAddresses(Collection<LinkAddress> addresses) { |
| 352 | mLinkAddresses.clear(); |
| 353 | for (LinkAddress address: addresses) { |
| 354 | addLinkAddress(address); |
| 355 | } |
| 356 | } |
| 357 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 358 | /** |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 359 | * Adds the given {@link InetAddress} to the list of DNS servers, if not present. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 360 | * |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 361 | * @param dnsServer The {@link InetAddress} to add to the list of DNS servers. |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 362 | * @return true if the DNS server was added, false if it was already present. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 363 | * @hide |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 364 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 365 | @UnsupportedAppUsage |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 366 | public boolean addDnsServer(InetAddress dnsServer) { |
| 367 | if (dnsServer != null && !mDnses.contains(dnsServer)) { |
| 368 | mDnses.add(dnsServer); |
| 369 | return true; |
| 370 | } |
| 371 | return false; |
| 372 | } |
| 373 | |
| 374 | /** |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 375 | * Removes the given {@link InetAddress} from the list of DNS servers. |
| 376 | * |
| 377 | * @param dnsServer The {@link InetAddress} to remove from the list of DNS servers. |
| 378 | * @return true if the DNS server was removed, false if it did not exist. |
| 379 | * @hide |
| 380 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 381 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 382 | public boolean removeDnsServer(InetAddress dnsServer) { |
| 383 | if (dnsServer != null) { |
| 384 | return mDnses.remove(dnsServer); |
| 385 | } |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | /** |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 390 | * Replaces the DNS servers in this {@code LinkProperties} with |
| 391 | * the given {@link Collection} of {@link InetAddress} objects. |
| 392 | * |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 393 | * @param dnsServers The {@link Collection} of DNS servers to set in this object. |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 394 | * @hide |
| 395 | */ |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 396 | @SystemApi |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 397 | public void setDnsServers(Collection<InetAddress> dnsServers) { |
| 398 | mDnses.clear(); |
| 399 | for (InetAddress dnsServer: dnsServers) { |
| 400 | addDnsServer(dnsServer); |
| 401 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 402 | } |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 403 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 404 | /** |
Sreeram Ramachandran | cc91c7b | 2014-06-03 18:41:43 -0700 | [diff] [blame] | 405 | * Returns all the {@link InetAddress} for DNS servers on this link. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 406 | * |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 407 | * @return An unmodifiable {@link List} of {@link InetAddress} for DNS servers on |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 408 | * this link. |
| 409 | */ |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 410 | public List<InetAddress> getDnsServers() { |
| 411 | return Collections.unmodifiableList(mDnses); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 414 | /** |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 415 | * Set whether private DNS is currently in use on this network. |
| 416 | * |
| 417 | * @param usePrivateDns The private DNS state. |
| 418 | * @hide |
| 419 | */ |
| 420 | public void setUsePrivateDns(boolean usePrivateDns) { |
| 421 | mUsePrivateDns = usePrivateDns; |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Returns whether private DNS is currently in use on this network. When |
| 426 | * private DNS is in use, applications must not send unencrypted DNS |
| 427 | * queries as doing so could reveal private user information. Furthermore, |
| 428 | * if private DNS is in use and {@link #getPrivateDnsServerName} is not |
| 429 | * {@code null}, DNS queries must be sent to the specified DNS server. |
| 430 | * |
| 431 | * @return {@code true} if private DNS is in use, {@code false} otherwise. |
| 432 | */ |
| 433 | public boolean isPrivateDnsActive() { |
| 434 | return mUsePrivateDns; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Set the name of the private DNS server to which private DNS queries |
| 439 | * should be sent when in strict mode. This value should be {@code null} |
| 440 | * when private DNS is off or in opportunistic mode. |
| 441 | * |
| 442 | * @param privateDnsServerName The private DNS server name. |
| 443 | * @hide |
| 444 | */ |
| 445 | public void setPrivateDnsServerName(@Nullable String privateDnsServerName) { |
| 446 | mPrivateDnsServerName = privateDnsServerName; |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Returns the private DNS server name that is in use. If not {@code null}, |
| 451 | * private DNS is in strict mode. In this mode, applications should ensure |
| 452 | * that all DNS queries are encrypted and sent to this hostname and that |
| 453 | * queries are only sent if the hostname's certificate is valid. If |
| 454 | * {@code null} and {@link #isPrivateDnsActive} is {@code true}, private |
| 455 | * DNS is in opportunistic mode, and applications should ensure that DNS |
| 456 | * queries are encrypted and sent to a DNS server returned by |
| 457 | * {@link #getDnsServers}. System DNS will handle each of these cases |
| 458 | * correctly, but applications implementing their own DNS lookups must make |
| 459 | * sure to follow these requirements. |
| 460 | * |
| 461 | * @return The private DNS server name. |
| 462 | */ |
| 463 | public @Nullable String getPrivateDnsServerName() { |
| 464 | return mPrivateDnsServerName; |
| 465 | } |
| 466 | |
| 467 | /** |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 468 | * Adds the given {@link InetAddress} to the list of validated private DNS servers, |
| 469 | * if not present. This is distinct from the server name in that these are actually |
| 470 | * resolved addresses. |
| 471 | * |
| 472 | * @param dnsServer The {@link InetAddress} to add to the list of validated private DNS servers. |
| 473 | * @return true if the DNS server was added, false if it was already present. |
| 474 | * @hide |
| 475 | */ |
| 476 | public boolean addValidatedPrivateDnsServer(InetAddress dnsServer) { |
| 477 | if (dnsServer != null && !mValidatedPrivateDnses.contains(dnsServer)) { |
| 478 | mValidatedPrivateDnses.add(dnsServer); |
| 479 | return true; |
| 480 | } |
| 481 | return false; |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Removes the given {@link InetAddress} from the list of validated private DNS servers. |
| 486 | * |
| 487 | * @param dnsServer The {@link InetAddress} to remove from the list of validated private DNS |
| 488 | * servers. |
| 489 | * @return true if the DNS server was removed, false if it did not exist. |
| 490 | * @hide |
| 491 | */ |
| 492 | public boolean removeValidatedPrivateDnsServer(InetAddress dnsServer) { |
| 493 | if (dnsServer != null) { |
| 494 | return mValidatedPrivateDnses.remove(dnsServer); |
| 495 | } |
| 496 | return false; |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * Replaces the validated private DNS servers in this {@code LinkProperties} with |
| 501 | * the given {@link Collection} of {@link InetAddress} objects. |
| 502 | * |
| 503 | * @param dnsServers The {@link Collection} of validated private DNS servers to set in this |
| 504 | * object. |
| 505 | * @hide |
| 506 | */ |
| 507 | public void setValidatedPrivateDnsServers(Collection<InetAddress> dnsServers) { |
| 508 | mValidatedPrivateDnses.clear(); |
| 509 | for (InetAddress dnsServer: dnsServers) { |
| 510 | addValidatedPrivateDnsServer(dnsServer); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * Returns all the {@link InetAddress} for validated private DNS servers on this link. |
| 516 | * These are resolved from the private DNS server name. |
| 517 | * |
| 518 | * @return An umodifiable {@link List} of {@link InetAddress} for validated private |
| 519 | * DNS servers on this link. |
| 520 | * @hide |
| 521 | */ |
| 522 | public List<InetAddress> getValidatedPrivateDnsServers() { |
| 523 | return Collections.unmodifiableList(mValidatedPrivateDnses); |
| 524 | } |
| 525 | |
| 526 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 527 | * Sets the DNS domain search path used on this link. |
| 528 | * |
| 529 | * @param domains A {@link String} listing in priority order the comma separated |
| 530 | * domains to search when resolving host names on this link. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 531 | * @hide |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 532 | */ |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 533 | @SystemApi |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 534 | public void setDomains(String domains) { |
| 535 | mDomains = domains; |
| 536 | } |
| 537 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 538 | /** |
| 539 | * Get the DNS domains search path set for this link. |
| 540 | * |
| 541 | * @return A {@link String} containing the comma separated domains to search when resolving |
| 542 | * host names on this link. |
| 543 | */ |
| 544 | public String getDomains() { |
| 545 | return mDomains; |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Sets the Maximum Transmission Unit size to use on this link. This should not be used |
| 550 | * unless the system default (1500) is incorrect. Values less than 68 or greater than |
| 551 | * 10000 will be ignored. |
| 552 | * |
| 553 | * @param mtu The MTU to use for this link. |
| 554 | * @hide |
| 555 | */ |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 556 | @SystemApi |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 557 | public void setMtu(int mtu) { |
| 558 | mMtu = mtu; |
| 559 | } |
| 560 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 561 | /** |
| 562 | * Gets any non-default MTU size set for this link. Note that if the default is being used |
| 563 | * this will return 0. |
| 564 | * |
| 565 | * @return The mtu value set for this link. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 566 | */ |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 567 | public int getMtu() { |
| 568 | return mMtu; |
| 569 | } |
| 570 | |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 571 | /** |
| 572 | * Sets the tcp buffers sizes to be used when this link is the system default. |
| 573 | * Should be of the form "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max". |
| 574 | * |
| 575 | * @param tcpBufferSizes The tcp buffers sizes to use. |
| 576 | * |
| 577 | * @hide |
| 578 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 579 | @UnsupportedAppUsage |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 580 | public void setTcpBufferSizes(String tcpBufferSizes) { |
| 581 | mTcpBufferSizes = tcpBufferSizes; |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * Gets the tcp buffer sizes. |
| 586 | * |
| 587 | * @return the tcp buffer sizes to use when this link is the system default. |
| 588 | * |
| 589 | * @hide |
| 590 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 591 | @UnsupportedAppUsage |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 592 | public String getTcpBufferSizes() { |
| 593 | return mTcpBufferSizes; |
| 594 | } |
| 595 | |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 596 | private RouteInfo routeWithInterface(RouteInfo route) { |
| 597 | return new RouteInfo( |
| 598 | route.getDestination(), |
| 599 | route.getGateway(), |
Lorenzo Colitti | 4b0f8e6 | 2014-09-19 01:49:05 +0900 | [diff] [blame] | 600 | mIfaceName, |
| 601 | route.getType()); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 602 | } |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 603 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 604 | /** |
Lorenzo Colitti | c17a1b9 | 2014-06-12 23:10:17 +0900 | [diff] [blame] | 605 | * Adds a {@link RouteInfo} to this {@code LinkProperties}, if not present. If the |
| 606 | * {@link RouteInfo} had an interface name set and that differs from the interface set for this |
| 607 | * {@code LinkProperties} an {@link IllegalArgumentException} will be thrown. The proper |
| 608 | * course is to add either un-named or properly named {@link RouteInfo}. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 609 | * |
| 610 | * @param route A {@link RouteInfo} to add to this object. |
Lorenzo Colitti | c17a1b9 | 2014-06-12 23:10:17 +0900 | [diff] [blame] | 611 | * @return {@code false} if the route was already present, {@code true} if it was added. |
| 612 | * |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 613 | * @hide |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 614 | */ |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 615 | @SystemApi |
Lorenzo Colitti | c17a1b9 | 2014-06-12 23:10:17 +0900 | [diff] [blame] | 616 | public boolean addRoute(RouteInfo route) { |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 617 | if (route != null) { |
| 618 | String routeIface = route.getInterface(); |
| 619 | if (routeIface != null && !routeIface.equals(mIfaceName)) { |
Lorenzo Colitti | 1994bc1 | 2013-03-08 19:11:40 -0800 | [diff] [blame] | 620 | throw new IllegalArgumentException( |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 621 | "Route added with non-matching interface: " + routeIface + |
Lorenzo Colitti | 1994bc1 | 2013-03-08 19:11:40 -0800 | [diff] [blame] | 622 | " vs. " + mIfaceName); |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 623 | } |
Lorenzo Colitti | c17a1b9 | 2014-06-12 23:10:17 +0900 | [diff] [blame] | 624 | route = routeWithInterface(route); |
| 625 | if (!mRoutes.contains(route)) { |
| 626 | mRoutes.add(route); |
| 627 | return true; |
| 628 | } |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 629 | } |
Lorenzo Colitti | c17a1b9 | 2014-06-12 23:10:17 +0900 | [diff] [blame] | 630 | return false; |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Removes a {@link RouteInfo} from this {@code LinkProperties}, if present. The route must |
| 635 | * specify an interface and the interface must match the interface of this |
| 636 | * {@code LinkProperties}, or it will not be removed. |
| 637 | * |
| 638 | * @return {@code true} if the route was removed, {@code false} if it was not present. |
| 639 | * |
| 640 | * @hide |
| 641 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 642 | @UnsupportedAppUsage |
Lorenzo Colitti | c17a1b9 | 2014-06-12 23:10:17 +0900 | [diff] [blame] | 643 | public boolean removeRoute(RouteInfo route) { |
| 644 | return route != null && |
| 645 | Objects.equals(mIfaceName, route.getInterface()) && |
| 646 | mRoutes.remove(route); |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 647 | } |
| 648 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 649 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 650 | * Returns all the {@link RouteInfo} set on this link. |
| 651 | * |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 652 | * @return An unmodifiable {@link List} of {@link RouteInfo} for this link. |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 653 | */ |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 654 | public List<RouteInfo> getRoutes() { |
| 655 | return Collections.unmodifiableList(mRoutes); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 658 | /** |
Rubin Xu | 1bb5c08 | 2017-09-05 18:40:49 +0100 | [diff] [blame] | 659 | * Make sure this LinkProperties instance contains routes that cover the local subnet |
| 660 | * of its link addresses. Add any route that is missing. |
| 661 | * @hide |
| 662 | */ |
| 663 | public void ensureDirectlyConnectedRoutes() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 664 | for (LinkAddress addr : mLinkAddresses) { |
Rubin Xu | 1bb5c08 | 2017-09-05 18:40:49 +0100 | [diff] [blame] | 665 | addRoute(new RouteInfo(addr, null, mIfaceName)); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | /** |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 670 | * Returns all the routes on this link and all the links stacked above it. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 671 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 672 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 673 | @UnsupportedAppUsage |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 674 | public List<RouteInfo> getAllRoutes() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 675 | List<RouteInfo> routes = new ArrayList<>(mRoutes); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 676 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 677 | routes.addAll(stacked.getAllRoutes()); |
| 678 | } |
Robert Greenwalt | 6629bcd | 2013-03-15 11:28:50 -0700 | [diff] [blame] | 679 | return routes; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 680 | } |
| 681 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 682 | /** |
| 683 | * Sets the recommended {@link ProxyInfo} to use on this link, or {@code null} for none. |
| 684 | * Note that Http Proxies are only a hint - the system recommends their use, but it does |
| 685 | * not enforce it and applications may ignore them. |
| 686 | * |
Erik Kline | b36a313 | 2015-06-26 19:21:34 +0900 | [diff] [blame] | 687 | * @param proxy A {@link ProxyInfo} defining the HTTP Proxy to use on this link. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 688 | * @hide |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 689 | */ |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 690 | @SystemApi |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 691 | public void setHttpProxy(ProxyInfo proxy) { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 692 | mHttpProxy = proxy; |
| 693 | } |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 694 | |
| 695 | /** |
| 696 | * Gets the recommended {@link ProxyInfo} (or {@code null}) set on this link. |
| 697 | * |
| 698 | * @return The {@link ProxyInfo} set on this link |
| 699 | */ |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 700 | public ProxyInfo getHttpProxy() { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 701 | return mHttpProxy; |
| 702 | } |
| 703 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 704 | /** |
| 705 | * Adds a stacked link. |
| 706 | * |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 707 | * If there is already a stacked link with the same interface name as link, |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 708 | * that link is replaced with link. Otherwise, link is added to the list |
| 709 | * of stacked links. If link is null, nothing changes. |
| 710 | * |
| 711 | * @param link The link to add. |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 712 | * @return true if the link was stacked, false otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 713 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 714 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 715 | @UnsupportedAppUsage |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 716 | public boolean addStackedLink(LinkProperties link) { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 717 | if (link != null && link.getInterfaceName() != null) { |
| 718 | mStackedLinks.put(link.getInterfaceName(), link); |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 719 | return true; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 720 | } |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 721 | return false; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | /** |
| 725 | * Removes a stacked link. |
| 726 | * |
Lorenzo Colitti | f3cab63 | 2014-10-20 11:08:03 +0900 | [diff] [blame] | 727 | * If there is a stacked link with the given interface name, it is |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 728 | * removed. Otherwise, nothing changes. |
| 729 | * |
Lorenzo Colitti | f3cab63 | 2014-10-20 11:08:03 +0900 | [diff] [blame] | 730 | * @param iface The interface name of the link to remove. |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 731 | * @return true if the link was removed, false otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 732 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 733 | */ |
Lorenzo Colitti | f3cab63 | 2014-10-20 11:08:03 +0900 | [diff] [blame] | 734 | public boolean removeStackedLink(String iface) { |
| 735 | if (iface != null) { |
| 736 | LinkProperties removed = mStackedLinks.remove(iface); |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 737 | return removed != null; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 738 | } |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 739 | return false; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | /** |
| 743 | * Returns all the links stacked on top of this link. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 744 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 745 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 746 | @UnsupportedAppUsage |
Jeff Sharkey | eb2c2c7 | 2014-08-11 15:22:51 -0700 | [diff] [blame] | 747 | public @NonNull List<LinkProperties> getStackedLinks() { |
| 748 | if (mStackedLinks.isEmpty()) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 749 | return Collections.emptyList(); |
Jeff Sharkey | eb2c2c7 | 2014-08-11 15:22:51 -0700 | [diff] [blame] | 750 | } |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 751 | List<LinkProperties> stacked = new ArrayList<>(); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 752 | for (LinkProperties link : mStackedLinks.values()) { |
Jeff Sharkey | eb2c2c7 | 2014-08-11 15:22:51 -0700 | [diff] [blame] | 753 | stacked.add(new LinkProperties(link)); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 754 | } |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 755 | return Collections.unmodifiableList(stacked); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 758 | /** |
| 759 | * Clears this object to its initial state. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 760 | * @hide |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 761 | */ |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 762 | @SystemApi |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 763 | public void clear() { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 764 | mIfaceName = null; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 765 | mLinkAddresses.clear(); |
| 766 | mDnses.clear(); |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 767 | mUsePrivateDns = false; |
| 768 | mPrivateDnsServerName = null; |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 769 | mDomains = null; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 770 | mRoutes.clear(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 771 | mHttpProxy = null; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 772 | mStackedLinks.clear(); |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 773 | mMtu = 0; |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 774 | mTcpBufferSizes = null; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | /** |
| 778 | * Implement the Parcelable interface |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 779 | */ |
| 780 | public int describeContents() { |
| 781 | return 0; |
| 782 | } |
| 783 | |
Wink Saville | 1f6408a | 2010-08-27 11:15:18 -0700 | [diff] [blame] | 784 | @Override |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 785 | public String toString() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 786 | // Space as a separator, so no need for spaces at start/end of the individual fragments. |
| 787 | final StringJoiner resultJoiner = new StringJoiner(" ", "{", "}"); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 788 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 789 | if (mIfaceName != null) { |
| 790 | resultJoiner.add("InterfaceName:"); |
| 791 | resultJoiner.add(mIfaceName); |
| 792 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 793 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 794 | resultJoiner.add("LinkAddresses: ["); |
| 795 | if (!mLinkAddresses.isEmpty()) { |
| 796 | resultJoiner.add(TextUtils.join(",", mLinkAddresses)); |
| 797 | } |
| 798 | resultJoiner.add("]"); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 799 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 800 | resultJoiner.add("DnsAddresses: ["); |
| 801 | if (!mDnses.isEmpty()) { |
| 802 | resultJoiner.add(TextUtils.join(",", mDnses)); |
| 803 | } |
| 804 | resultJoiner.add("]"); |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 805 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 806 | if (mUsePrivateDns) { |
| 807 | resultJoiner.add("UsePrivateDns: true"); |
| 808 | } |
| 809 | |
Chalard Jean | faaf2fe | 2018-06-07 13:28:09 +0900 | [diff] [blame] | 810 | if (mPrivateDnsServerName != null) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 811 | resultJoiner.add("PrivateDnsServerName:"); |
| 812 | resultJoiner.add(mPrivateDnsServerName); |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 813 | } |
| 814 | |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 815 | if (!mValidatedPrivateDnses.isEmpty()) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 816 | final StringJoiner validatedPrivateDnsesJoiner = |
| 817 | new StringJoiner(",", "ValidatedPrivateDnsAddresses: [", "]"); |
| 818 | for (final InetAddress addr : mValidatedPrivateDnses) { |
| 819 | validatedPrivateDnsesJoiner.add(addr.getHostAddress()); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 820 | } |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 821 | resultJoiner.add(validatedPrivateDnsesJoiner.toString()); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 822 | } |
| 823 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 824 | resultJoiner.add("Domains:"); |
| 825 | resultJoiner.add(mDomains); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 826 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 827 | resultJoiner.add("MTU:"); |
| 828 | resultJoiner.add(Integer.toString(mMtu)); |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 829 | |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 830 | if (mTcpBufferSizes != null) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 831 | resultJoiner.add("TcpBufferSizes:"); |
| 832 | resultJoiner.add(mTcpBufferSizes); |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 835 | resultJoiner.add("Routes: ["); |
| 836 | if (!mRoutes.isEmpty()) { |
| 837 | resultJoiner.add(TextUtils.join(",", mRoutes)); |
| 838 | } |
| 839 | resultJoiner.add("]"); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 840 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 841 | if (mHttpProxy != null) { |
| 842 | resultJoiner.add("HttpProxy:"); |
| 843 | resultJoiner.add(mHttpProxy.toString()); |
| 844 | } |
| 845 | |
| 846 | final Collection<LinkProperties> stackedLinksValues = mStackedLinks.values(); |
| 847 | if (!stackedLinksValues.isEmpty()) { |
| 848 | final StringJoiner stackedLinksJoiner = new StringJoiner(",", "Stacked: [", "]"); |
| 849 | for (final LinkProperties lp : stackedLinksValues) { |
| 850 | stackedLinksJoiner.add("[ " + lp + " ]"); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 851 | } |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 852 | resultJoiner.add(stackedLinksJoiner.toString()); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 853 | } |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 854 | |
| 855 | return resultJoiner.toString(); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /** |
| 859 | * Returns true if this link has an IPv4 address. |
| 860 | * |
| 861 | * @return {@code true} if there is an IPv4 address, {@code false} otherwise. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 862 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 863 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 864 | @UnsupportedAppUsage |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 865 | public boolean hasIPv4Address() { |
| 866 | for (LinkAddress address : mLinkAddresses) { |
Hugo Benichi | bd87a39 | 2017-10-10 16:29:06 +0900 | [diff] [blame] | 867 | if (address.getAddress() instanceof Inet4Address) { |
| 868 | return true; |
| 869 | } |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 870 | } |
| 871 | return false; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 874 | /** |
Lorenzo Colitti | 87cfc70 | 2015-07-27 16:35:33 +0900 | [diff] [blame] | 875 | * Returns true if this link or any of its stacked interfaces has an IPv4 address. |
| 876 | * |
| 877 | * @return {@code true} if there is an IPv4 address, {@code false} otherwise. |
| 878 | */ |
| 879 | private boolean hasIPv4AddressOnInterface(String iface) { |
Lorenzo Colitti | 89b6392 | 2015-07-30 23:41:43 +0900 | [diff] [blame] | 880 | // mIfaceName can be null. |
| 881 | return (Objects.equals(iface, mIfaceName) && hasIPv4Address()) || |
Lorenzo Colitti | 87cfc70 | 2015-07-27 16:35:33 +0900 | [diff] [blame] | 882 | (iface != null && mStackedLinks.containsKey(iface) && |
| 883 | mStackedLinks.get(iface).hasIPv4Address()); |
| 884 | } |
| 885 | |
| 886 | /** |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 887 | * Returns true if this link has a global preferred IPv6 address. |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 888 | * |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 889 | * @return {@code true} if there is a global preferred IPv6 address, {@code false} otherwise. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 890 | * @hide |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 891 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 892 | @UnsupportedAppUsage |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 893 | public boolean hasGlobalIPv6Address() { |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 894 | for (LinkAddress address : mLinkAddresses) { |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 895 | if (address.getAddress() instanceof Inet6Address && address.isGlobalPreferred()) { |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 896 | return true; |
| 897 | } |
| 898 | } |
| 899 | return false; |
| 900 | } |
| 901 | |
| 902 | /** |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 903 | * Returns true if this link has an IPv4 default route. |
| 904 | * |
| 905 | * @return {@code true} if there is an IPv4 default route, {@code false} otherwise. |
| 906 | * @hide |
| 907 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 908 | @UnsupportedAppUsage |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 909 | public boolean hasIPv4DefaultRoute() { |
| 910 | for (RouteInfo r : mRoutes) { |
Hugo Benichi | bd87a39 | 2017-10-10 16:29:06 +0900 | [diff] [blame] | 911 | if (r.isIPv4Default()) { |
| 912 | return true; |
| 913 | } |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 914 | } |
| 915 | return false; |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * Returns true if this link has an IPv6 default route. |
| 920 | * |
| 921 | * @return {@code true} if there is an IPv6 default route, {@code false} otherwise. |
| 922 | * @hide |
| 923 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 924 | @UnsupportedAppUsage |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 925 | public boolean hasIPv6DefaultRoute() { |
| 926 | for (RouteInfo r : mRoutes) { |
Hugo Benichi | bd87a39 | 2017-10-10 16:29:06 +0900 | [diff] [blame] | 927 | if (r.isIPv6Default()) { |
| 928 | return true; |
| 929 | } |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 930 | } |
| 931 | return false; |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * Returns true if this link has an IPv4 DNS server. |
| 936 | * |
| 937 | * @return {@code true} if there is an IPv4 DNS server, {@code false} otherwise. |
| 938 | * @hide |
| 939 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 940 | @UnsupportedAppUsage |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 941 | public boolean hasIPv4DnsServer() { |
| 942 | for (InetAddress ia : mDnses) { |
Hugo Benichi | bd87a39 | 2017-10-10 16:29:06 +0900 | [diff] [blame] | 943 | if (ia instanceof Inet4Address) { |
| 944 | return true; |
| 945 | } |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 946 | } |
| 947 | return false; |
| 948 | } |
| 949 | |
| 950 | /** |
| 951 | * Returns true if this link has an IPv6 DNS server. |
| 952 | * |
| 953 | * @return {@code true} if there is an IPv6 DNS server, {@code false} otherwise. |
| 954 | * @hide |
| 955 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 956 | @UnsupportedAppUsage |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 957 | public boolean hasIPv6DnsServer() { |
| 958 | for (InetAddress ia : mDnses) { |
Hugo Benichi | bd87a39 | 2017-10-10 16:29:06 +0900 | [diff] [blame] | 959 | if (ia instanceof Inet6Address) { |
| 960 | return true; |
| 961 | } |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 962 | } |
| 963 | return false; |
| 964 | } |
| 965 | |
| 966 | /** |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 967 | * Returns true if this link is provisioned for global IPv4 connectivity. |
| 968 | * This requires an IP address, default route, and DNS server. |
| 969 | * |
| 970 | * @return {@code true} if the link is provisioned, {@code false} otherwise. |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 971 | * @hide |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 972 | */ |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 973 | public boolean isIPv4Provisioned() { |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 974 | return (hasIPv4Address() && |
| 975 | hasIPv4DefaultRoute() && |
| 976 | hasIPv4DnsServer()); |
| 977 | } |
| 978 | |
| 979 | /** |
| 980 | * Returns true if this link is provisioned for global IPv6 connectivity. |
| 981 | * This requires an IP address, default route, and DNS server. |
| 982 | * |
| 983 | * @return {@code true} if the link is provisioned, {@code false} otherwise. |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 984 | * @hide |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 985 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 986 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 987 | public boolean isIPv6Provisioned() { |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 988 | return (hasGlobalIPv6Address() && |
| 989 | hasIPv6DefaultRoute() && |
| 990 | hasIPv6DnsServer()); |
| 991 | } |
| 992 | |
| 993 | /** |
| 994 | * Returns true if this link is provisioned for global connectivity, |
| 995 | * for at least one Internet Protocol family. |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 996 | * |
| 997 | * @return {@code true} if the link is provisioned, {@code false} otherwise. |
| 998 | * @hide |
| 999 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1000 | @UnsupportedAppUsage |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1001 | public boolean isProvisioned() { |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 1002 | return (isIPv4Provisioned() || isIPv6Provisioned()); |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /** |
Erik Kline | b36a313 | 2015-06-26 19:21:34 +0900 | [diff] [blame] | 1006 | * Evaluate whether the {@link InetAddress} is considered reachable. |
| 1007 | * |
| 1008 | * @return {@code true} if the given {@link InetAddress} is considered reachable, |
| 1009 | * {@code false} otherwise. |
| 1010 | * @hide |
| 1011 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1012 | @UnsupportedAppUsage |
Erik Kline | b36a313 | 2015-06-26 19:21:34 +0900 | [diff] [blame] | 1013 | public boolean isReachable(InetAddress ip) { |
| 1014 | final List<RouteInfo> allRoutes = getAllRoutes(); |
| 1015 | // If we don't have a route to this IP address, it's not reachable. |
| 1016 | final RouteInfo bestRoute = RouteInfo.selectBestRoute(allRoutes, ip); |
| 1017 | if (bestRoute == null) { |
| 1018 | return false; |
| 1019 | } |
| 1020 | |
| 1021 | // TODO: better source address evaluation for destination addresses. |
| 1022 | |
| 1023 | if (ip instanceof Inet4Address) { |
| 1024 | // For IPv4, it suffices for now to simply have any address. |
Lorenzo Colitti | 87cfc70 | 2015-07-27 16:35:33 +0900 | [diff] [blame] | 1025 | return hasIPv4AddressOnInterface(bestRoute.getInterface()); |
Erik Kline | b36a313 | 2015-06-26 19:21:34 +0900 | [diff] [blame] | 1026 | } else if (ip instanceof Inet6Address) { |
| 1027 | if (ip.isLinkLocalAddress()) { |
| 1028 | // For now, just make sure link-local destinations have |
| 1029 | // scopedIds set, since transmits will generally fail otherwise. |
| 1030 | // TODO: verify it matches the ifindex of one of the interfaces. |
| 1031 | return (((Inet6Address)ip).getScopeId() != 0); |
| 1032 | } else { |
| 1033 | // For non-link-local destinations check that either the best route |
| 1034 | // is directly connected or that some global preferred address exists. |
| 1035 | // TODO: reconsider all cases (disconnected ULA networks, ...). |
| 1036 | return (!bestRoute.hasGateway() || hasGlobalIPv6Address()); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | return false; |
| 1041 | } |
| 1042 | |
| 1043 | /** |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1044 | * Compares this {@code LinkProperties} interface name against the target |
| 1045 | * |
| 1046 | * @param target LinkProperties to compare. |
| 1047 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1048 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1049 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1050 | @UnsupportedAppUsage |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1051 | public boolean isIdenticalInterfaceName(LinkProperties target) { |
| 1052 | return TextUtils.equals(getInterfaceName(), target.getInterfaceName()); |
| 1053 | } |
| 1054 | |
| 1055 | /** |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 1056 | * Compares this {@code LinkProperties} interface addresses against the target |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1057 | * |
| 1058 | * @param target LinkProperties to compare. |
| 1059 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1060 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1061 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1062 | @UnsupportedAppUsage |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1063 | public boolean isIdenticalAddresses(LinkProperties target) { |
| 1064 | Collection<InetAddress> targetAddresses = target.getAddresses(); |
| 1065 | Collection<InetAddress> sourceAddresses = getAddresses(); |
| 1066 | return (sourceAddresses.size() == targetAddresses.size()) ? |
| 1067 | sourceAddresses.containsAll(targetAddresses) : false; |
| 1068 | } |
| 1069 | |
| 1070 | /** |
| 1071 | * Compares this {@code LinkProperties} DNS addresses against the target |
| 1072 | * |
| 1073 | * @param target LinkProperties to compare. |
| 1074 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1075 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1076 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1077 | @UnsupportedAppUsage |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1078 | public boolean isIdenticalDnses(LinkProperties target) { |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 1079 | Collection<InetAddress> targetDnses = target.getDnsServers(); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 1080 | String targetDomains = target.getDomains(); |
| 1081 | if (mDomains == null) { |
| 1082 | if (targetDomains != null) return false; |
| 1083 | } else { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1084 | if (!mDomains.equals(targetDomains)) return false; |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 1085 | } |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1086 | return (mDnses.size() == targetDnses.size()) ? |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1087 | mDnses.containsAll(targetDnses) : false; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | /** |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1091 | * Compares this {@code LinkProperties} private DNS settings against the |
| 1092 | * target. |
| 1093 | * |
| 1094 | * @param target LinkProperties to compare. |
| 1095 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1096 | * @hide |
| 1097 | */ |
| 1098 | public boolean isIdenticalPrivateDns(LinkProperties target) { |
| 1099 | return (isPrivateDnsActive() == target.isPrivateDnsActive() |
| 1100 | && TextUtils.equals(getPrivateDnsServerName(), |
| 1101 | target.getPrivateDnsServerName())); |
| 1102 | } |
| 1103 | |
| 1104 | /** |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1105 | * Compares this {@code LinkProperties} validated private DNS addresses against |
| 1106 | * the target |
| 1107 | * |
| 1108 | * @param target LinkProperties to compare. |
| 1109 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1110 | * @hide |
| 1111 | */ |
| 1112 | public boolean isIdenticalValidatedPrivateDnses(LinkProperties target) { |
| 1113 | Collection<InetAddress> targetDnses = target.getValidatedPrivateDnsServers(); |
| 1114 | return (mValidatedPrivateDnses.size() == targetDnses.size()) |
| 1115 | ? mValidatedPrivateDnses.containsAll(targetDnses) : false; |
| 1116 | } |
| 1117 | |
| 1118 | /** |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1119 | * Compares this {@code LinkProperties} Routes against the target |
| 1120 | * |
| 1121 | * @param target LinkProperties to compare. |
| 1122 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1123 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1124 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1125 | @UnsupportedAppUsage |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1126 | public boolean isIdenticalRoutes(LinkProperties target) { |
| 1127 | Collection<RouteInfo> targetRoutes = target.getRoutes(); |
| 1128 | return (mRoutes.size() == targetRoutes.size()) ? |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1129 | mRoutes.containsAll(targetRoutes) : false; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /** |
| 1133 | * Compares this {@code LinkProperties} HttpProxy against the target |
| 1134 | * |
| 1135 | * @param target LinkProperties to compare. |
| 1136 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1137 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1138 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1139 | @UnsupportedAppUsage |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1140 | public boolean isIdenticalHttpProxy(LinkProperties target) { |
| 1141 | return getHttpProxy() == null ? target.getHttpProxy() == null : |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1142 | getHttpProxy().equals(target.getHttpProxy()); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1143 | } |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1144 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1145 | /** |
| 1146 | * Compares this {@code LinkProperties} stacked links against the target |
| 1147 | * |
| 1148 | * @param target LinkProperties to compare. |
| 1149 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1150 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1151 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1152 | @UnsupportedAppUsage |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1153 | public boolean isIdenticalStackedLinks(LinkProperties target) { |
Lorenzo Colitti | 213f98b | 2013-04-01 10:47:43 +0900 | [diff] [blame] | 1154 | if (!mStackedLinks.keySet().equals(target.mStackedLinks.keySet())) { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1155 | return false; |
| 1156 | } |
| 1157 | for (LinkProperties stacked : mStackedLinks.values()) { |
| 1158 | // Hashtable values can never be null. |
| 1159 | String iface = stacked.getInterfaceName(); |
| 1160 | if (!stacked.equals(target.mStackedLinks.get(iface))) { |
| 1161 | return false; |
| 1162 | } |
| 1163 | } |
| 1164 | return true; |
| 1165 | } |
| 1166 | |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1167 | /** |
| 1168 | * Compares this {@code LinkProperties} MTU against the target |
| 1169 | * |
Ying Wang | d57de6a | 2013-09-06 22:53:16 -0700 | [diff] [blame] | 1170 | * @param target LinkProperties to compare. |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1171 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1172 | * @hide |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1173 | */ |
| 1174 | public boolean isIdenticalMtu(LinkProperties target) { |
| 1175 | return getMtu() == target.getMtu(); |
| 1176 | } |
| 1177 | |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 1178 | /** |
| 1179 | * Compares this {@code LinkProperties} Tcp buffer sizes against the target. |
| 1180 | * |
| 1181 | * @param target LinkProperties to compare. |
| 1182 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1183 | * @hide |
| 1184 | */ |
| 1185 | public boolean isIdenticalTcpBufferSizes(LinkProperties target) { |
| 1186 | return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes); |
| 1187 | } |
| 1188 | |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1189 | /** |
| 1190 | * Compares this {@code LinkProperties} instance against the target |
| 1191 | * LinkProperties in {@code obj}. Two LinkPropertieses are equal if |
| 1192 | * all their fields are equal in values. |
| 1193 | * |
| 1194 | * For collection fields, such as mDnses, containsAll() is used to check |
| 1195 | * if two collections contains the same elements, independent of order. |
| 1196 | * There are two thoughts regarding containsAll() |
| 1197 | * 1. Duplicated elements. eg, (A, B, B) and (A, A, B) are equal. |
| 1198 | * 2. Worst case performance is O(n^2). |
| 1199 | * |
| 1200 | * @param obj the object to be tested for equality. |
| 1201 | * @return {@code true} if both objects are equal, {@code false} otherwise. |
| 1202 | */ |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1203 | @Override |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1204 | public boolean equals(Object obj) { |
| 1205 | if (this == obj) return true; |
| 1206 | |
| 1207 | if (!(obj instanceof LinkProperties)) return false; |
| 1208 | |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1209 | LinkProperties target = (LinkProperties) obj; |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1210 | /* |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1211 | * This method does not check that stacked interfaces are equal, because |
| 1212 | * stacked interfaces are not so much a property of the link as a |
| 1213 | * description of connections between links. |
| 1214 | */ |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1215 | return isIdenticalInterfaceName(target) |
| 1216 | && isIdenticalAddresses(target) |
| 1217 | && isIdenticalDnses(target) |
| 1218 | && isIdenticalPrivateDns(target) |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1219 | && isIdenticalValidatedPrivateDnses(target) |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1220 | && isIdenticalRoutes(target) |
| 1221 | && isIdenticalHttpProxy(target) |
| 1222 | && isIdenticalStackedLinks(target) |
| 1223 | && isIdenticalMtu(target) |
| 1224 | && isIdenticalTcpBufferSizes(target); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1225 | } |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1226 | |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1227 | /** |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1228 | * Compares the addresses in this LinkProperties with another |
| 1229 | * LinkProperties, examining only addresses on the base link. |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1230 | * |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1231 | * @param target a LinkProperties with the new list of addresses |
| 1232 | * @return the differences between the addresses. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1233 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1234 | */ |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1235 | public CompareResult<LinkAddress> compareAddresses(LinkProperties target) { |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1236 | /* |
| 1237 | * Duplicate the LinkAddresses into removed, we will be removing |
| 1238 | * address which are common between mLinkAddresses and target |
| 1239 | * leaving the addresses that are different. And address which |
| 1240 | * are in target but not in mLinkAddresses are placed in the |
| 1241 | * addedAddresses. |
| 1242 | */ |
Rubin Xu | 2fc72f7 | 2017-08-22 16:35:52 +0100 | [diff] [blame] | 1243 | return new CompareResult<>(mLinkAddresses, |
| 1244 | target != null ? target.getLinkAddresses() : null); |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1247 | /** |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1248 | * Compares the DNS addresses in this LinkProperties with another |
| 1249 | * LinkProperties, examining only DNS addresses on the base link. |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1250 | * |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1251 | * @param target a LinkProperties with the new list of dns addresses |
| 1252 | * @return the differences between the DNS addresses. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1253 | * @hide |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1254 | */ |
| 1255 | public CompareResult<InetAddress> compareDnses(LinkProperties target) { |
| 1256 | /* |
| 1257 | * Duplicate the InetAddresses into removed, we will be removing |
| 1258 | * dns address which are common between mDnses and target |
| 1259 | * leaving the addresses that are different. And dns address which |
| 1260 | * are in target but not in mDnses are placed in the |
| 1261 | * addedAddresses. |
| 1262 | */ |
Rubin Xu | 2fc72f7 | 2017-08-22 16:35:52 +0100 | [diff] [blame] | 1263 | return new CompareResult<>(mDnses, target != null ? target.getDnsServers() : null); |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | /** |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1267 | * Compares the validated private DNS addresses in this LinkProperties with another |
| 1268 | * LinkProperties. |
| 1269 | * |
| 1270 | * @param target a LinkProperties with the new list of validated private dns addresses |
| 1271 | * @return the differences between the DNS addresses. |
| 1272 | * @hide |
| 1273 | */ |
| 1274 | public CompareResult<InetAddress> compareValidatedPrivateDnses(LinkProperties target) { |
| 1275 | return new CompareResult<>(mValidatedPrivateDnses, |
| 1276 | target != null ? target.getValidatedPrivateDnsServers() : null); |
| 1277 | } |
| 1278 | |
| 1279 | /** |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1280 | * Compares all routes in this LinkProperties with another LinkProperties, |
| 1281 | * examining both the the base link and all stacked links. |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1282 | * |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1283 | * @param target a LinkProperties with the new list of routes |
| 1284 | * @return the differences between the routes. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1285 | * @hide |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1286 | */ |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1287 | public CompareResult<RouteInfo> compareAllRoutes(LinkProperties target) { |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1288 | /* |
| 1289 | * Duplicate the RouteInfos into removed, we will be removing |
Lorenzo Colitti | 1994bc1 | 2013-03-08 19:11:40 -0800 | [diff] [blame] | 1290 | * routes which are common between mRoutes and target |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1291 | * leaving the routes that are different. And route address which |
| 1292 | * are in target but not in mRoutes are placed in added. |
| 1293 | */ |
Rubin Xu | 2fc72f7 | 2017-08-22 16:35:52 +0100 | [diff] [blame] | 1294 | return new CompareResult<>(getAllRoutes(), target != null ? target.getAllRoutes() : null); |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
Paul Jensen | 992f252 | 2014-04-28 10:33:11 -0400 | [diff] [blame] | 1297 | /** |
| 1298 | * Compares all interface names in this LinkProperties with another |
| 1299 | * LinkProperties, examining both the the base link and all stacked links. |
| 1300 | * |
| 1301 | * @param target a LinkProperties with the new list of interface names |
| 1302 | * @return the differences between the interface names. |
| 1303 | * @hide |
| 1304 | */ |
| 1305 | public CompareResult<String> compareAllInterfaceNames(LinkProperties target) { |
| 1306 | /* |
| 1307 | * Duplicate the interface names into removed, we will be removing |
| 1308 | * interface names which are common between this and target |
| 1309 | * leaving the interface names that are different. And interface names which |
| 1310 | * are in target but not in this are placed in added. |
| 1311 | */ |
Rubin Xu | 2fc72f7 | 2017-08-22 16:35:52 +0100 | [diff] [blame] | 1312 | return new CompareResult<>(getAllInterfaceNames(), |
| 1313 | target != null ? target.getAllInterfaceNames() : null); |
Paul Jensen | 992f252 | 2014-04-28 10:33:11 -0400 | [diff] [blame] | 1314 | } |
| 1315 | |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1316 | |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1317 | /** |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1318 | * Generate hashcode based on significant fields |
| 1319 | * |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1320 | * Equal objects must produce the same hash code, while unequal objects |
| 1321 | * may have the same hash codes. |
| 1322 | */ |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1323 | @Override |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1324 | public int hashCode() { |
| 1325 | return ((null == mIfaceName) ? 0 : mIfaceName.hashCode() |
| 1326 | + mLinkAddresses.size() * 31 |
| 1327 | + mDnses.size() * 37 |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1328 | + mValidatedPrivateDnses.size() * 61 |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 1329 | + ((null == mDomains) ? 0 : mDomains.hashCode()) |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 1330 | + mRoutes.size() * 41 |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1331 | + ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode()) |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1332 | + mStackedLinks.hashCode() * 47) |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 1333 | + mMtu * 51 |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1334 | + ((null == mTcpBufferSizes) ? 0 : mTcpBufferSizes.hashCode()) |
| 1335 | + (mUsePrivateDns ? 57 : 0) |
| 1336 | + ((null == mPrivateDnsServerName) ? 0 : mPrivateDnsServerName.hashCode()); |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1339 | /** |
| 1340 | * Implement the Parcelable interface. |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1341 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 1342 | public void writeToParcel(Parcel dest, int flags) { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1343 | dest.writeString(getInterfaceName()); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 1344 | dest.writeInt(mLinkAddresses.size()); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1345 | for (LinkAddress linkAddress : mLinkAddresses) { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 1346 | dest.writeParcelable(linkAddress, flags); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1347 | } |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 1348 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1349 | dest.writeInt(mDnses.size()); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1350 | for (InetAddress d : mDnses) { |
| 1351 | dest.writeByteArray(d.getAddress()); |
| 1352 | } |
| 1353 | dest.writeInt(mValidatedPrivateDnses.size()); |
| 1354 | for (InetAddress d : mValidatedPrivateDnses) { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1355 | dest.writeByteArray(d.getAddress()); |
| 1356 | } |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1357 | dest.writeBoolean(mUsePrivateDns); |
| 1358 | dest.writeString(mPrivateDnsServerName); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 1359 | dest.writeString(mDomains); |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1360 | dest.writeInt(mMtu); |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 1361 | dest.writeString(mTcpBufferSizes); |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 1362 | dest.writeInt(mRoutes.size()); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1363 | for (RouteInfo route : mRoutes) { |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 1364 | dest.writeParcelable(route, flags); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1365 | } |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 1366 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1367 | if (mHttpProxy != null) { |
| 1368 | dest.writeByte((byte)1); |
| 1369 | dest.writeParcelable(mHttpProxy, flags); |
| 1370 | } else { |
| 1371 | dest.writeByte((byte)0); |
| 1372 | } |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1373 | ArrayList<LinkProperties> stackedLinks = new ArrayList<>(mStackedLinks.values()); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1374 | dest.writeList(stackedLinks); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | /** |
| 1378 | * Implement the Parcelable interface. |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1379 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 1380 | public static final Creator<LinkProperties> CREATOR = |
| 1381 | new Creator<LinkProperties>() { |
| 1382 | public LinkProperties createFromParcel(Parcel in) { |
| 1383 | LinkProperties netProp = new LinkProperties(); |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 1384 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1385 | String iface = in.readString(); |
| 1386 | if (iface != null) { |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 1387 | netProp.setInterfaceName(iface); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1388 | } |
| 1389 | int addressCount = in.readInt(); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1390 | for (int i = 0; i < addressCount; i++) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1391 | netProp.addLinkAddress(in.readParcelable(null)); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1392 | } |
| 1393 | addressCount = in.readInt(); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1394 | for (int i = 0; i < addressCount; i++) { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1395 | try { |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 1396 | netProp.addDnsServer(InetAddress.getByAddress(in.createByteArray())); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1397 | } catch (UnknownHostException e) { } |
| 1398 | } |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1399 | addressCount = in.readInt(); |
| 1400 | for (int i = 0; i < addressCount; i++) { |
| 1401 | try { |
| 1402 | netProp.addValidatedPrivateDnsServer( |
| 1403 | InetAddress.getByAddress(in.createByteArray())); |
| 1404 | } catch (UnknownHostException e) { } |
| 1405 | } |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1406 | netProp.setUsePrivateDns(in.readBoolean()); |
| 1407 | netProp.setPrivateDnsServerName(in.readString()); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 1408 | netProp.setDomains(in.readString()); |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1409 | netProp.setMtu(in.readInt()); |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 1410 | netProp.setTcpBufferSizes(in.readString()); |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 1411 | addressCount = in.readInt(); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1412 | for (int i = 0; i < addressCount; i++) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1413 | netProp.addRoute(in.readParcelable(null)); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1414 | } |
| 1415 | if (in.readByte() == 1) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1416 | netProp.setHttpProxy(in.readParcelable(null)); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1417 | } |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1418 | ArrayList<LinkProperties> stackedLinks = new ArrayList<LinkProperties>(); |
| 1419 | in.readList(stackedLinks, LinkProperties.class.getClassLoader()); |
| 1420 | for (LinkProperties stackedLink: stackedLinks) { |
| 1421 | netProp.addStackedLink(stackedLink); |
| 1422 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1423 | return netProp; |
| 1424 | } |
| 1425 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 1426 | public LinkProperties[] newArray(int size) { |
| 1427 | return new LinkProperties[size]; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1428 | } |
| 1429 | }; |
w19976 | 15afd81 | 2014-08-05 15:18:11 -0700 | [diff] [blame] | 1430 | |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1431 | /** |
| 1432 | * Check the valid MTU range based on IPv4 or IPv6. |
| 1433 | * @hide |
| 1434 | */ |
| 1435 | public static boolean isValidMtu(int mtu, boolean ipv6) { |
| 1436 | if (ipv6) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1437 | return mtu >= MIN_MTU_V6 && mtu <= MAX_MTU; |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1438 | } else { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1439 | return mtu >= MIN_MTU && mtu <= MAX_MTU; |
w19976 | 15afd81 | 2014-08-05 15:18:11 -0700 | [diff] [blame] | 1440 | } |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1441 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1442 | } |