Loading services/core/java/com/android/server/ConnectivityService.java +24 −21 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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>(); Loading Loading @@ -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) { Loading services/core/java/com/android/server/connectivity/Nat464Xlat.java +37 −26 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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"; Loading @@ -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()); Loading @@ -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 { Loading @@ -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"); Loading @@ -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)) { Loading @@ -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(); } } Loading @@ -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); } } Loading Loading
services/core/java/com/android/server/ConnectivityService.java +24 −21 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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>(); Loading Loading @@ -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) { Loading
services/core/java/com/android/server/connectivity/Nat464Xlat.java +37 −26 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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"; Loading @@ -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()); Loading @@ -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 { Loading @@ -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"); Loading @@ -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)) { Loading @@ -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(); } } Loading @@ -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); } } Loading