Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 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 com.android.server.connectivity; |
| 18 | |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 19 | import android.net.InterfaceConfiguration; |
Lorenzo Colitti | 853d741 | 2016-03-03 17:17:29 +0900 | [diff] [blame] | 20 | import android.net.ConnectivityManager; |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 21 | import android.net.LinkAddress; |
| 22 | import android.net.LinkProperties; |
Erik Kline | 3c18216 | 2017-09-21 17:28:10 +0900 | [diff] [blame] | 23 | import android.net.NetworkInfo; |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 24 | import android.net.RouteInfo; |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 25 | import android.os.INetworkManagementService; |
| 26 | import android.os.RemoteException; |
| 27 | import android.util.Slog; |
| 28 | |
Hugo Benichi | 50d46a4 | 2017-08-31 14:29:51 +0000 | [diff] [blame] | 29 | import com.android.internal.util.ArrayUtils; |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 30 | import com.android.server.net.BaseNetworkObserver; |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 31 | |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 32 | import java.net.Inet4Address; |
| 33 | import java.util.Objects; |
| 34 | |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 35 | /** |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 36 | * Class to manage a 464xlat CLAT daemon. Nat464Xlat is not thread safe and should be manipulated |
| 37 | * from a consistent and unique thread context. It is the responsibility of ConnectivityService to |
| 38 | * call into this class from its own Handler thread. |
Hugo Benichi | b577d65 | 2017-06-27 15:13:20 +0900 | [diff] [blame] | 39 | * |
| 40 | * @hide |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 41 | */ |
| 42 | public class Nat464Xlat extends BaseNetworkObserver { |
Hugo Benichi | b577d65 | 2017-06-27 15:13:20 +0900 | [diff] [blame] | 43 | private static final String TAG = Nat464Xlat.class.getSimpleName(); |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 44 | |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 45 | // This must match the interface prefix in clatd.c. |
| 46 | private static final String CLAT_PREFIX = "v4-"; |
| 47 | |
Erik Kline | 3c18216 | 2017-09-21 17:28:10 +0900 | [diff] [blame] | 48 | // The network types on which we will start clatd, |
Hugo Benichi | b577d65 | 2017-06-27 15:13:20 +0900 | [diff] [blame] | 49 | // allowing clat only on networks for which we can support IPv6-only. |
Lorenzo Colitti | 853d741 | 2016-03-03 17:17:29 +0900 | [diff] [blame] | 50 | private static final int[] NETWORK_TYPES = { |
Erik Kline | 3c18216 | 2017-09-21 17:28:10 +0900 | [diff] [blame] | 51 | ConnectivityManager.TYPE_MOBILE, |
| 52 | ConnectivityManager.TYPE_WIFI, |
| 53 | ConnectivityManager.TYPE_ETHERNET, |
| 54 | }; |
| 55 | |
| 56 | // The network states in which running clatd is supported. |
| 57 | private static final NetworkInfo.State[] NETWORK_STATES = { |
| 58 | NetworkInfo.State.CONNECTED, |
| 59 | NetworkInfo.State.SUSPENDED, |
Lorenzo Colitti | 853d741 | 2016-03-03 17:17:29 +0900 | [diff] [blame] | 60 | }; |
| 61 | |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 62 | private final INetworkManagementService mNMService; |
| 63 | |
Lorenzo Colitti | e21a26b | 2014-10-28 15:24:03 +0900 | [diff] [blame] | 64 | // The network we're running on, and its type. |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 65 | private final NetworkAgentInfo mNetwork; |
| 66 | |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 67 | private enum State { |
| 68 | IDLE, // start() not called. Base iface and stacked iface names are null. |
| 69 | STARTING, // start() called. Base iface and stacked iface names are known. |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 70 | RUNNING, // start() called, and the stacked iface is known to be up. |
| 71 | STOPPING; // stop() called, this Nat464Xlat is still registered as a network observer for |
| 72 | // the stacked interface. |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 73 | } |
| 74 | |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 75 | private String mBaseIface; |
| 76 | private String mIface; |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 77 | private State mState = State.IDLE; |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 78 | |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 79 | public Nat464Xlat(INetworkManagementService nmService, NetworkAgentInfo nai) { |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 80 | mNMService = nmService; |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 81 | mNetwork = nai; |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
Paul Jensen | 3b75982 | 2014-05-13 11:44:01 -0400 | [diff] [blame] | 85 | * Determines whether a network requires clat. |
| 86 | * @param network the NetworkAgentInfo corresponding to the network. |
| 87 | * @return true if the network requires clat, false otherwise. |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 88 | */ |
Lorenzo Colitti | 1df5fa5 | 2014-09-20 13:47:47 +0900 | [diff] [blame] | 89 | public static boolean requiresClat(NetworkAgentInfo nai) { |
Hugo Benichi | b577d65 | 2017-06-27 15:13:20 +0900 | [diff] [blame] | 90 | // TODO: migrate to NetworkCapabilities.TRANSPORT_*. |
Hugo Benichi | b577d65 | 2017-06-27 15:13:20 +0900 | [diff] [blame] | 91 | final boolean supported = ArrayUtils.contains(NETWORK_TYPES, nai.networkInfo.getType()); |
Erik Kline | 3c18216 | 2017-09-21 17:28:10 +0900 | [diff] [blame] | 92 | final boolean connected = ArrayUtils.contains(NETWORK_STATES, nai.networkInfo.getState()); |
Hugo Benichi | b577d65 | 2017-06-27 15:13:20 +0900 | [diff] [blame] | 93 | // We only run clat on networks that don't have a native IPv4 address. |
Lorenzo Colitti | 1df5fa5 | 2014-09-20 13:47:47 +0900 | [diff] [blame] | 94 | final boolean hasIPv4Address = |
Hugo Benichi | b577d65 | 2017-06-27 15:13:20 +0900 | [diff] [blame] | 95 | (nai.linkProperties != null) && nai.linkProperties.hasIPv4Address(); |
| 96 | return supported && connected && !hasIPv4Address; |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 97 | } |
| 98 | |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 99 | /** |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 100 | * @return true if clatd has been started and has not yet stopped. |
| 101 | * A true result corresponds to internal states STARTING and RUNNING. |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 102 | */ |
| 103 | public boolean isStarted() { |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 104 | return mState != State.IDLE; |
| 105 | } |
| 106 | |
| 107 | /** |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 108 | * @return true if clatd has been started but the stacked interface is not yet up. |
| 109 | */ |
| 110 | public boolean isStarting() { |
| 111 | return mState == State.STARTING; |
| 112 | } |
| 113 | |
| 114 | /** |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 115 | * @return true if clatd has been started and the stacked interface is up. |
| 116 | */ |
| 117 | public boolean isRunning() { |
| 118 | return mState == State.RUNNING; |
| 119 | } |
| 120 | |
| 121 | /** |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 122 | * @return true if clatd has been stopped. |
| 123 | */ |
| 124 | public boolean isStopping() { |
| 125 | return mState == State.STOPPING; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Start clatd, register this Nat464Xlat as a network observer for the stacked interface, |
| 130 | * and set internal state. |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 131 | */ |
| 132 | private void enterStartingState(String baseIface) { |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 133 | try { |
| 134 | mNMService.registerObserver(this); |
| 135 | } catch(RemoteException e) { |
| 136 | Slog.e(TAG, |
| 137 | "startClat: Can't register interface observer for clat on " + mNetwork.name()); |
| 138 | return; |
| 139 | } |
| 140 | try { |
| 141 | mNMService.startClatd(baseIface); |
| 142 | } catch(RemoteException|IllegalStateException e) { |
| 143 | Slog.e(TAG, "Error starting clatd on " + baseIface, e); |
| 144 | } |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 145 | mIface = CLAT_PREFIX + baseIface; |
| 146 | mBaseIface = baseIface; |
| 147 | mState = State.STARTING; |
Lorenzo Colitti | d2ef1e5 | 2013-03-28 14:13:43 +0900 | [diff] [blame] | 148 | } |
| 149 | |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 150 | /** |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 151 | * Enter running state just after getting confirmation that the stacked interface is up, and |
| 152 | * turn ND offload off if on WiFi. |
| 153 | */ |
| 154 | private void enterRunningState() { |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 155 | mState = State.RUNNING; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Stop clatd, and turn ND offload on if it had been turned off. |
| 160 | */ |
| 161 | private void enterStoppingState() { |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 162 | try { |
| 163 | mNMService.stopClatd(mBaseIface); |
| 164 | } catch(RemoteException|IllegalStateException e) { |
| 165 | Slog.e(TAG, "Error stopping clatd on " + mBaseIface, e); |
| 166 | } |
| 167 | |
| 168 | mState = State.STOPPING; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Unregister as a base observer for the stacked interface, and clear internal state. |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 173 | */ |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 174 | private void enterIdleState() { |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 175 | try { |
| 176 | mNMService.unregisterObserver(this); |
| 177 | } catch(RemoteException|IllegalStateException e) { |
| 178 | Slog.e(TAG, "Error unregistering clatd observer on " + mBaseIface, e); |
| 179 | } |
| 180 | |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 181 | mIface = null; |
| 182 | mBaseIface = null; |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 183 | mState = State.IDLE; |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 187 | * Starts the clat daemon. |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 188 | */ |
| 189 | public void start() { |
| 190 | if (isStarted()) { |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 191 | Slog.e(TAG, "startClat: already started"); |
| 192 | return; |
| 193 | } |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 194 | |
| 195 | if (mNetwork.linkProperties == null) { |
| 196 | Slog.e(TAG, "startClat: Can't start clat with null LinkProperties"); |
| 197 | return; |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 198 | } |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 199 | |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 200 | String baseIface = mNetwork.linkProperties.getInterfaceName(); |
| 201 | if (baseIface == null) { |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 202 | Slog.e(TAG, "startClat: Can't start clat on null interface"); |
| 203 | return; |
| 204 | } |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 205 | // TODO: should we only do this if mNMService.startClatd() succeeds? |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 206 | Slog.i(TAG, "Starting clatd on " + baseIface); |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 207 | enterStartingState(baseIface); |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /** |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 211 | * Stops the clat daemon. |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 212 | */ |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 213 | public void stop() { |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 214 | if (!isStarted()) { |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 215 | return; |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 216 | } |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 217 | Slog.i(TAG, "Stopping clatd on " + mBaseIface); |
Hugo Benichi | 50d46a4 | 2017-08-31 14:29:51 +0000 | [diff] [blame] | 218 | |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 219 | boolean wasStarting = isStarting(); |
| 220 | enterStoppingState(); |
| 221 | if (wasStarting) { |
| 222 | enterIdleState(); |
| 223 | } |
Paul Jensen | 3b75982 | 2014-05-13 11:44:01 -0400 | [diff] [blame] | 224 | } |
| 225 | |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 226 | /** |
| 227 | * Copies the stacked clat link in oldLp, if any, to the LinkProperties in mNetwork. |
| 228 | * This is necessary because the LinkProperties in mNetwork come from the transport layer, which |
| 229 | * has no idea that 464xlat is running on top of it. |
| 230 | */ |
| 231 | public void fixupLinkProperties(LinkProperties oldLp) { |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 232 | if (!isRunning()) { |
| 233 | return; |
| 234 | } |
| 235 | LinkProperties lp = mNetwork.linkProperties; |
| 236 | if (lp == null || lp.getAllInterfaceNames().contains(mIface)) { |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | Slog.d(TAG, "clatd running, updating NAI for " + mIface); |
| 241 | for (LinkProperties stacked: oldLp.getStackedLinks()) { |
| 242 | if (Objects.equals(mIface, stacked.getInterfaceName())) { |
| 243 | lp.addStackedLink(stacked); |
| 244 | return; |
Lorenzo Colitti | 1df5fa5 | 2014-09-20 13:47:47 +0900 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 249 | private LinkProperties makeLinkProperties(LinkAddress clatAddress) { |
| 250 | LinkProperties stacked = new LinkProperties(); |
| 251 | stacked.setInterfaceName(mIface); |
| 252 | |
| 253 | // Although the clat interface is a point-to-point tunnel, we don't |
| 254 | // point the route directly at the interface because some apps don't |
| 255 | // understand routes without gateways (see, e.g., http://b/9597256 |
| 256 | // http://b/9597516). Instead, set the next hop of the route to the |
| 257 | // clat IPv4 address itself (for those apps, it doesn't matter what |
| 258 | // the IP of the gateway is, only that there is one). |
| 259 | RouteInfo ipv4Default = new RouteInfo( |
| 260 | new LinkAddress(Inet4Address.ANY, 0), |
| 261 | clatAddress.getAddress(), mIface); |
| 262 | stacked.addRoute(ipv4Default); |
| 263 | stacked.addLinkAddress(clatAddress); |
| 264 | return stacked; |
| 265 | } |
| 266 | |
Lorenzo Colitti | e21a26b | 2014-10-28 15:24:03 +0900 | [diff] [blame] | 267 | private LinkAddress getLinkAddress(String iface) { |
| 268 | try { |
| 269 | InterfaceConfiguration config = mNMService.getInterfaceConfig(iface); |
| 270 | return config.getLinkAddress(); |
| 271 | } catch(RemoteException|IllegalStateException e) { |
| 272 | Slog.e(TAG, "Error getting link properties: " + e); |
| 273 | return null; |
| 274 | } |
| 275 | } |
| 276 | |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 277 | /** |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 278 | * Adds stacked link on base link and transitions to RUNNING state. |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 279 | */ |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 280 | private void handleInterfaceLinkStateChanged(String iface, boolean up) { |
| 281 | if (!isStarting() || !up || !Objects.equals(mIface, iface)) { |
Hugo Benichi | 50d46a4 | 2017-08-31 14:29:51 +0000 | [diff] [blame] | 282 | return; |
| 283 | } |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 284 | |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 285 | LinkAddress clatAddress = getLinkAddress(iface); |
| 286 | if (clatAddress == null) { |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 287 | Slog.e(TAG, "clatAddress was null for stacked iface " + iface); |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 288 | return; |
| 289 | } |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 290 | |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 291 | Slog.i(TAG, String.format("interface %s is up, adding stacked link %s on top of %s", |
| 292 | mIface, mIface, mBaseIface)); |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 293 | enterRunningState(); |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 294 | LinkProperties lp = new LinkProperties(mNetwork.linkProperties); |
| 295 | lp.addStackedLink(makeLinkProperties(clatAddress)); |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 296 | mNetwork.connService().handleUpdateLinkProperties(mNetwork, lp); |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 297 | } |
| 298 | |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 299 | /** |
| 300 | * Removes stacked link on base link and transitions to IDLE state. |
| 301 | */ |
| 302 | private void handleInterfaceRemoved(String iface) { |
| 303 | if (!Objects.equals(mIface, iface)) { |
Hugo Benichi | 50d46a4 | 2017-08-31 14:29:51 +0000 | [diff] [blame] | 304 | return; |
| 305 | } |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 306 | if (!isRunning() && !isStopping()) { |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 307 | return; |
| 308 | } |
| 309 | |
| 310 | Slog.i(TAG, "interface " + iface + " removed"); |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 311 | if (!isStopping()) { |
| 312 | // Ensure clatd is stopped if stop() has not been called: this likely means that clatd |
| 313 | // has crashed. |
| 314 | enterStoppingState(); |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 315 | } |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 316 | enterIdleState(); |
Hugo Benichi | ef50288 | 2017-09-01 01:23:32 +0000 | [diff] [blame] | 317 | LinkProperties lp = new LinkProperties(mNetwork.linkProperties); |
| 318 | lp.removeStackedLink(iface); |
| 319 | mNetwork.connService().handleUpdateLinkProperties(mNetwork, lp); |
| 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public void interfaceLinkStateChanged(String iface, boolean up) { |
| 324 | mNetwork.handler().post(() -> { handleInterfaceLinkStateChanged(iface, up); }); |
| 325 | } |
| 326 | |
| 327 | @Override |
| 328 | public void interfaceRemoved(String iface) { |
| 329 | mNetwork.handler().post(() -> { handleInterfaceRemoved(iface); }); |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 330 | } |
Hugo Benichi | b577d65 | 2017-06-27 15:13:20 +0900 | [diff] [blame] | 331 | |
| 332 | @Override |
| 333 | public String toString() { |
Hugo Benichi | 4f6f139 | 2017-06-29 14:04:13 +0900 | [diff] [blame] | 334 | return "mBaseIface: " + mBaseIface + ", mIface: " + mIface + ", mState: " + mState; |
Hugo Benichi | b577d65 | 2017-06-27 15:13:20 +0900 | [diff] [blame] | 335 | } |
Lorenzo Colitti | 9543946 | 2014-10-09 13:44:48 +0900 | [diff] [blame] | 336 | } |