Get clatd/Nat464Xlat working with new NetworkAgents.
Change-Id: I65dfb59ce519a42bdb872940d229039b5403fd92
This commit is contained in:
committed by
Lorenzo Colitti
parent
52f1e4631e
commit
3927e336e7
@@ -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.
|
// TODO: Temporary notifying upstread change to Tethering.
|
||||||
// @see bug/4455071
|
// @see bug/4455071
|
||||||
/** Notify TetheringService if interface name has been changed. */
|
/** Notify TetheringService if interface name has been changed. */
|
||||||
@@ -3073,7 +3053,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
}
|
}
|
||||||
notifyNetworkCallbacks(nai, NetworkCallbacks.LOST);
|
notifyNetworkCallbacks(nai, NetworkCallbacks.LOST);
|
||||||
nai.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_DISCONNECTED);
|
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
|
// Since we've lost the network, go through all the requests that
|
||||||
// it was satisfying and see if any other factory can satisfy them.
|
// it was satisfying and see if any other factory can satisfy them.
|
||||||
final ArrayList<NetworkAgentInfo> toActivate = new ArrayList<NetworkAgentInfo>();
|
final ArrayList<NetworkAgentInfo> toActivate = new ArrayList<NetworkAgentInfo>();
|
||||||
@@ -5121,6 +5102,28 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
// }
|
// }
|
||||||
updateRoutes(newLp, oldLp, netId);
|
updateRoutes(newLp, oldLp, netId);
|
||||||
updateDnses(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) {
|
private void updateInterfaces(LinkProperties newLp, LinkProperties oldLp, int netId) {
|
||||||
|
|||||||
@@ -25,11 +25,12 @@ import android.net.IConnectivityManager;
|
|||||||
import android.net.InterfaceConfiguration;
|
import android.net.InterfaceConfiguration;
|
||||||
import android.net.LinkAddress;
|
import android.net.LinkAddress;
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
import android.net.NetworkStateTracker;
|
import android.net.NetworkAgent;
|
||||||
import android.net.NetworkUtils;
|
import android.net.NetworkUtils;
|
||||||
import android.net.RouteInfo;
|
import android.net.RouteInfo;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
import android.os.INetworkManagementService;
|
import android.os.INetworkManagementService;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
@@ -45,15 +46,18 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private INetworkManagementService mNMService;
|
private INetworkManagementService mNMService;
|
||||||
private IConnectivityManager mConnService;
|
private IConnectivityManager mConnService;
|
||||||
private NetworkStateTracker mTracker;
|
|
||||||
private Handler mHandler;
|
|
||||||
|
|
||||||
// Whether we started clatd and expect it to be running.
|
// Whether we started clatd and expect it to be running.
|
||||||
private boolean mIsStarted;
|
private boolean mIsStarted;
|
||||||
// Whether the clatd interface exists (i.e., clatd is running).
|
// Whether the clatd interface exists (i.e., clatd is running).
|
||||||
private boolean mIsRunning;
|
private boolean mIsRunning;
|
||||||
// The LinkProperties of the clat interface.
|
// The LinkProperties of the clat interface.
|
||||||
private LinkProperties mLP;
|
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.
|
// This must match the interface name in clatd.conf.
|
||||||
private static final String CLAT_INTERFACE_NAME = "clat4";
|
private static final String CLAT_INTERFACE_NAME = "clat4";
|
||||||
@@ -73,14 +77,13 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether an interface requires clat.
|
* Determines whether a network requires clat.
|
||||||
* @param netType the network type (one of the
|
* @param network the NetworkAgentInfo corresponding to the network.
|
||||||
* android.net.ConnectivityManager.TYPE_* constants)
|
* @return true if the network requires clat, false otherwise.
|
||||||
* @param tracker the NetworkStateTracker corresponding to the network type.
|
|
||||||
* @return true if the interface requires clat, false otherwise.
|
|
||||||
*/
|
*/
|
||||||
public boolean requiresClat(int netType, NetworkStateTracker tracker) {
|
public boolean requiresClat(NetworkAgentInfo network) {
|
||||||
LinkProperties lp = tracker.getLinkProperties();
|
int netType = network.networkInfo.getType();
|
||||||
|
LinkProperties lp = network.linkProperties;
|
||||||
// Only support clat on mobile for now.
|
// Only support clat on mobile for now.
|
||||||
Slog.d(TAG, "requiresClat: netType=" + netType + ", hasIPv4Address=" +
|
Slog.d(TAG, "requiresClat: netType=" + netType + ", hasIPv4Address=" +
|
||||||
lp.hasIPv4Address());
|
lp.hasIPv4Address());
|
||||||
@@ -95,13 +98,18 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
|||||||
* Starts the clat daemon.
|
* Starts the clat daemon.
|
||||||
* @param lp The link properties of the interface to start clatd on.
|
* @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) {
|
if (mIsStarted) {
|
||||||
Slog.e(TAG, "startClat: already started");
|
Slog.e(TAG, "startClat: already started");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mTracker = tracker;
|
|
||||||
LinkProperties lp = mTracker.getLinkProperties();
|
|
||||||
String iface = lp.getInterfaceName();
|
String iface = lp.getInterfaceName();
|
||||||
Slog.i(TAG, "Starting clatd on " + iface + ", lp=" + lp);
|
Slog.i(TAG, "Starting clatd on " + iface + ", lp=" + lp);
|
||||||
try {
|
try {
|
||||||
@@ -125,7 +133,8 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
mIsStarted = false;
|
mIsStarted = false;
|
||||||
mIsRunning = false;
|
mIsRunning = false;
|
||||||
mTracker = null;
|
mNetworkMessenger = null;
|
||||||
|
mBaseLP = null;
|
||||||
mLP.clear();
|
mLP.clear();
|
||||||
} else {
|
} else {
|
||||||
Slog.e(TAG, "stopClat: already stopped");
|
Slog.e(TAG, "stopClat: already stopped");
|
||||||
@@ -140,6 +149,14 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
|||||||
return mIsRunning;
|
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
|
@Override
|
||||||
public void interfaceAdded(String iface) {
|
public void interfaceAdded(String iface) {
|
||||||
if (iface.equals(CLAT_INTERFACE_NAME)) {
|
if (iface.equals(CLAT_INTERFACE_NAME)) {
|
||||||
@@ -165,19 +182,12 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
|||||||
clatAddress.getAddress(), iface);
|
clatAddress.getAddress(), iface);
|
||||||
mLP.addRoute(ipv4Default);
|
mLP.addRoute(ipv4Default);
|
||||||
mLP.addLinkAddress(clatAddress);
|
mLP.addLinkAddress(clatAddress);
|
||||||
mTracker.addStackedLink(mLP);
|
mBaseLP.addStackedLink(mLP);
|
||||||
Slog.i(TAG, "Adding stacked link. tracker LP: " +
|
Slog.i(TAG, "Adding stacked link. tracker LP: " + mBaseLP);
|
||||||
mTracker.getLinkProperties());
|
updateConnectivityService();
|
||||||
} catch(RemoteException e) {
|
} catch(RemoteException e) {
|
||||||
Slog.e(TAG, "Error getting link properties: " + 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 +
|
Slog.i(TAG, "interface " + CLAT_INTERFACE_NAME +
|
||||||
" removed, mIsRunning = " + mIsRunning + " -> false");
|
" removed, mIsRunning = " + mIsRunning + " -> false");
|
||||||
mIsRunning = false;
|
mIsRunning = false;
|
||||||
mTracker.removeStackedLink(mLP);
|
mBaseLP.removeStackedLink(mLP);
|
||||||
mLP.clear();
|
mLP.clear();
|
||||||
|
updateConnectivityService();
|
||||||
Slog.i(TAG, "mLP = " + mLP);
|
Slog.i(TAG, "mLP = " + mLP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user