Merge "Nat464Xlat: clat management cleanup" am: 81b179cfdd am: bd5610af79
am: da71487a59 Change-Id: I06661bd6bd1456ba34a3bbdb52c120ac01da9d61
This commit is contained in:
@@ -2269,7 +2269,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
nai.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_DISCONNECTED);
|
nai.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_DISCONNECTED);
|
||||||
mNetworkAgentInfos.remove(msg.replyTo);
|
mNetworkAgentInfos.remove(msg.replyTo);
|
||||||
updateClat(null, nai.linkProperties, nai);
|
maybeStopClat(nai);
|
||||||
synchronized (mNetworkForNetId) {
|
synchronized (mNetworkForNetId) {
|
||||||
// Remove the NetworkAgent, but don't mark the netId as
|
// Remove the NetworkAgent, but don't mark the netId as
|
||||||
// available until we've told netd to delete it below.
|
// available until we've told netd to delete it below.
|
||||||
@@ -4382,7 +4382,8 @@ 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);
|
// Start or stop clat accordingly to network state.
|
||||||
|
updateClat(networkAgent);
|
||||||
if (isDefaultNetwork(networkAgent)) {
|
if (isDefaultNetwork(networkAgent)) {
|
||||||
handleApplyDefaultProxy(newLp.getHttpProxy());
|
handleApplyDefaultProxy(newLp.getHttpProxy());
|
||||||
} else {
|
} else {
|
||||||
@@ -4397,18 +4398,32 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mKeepaliveTracker.handleCheckKeepalivesStillValid(networkAgent);
|
mKeepaliveTracker.handleCheckKeepalivesStillValid(networkAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateClat(LinkProperties newLp, LinkProperties oldLp, NetworkAgentInfo nai) {
|
private void updateClat(NetworkAgentInfo nai) {
|
||||||
final boolean wasRunningClat = nai.clatd != null && nai.clatd.isStarted();
|
if (Nat464Xlat.requiresClat(nai)) {
|
||||||
final boolean shouldRunClat = Nat464Xlat.requiresClat(nai);
|
maybeStartClat(nai);
|
||||||
|
} else {
|
||||||
if (!wasRunningClat && shouldRunClat) {
|
maybeStopClat(nai);
|
||||||
nai.clatd = new Nat464Xlat(mContext, mNetd, mTrackerHandler, nai);
|
|
||||||
nai.clatd.start();
|
|
||||||
} else if (wasRunningClat && !shouldRunClat) {
|
|
||||||
nai.clatd.stop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Ensure clat has started for this network. */
|
||||||
|
private void maybeStartClat(NetworkAgentInfo nai) {
|
||||||
|
if (nai.clatd != null && nai.clatd.isStarted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nai.clatd = new Nat464Xlat(mNetd, mTrackerHandler, nai);
|
||||||
|
nai.clatd.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ensure clat has stopped for this network. */
|
||||||
|
private void maybeStopClat(NetworkAgentInfo nai) {
|
||||||
|
if (nai.clatd == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nai.clatd.stop();
|
||||||
|
nai.clatd = null;
|
||||||
|
}
|
||||||
|
|
||||||
private void wakeupModifyInterface(String iface, NetworkCapabilities caps, boolean add) {
|
private void wakeupModifyInterface(String iface, NetworkCapabilities caps, boolean add) {
|
||||||
// Marks are only available on WiFi interaces. Checking for
|
// Marks are only available on WiFi interaces. Checking for
|
||||||
// marks on unsupported interfaces is harmless.
|
// marks on unsupported interfaces is harmless.
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package com.android.server.connectivity;
|
|||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.InterfaceConfiguration;
|
import android.net.InterfaceConfiguration;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.LinkAddress;
|
import android.net.LinkAddress;
|
||||||
@@ -35,17 +34,18 @@ import com.android.server.net.BaseNetworkObserver;
|
|||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
|
||||||
*
|
|
||||||
* Class to manage a 464xlat CLAT daemon.
|
* Class to manage a 464xlat CLAT daemon.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class Nat464Xlat extends BaseNetworkObserver {
|
public class Nat464Xlat extends BaseNetworkObserver {
|
||||||
private static final String TAG = "Nat464Xlat";
|
private static final String TAG = Nat464Xlat.class.getSimpleName();
|
||||||
|
|
||||||
// This must match the interface prefix in clatd.c.
|
// This must match the interface prefix in clatd.c.
|
||||||
private static final String CLAT_PREFIX = "v4-";
|
private static final String CLAT_PREFIX = "v4-";
|
||||||
|
|
||||||
// The network types we will start clatd on.
|
// The network types we will start clatd on,
|
||||||
|
// allowing clat only on networks for which we can support IPv6-only.
|
||||||
private static final int[] NETWORK_TYPES = {
|
private static final int[] NETWORK_TYPES = {
|
||||||
ConnectivityManager.TYPE_MOBILE,
|
ConnectivityManager.TYPE_MOBILE,
|
||||||
ConnectivityManager.TYPE_WIFI,
|
ConnectivityManager.TYPE_WIFI,
|
||||||
@@ -76,9 +76,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
|||||||
private String mIface;
|
private String mIface;
|
||||||
private boolean mIsRunning;
|
private boolean mIsRunning;
|
||||||
|
|
||||||
public Nat464Xlat(
|
public Nat464Xlat(INetworkManagementService nmService, Handler handler, NetworkAgentInfo nai) {
|
||||||
Context context, INetworkManagementService nmService,
|
|
||||||
Handler handler, NetworkAgentInfo nai) {
|
|
||||||
mNMService = nmService;
|
mNMService = nmService;
|
||||||
mHandler = handler;
|
mHandler = handler;
|
||||||
mNetwork = nai;
|
mNetwork = nai;
|
||||||
@@ -90,13 +88,14 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
|||||||
* @return true if the network requires clat, false otherwise.
|
* @return true if the network requires clat, false otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean requiresClat(NetworkAgentInfo nai) {
|
public static boolean requiresClat(NetworkAgentInfo nai) {
|
||||||
|
// TODO: migrate to NetworkCapabilities.TRANSPORT_*.
|
||||||
final int netType = nai.networkInfo.getType();
|
final int netType = nai.networkInfo.getType();
|
||||||
|
final boolean supported = ArrayUtils.contains(NETWORK_TYPES, nai.networkInfo.getType());
|
||||||
final boolean connected = nai.networkInfo.isConnected();
|
final boolean connected = nai.networkInfo.isConnected();
|
||||||
|
// We only run clat on networks that don't have a native IPv4 address.
|
||||||
final boolean hasIPv4Address =
|
final boolean hasIPv4Address =
|
||||||
(nai.linkProperties != null) ? nai.linkProperties.hasIPv4Address() : false;
|
(nai.linkProperties != null) && nai.linkProperties.hasIPv4Address();
|
||||||
// Only support clat on mobile and wifi for now, because these are the only IPv6-only
|
return supported && connected && !hasIPv4Address;
|
||||||
// networks we can connect to.
|
|
||||||
return connected && !hasIPv4Address && ArrayUtils.contains(NETWORK_TYPES, netType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,6 +226,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void maybeSetIpv6NdOffload(String iface, boolean on) {
|
private void maybeSetIpv6NdOffload(String iface, boolean on) {
|
||||||
|
// TODO: migrate to NetworkCapabilities.TRANSPORT_*.
|
||||||
if (mNetwork.networkInfo.getType() != ConnectivityManager.TYPE_WIFI) {
|
if (mNetwork.networkInfo.getType() != ConnectivityManager.TYPE_WIFI) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -286,4 +286,9 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "mBaseIface: " + mBaseIface + ", mIface: " + mIface + ", mIsRunning: " + mIsRunning;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -562,13 +562,13 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
|||||||
"acceptUnvalidated{" + networkMisc.acceptUnvalidated + "} " +
|
"acceptUnvalidated{" + networkMisc.acceptUnvalidated + "} " +
|
||||||
"everCaptivePortalDetected{" + everCaptivePortalDetected + "} " +
|
"everCaptivePortalDetected{" + everCaptivePortalDetected + "} " +
|
||||||
"lastCaptivePortalDetected{" + lastCaptivePortalDetected + "} " +
|
"lastCaptivePortalDetected{" + lastCaptivePortalDetected + "} " +
|
||||||
|
"clat{" + clatd + "} " +
|
||||||
"}";
|
"}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String name() {
|
public String name() {
|
||||||
return "NetworkAgentInfo [" + networkInfo.getTypeName() + " (" +
|
return "NetworkAgentInfo [" + networkInfo.getTypeName() + " (" +
|
||||||
networkInfo.getSubtypeName() + ") - " +
|
networkInfo.getSubtypeName() + ") - " + Objects.toString(network) + "]";
|
||||||
(network == null ? "null" : network.toString()) + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enables sorting in descending order of score.
|
// Enables sorting in descending order of score.
|
||||||
|
|||||||
Reference in New Issue
Block a user