diff options
author | Paul Jensen <pauljensen@google.com> | 2014-05-13 11:44:01 -0400 |
---|---|---|
committer | Lorenzo Colitti <lorenzo@google.com> | 2014-05-14 03:56:35 -0700 |
commit | 3b75982e39ed9370153ae7f238f1d6041b9506ed (patch) | |
tree | a6989357fad794d2b59a628f0cf519eb41b790f6 /services | |
parent | 7ef92576016aaa43e3488b6ddc213b7c1e52b118 (diff) | |
download | frameworks_base-3b75982e39ed9370153ae7f238f1d6041b9506ed.zip frameworks_base-3b75982e39ed9370153ae7f238f1d6041b9506ed.tar.gz frameworks_base-3b75982e39ed9370153ae7f238f1d6041b9506ed.tar.bz2 |
Get clatd/Nat464Xlat working with new NetworkAgents.
Change-Id: I65dfb59ce519a42bdb872940d229039b5403fd92
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/ConnectivityService.java | 45 | ||||
-rw-r--r-- | services/core/java/com/android/server/connectivity/Nat464Xlat.java | 63 |
2 files changed, 61 insertions, 47 deletions
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index a9d226e..71977d3 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -2486,26 +2486,6 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } - // Update 464xlat state. - NetworkStateTracker tracker = mNetTrackers[netType]; - if (mClat.requiresClat(netType, tracker)) { - - // If the connection was previously using clat, but is not using it now, stop the clat - // daemon. Normally, this happens automatically when the connection disconnects, but if - // the disconnect is not reported, or if the connection's LinkProperties changed for - // some other reason (e.g., handoff changes the IP addresses on the link), it would - // still be running. If it's not running, then stopping it is a no-op. - if (Nat464Xlat.isRunningClat(curLp) && !Nat464Xlat.isRunningClat(newLp)) { - mClat.stopClat(); - } - // If the link requires clat to be running, then start the daemon now. - if (mNetTrackers[netType].getNetworkInfo().isConnected()) { - mClat.startClat(tracker); - } else { - mClat.stopClat(); - } - } - // TODO: Temporary notifying upstread change to Tethering. // @see bug/4455071 /** Notify TetheringService if interface name has been changed. */ @@ -3073,7 +3053,8 @@ public class ConnectivityService extends IConnectivityManager.Stub { } notifyNetworkCallbacks(nai, NetworkCallbacks.LOST); nai.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_DISCONNECTED); - mNetworkAgentInfos.remove(nai); + mNetworkAgentInfos.remove(msg.replyTo); + updateClat(null, nai.linkProperties, nai); // Since we've lost the network, go through all the requests that // it was satisfying and see if any other factory can satisfy them. final ArrayList<NetworkAgentInfo> toActivate = new ArrayList<NetworkAgentInfo>(); @@ -5121,6 +5102,28 @@ public class ConnectivityService extends IConnectivityManager.Stub { // } updateRoutes(newLp, oldLp, netId); updateDnses(newLp, oldLp, netId); + updateClat(newLp, oldLp, networkAgent); + } + + private void updateClat(LinkProperties newLp, LinkProperties oldLp, NetworkAgentInfo na) { + // Update 464xlat state. + if (mClat.requiresClat(na)) { + + // If the connection was previously using clat, but is not using it now, stop the clat + // daemon. Normally, this happens automatically when the connection disconnects, but if + // the disconnect is not reported, or if the connection's LinkProperties changed for + // some other reason (e.g., handoff changes the IP addresses on the link), it would + // still be running. If it's not running, then stopping it is a no-op. + if (Nat464Xlat.isRunningClat(oldLp) && !Nat464Xlat.isRunningClat(newLp)) { + mClat.stopClat(); + } + // If the link requires clat to be running, then start the daemon now. + if (newLp != null && na.networkInfo.isConnected()) { + mClat.startClat(na); + } else { + mClat.stopClat(); + } + } } private void updateInterfaces(LinkProperties newLp, LinkProperties oldLp, int netId) { diff --git a/services/core/java/com/android/server/connectivity/Nat464Xlat.java b/services/core/java/com/android/server/connectivity/Nat464Xlat.java index a15d678..3884ab0 100644 --- a/services/core/java/com/android/server/connectivity/Nat464Xlat.java +++ b/services/core/java/com/android/server/connectivity/Nat464Xlat.java @@ -25,11 +25,12 @@ import android.net.IConnectivityManager; import android.net.InterfaceConfiguration; import android.net.LinkAddress; import android.net.LinkProperties; -import android.net.NetworkStateTracker; +import android.net.NetworkAgent; import android.net.NetworkUtils; import android.net.RouteInfo; import android.os.Handler; import android.os.Message; +import android.os.Messenger; import android.os.INetworkManagementService; import android.os.RemoteException; import android.util.Slog; @@ -45,15 +46,18 @@ public class Nat464Xlat extends BaseNetworkObserver { private Context mContext; private INetworkManagementService mNMService; private IConnectivityManager mConnService; - private NetworkStateTracker mTracker; - private Handler mHandler; - // Whether we started clatd and expect it to be running. private boolean mIsStarted; // Whether the clatd interface exists (i.e., clatd is running). private boolean mIsRunning; // The LinkProperties of the clat interface. private LinkProperties mLP; + // Current LinkProperties of the network. Includes mLP as a stacked link when clat is active. + private LinkProperties mBaseLP; + // ConnectivityService Handler for LinkProperties updates. + private Handler mHandler; + // Marker to connote which network we're augmenting. + private Messenger mNetworkMessenger; // This must match the interface name in clatd.conf. private static final String CLAT_INTERFACE_NAME = "clat4"; @@ -73,14 +77,13 @@ public class Nat464Xlat extends BaseNetworkObserver { } /** - * Determines whether an interface requires clat. - * @param netType the network type (one of the - * android.net.ConnectivityManager.TYPE_* constants) - * @param tracker the NetworkStateTracker corresponding to the network type. - * @return true if the interface requires clat, false otherwise. + * Determines whether a network requires clat. + * @param network the NetworkAgentInfo corresponding to the network. + * @return true if the network requires clat, false otherwise. */ - public boolean requiresClat(int netType, NetworkStateTracker tracker) { - LinkProperties lp = tracker.getLinkProperties(); + public boolean requiresClat(NetworkAgentInfo network) { + int netType = network.networkInfo.getType(); + LinkProperties lp = network.linkProperties; // Only support clat on mobile for now. Slog.d(TAG, "requiresClat: netType=" + netType + ", hasIPv4Address=" + lp.hasIPv4Address()); @@ -95,13 +98,18 @@ public class Nat464Xlat extends BaseNetworkObserver { * Starts the clat daemon. * @param lp The link properties of the interface to start clatd on. */ - public void startClat(NetworkStateTracker tracker) { + public void startClat(NetworkAgentInfo network) { + if (mNetworkMessenger != null && mNetworkMessenger != network.messenger) { + Slog.e(TAG, "startClat: too many networks requesting clat"); + return; + } + mNetworkMessenger = network.messenger; + LinkProperties lp = network.linkProperties; + mBaseLP = new LinkProperties(lp); if (mIsStarted) { Slog.e(TAG, "startClat: already started"); return; } - mTracker = tracker; - LinkProperties lp = mTracker.getLinkProperties(); String iface = lp.getInterfaceName(); Slog.i(TAG, "Starting clatd on " + iface + ", lp=" + lp); try { @@ -125,7 +133,8 @@ public class Nat464Xlat extends BaseNetworkObserver { } mIsStarted = false; mIsRunning = false; - mTracker = null; + mNetworkMessenger = null; + mBaseLP = null; mLP.clear(); } else { Slog.e(TAG, "stopClat: already stopped"); @@ -140,6 +149,14 @@ public class Nat464Xlat extends BaseNetworkObserver { return mIsRunning; } + private void updateConnectivityService() { + Message msg = mHandler.obtainMessage( + NetworkAgent.EVENT_NETWORK_PROPERTIES_CHANGED, mBaseLP); + msg.replyTo = mNetworkMessenger; + Slog.i(TAG, "sending message to ConnectivityService: " + msg); + msg.sendToTarget(); + } + @Override public void interfaceAdded(String iface) { if (iface.equals(CLAT_INTERFACE_NAME)) { @@ -165,19 +182,12 @@ public class Nat464Xlat extends BaseNetworkObserver { clatAddress.getAddress(), iface); mLP.addRoute(ipv4Default); mLP.addLinkAddress(clatAddress); - mTracker.addStackedLink(mLP); - Slog.i(TAG, "Adding stacked link. tracker LP: " + - mTracker.getLinkProperties()); + mBaseLP.addStackedLink(mLP); + Slog.i(TAG, "Adding stacked link. tracker LP: " + mBaseLP); + updateConnectivityService(); } catch(RemoteException e) { Slog.e(TAG, "Error getting link properties: " + e); } - - // Inform ConnectivityService that things have changed. - Message msg = mHandler.obtainMessage( - NetworkStateTracker.EVENT_CONFIGURATION_CHANGED, - mTracker.getNetworkInfo()); - Slog.i(TAG, "sending message to ConnectivityService: " + msg); - msg.sendToTarget(); } } @@ -192,8 +202,9 @@ public class Nat464Xlat extends BaseNetworkObserver { Slog.i(TAG, "interface " + CLAT_INTERFACE_NAME + " removed, mIsRunning = " + mIsRunning + " -> false"); mIsRunning = false; - mTracker.removeStackedLink(mLP); + mBaseLP.removeStackedLink(mLP); mLP.clear(); + updateConnectivityService(); Slog.i(TAG, "mLP = " + mLP); } } |