Merge "Add support for running 464xlat on wifi as well." into lmp-mr1-dev

This commit is contained in:
Lorenzo Colitti
2014-10-30 13:27:53 +00:00
committed by Android (Google) Code Review

View File

@@ -17,6 +17,7 @@
package com.android.server.connectivity; package com.android.server.connectivity;
import static android.net.ConnectivityManager.TYPE_MOBILE; import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.ConnectivityManager.TYPE_WIFI;
import java.net.Inet4Address; import java.net.Inet4Address;
@@ -53,7 +54,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
// ConnectivityService Handler for LinkProperties updates. // ConnectivityService Handler for LinkProperties updates.
private final Handler mHandler; private final Handler mHandler;
// The network we're running on. // The network we're running on, and its type.
private final NetworkAgentInfo mNetwork; private final NetworkAgentInfo mNetwork;
// Internal state variables. // Internal state variables.
@@ -211,23 +212,41 @@ public class Nat464Xlat extends BaseNetworkObserver {
return stacked; return stacked;
} }
private LinkAddress getLinkAddress(String iface) {
try {
InterfaceConfiguration config = mNMService.getInterfaceConfig(iface);
return config.getLinkAddress();
} catch(RemoteException|IllegalStateException e) {
Slog.e(TAG, "Error getting link properties: " + e);
return null;
}
}
private void maybeSetIpv6NdOffload(String iface, boolean on) {
if (mNetwork.networkInfo.getType() != TYPE_WIFI) {
return;
}
try {
Slog.d(TAG, (on ? "En" : "Dis") + "abling ND offload on " + iface);
mNMService.setInterfaceIpv6NdOffload(iface, on);
} catch(RemoteException|IllegalStateException e) {
Slog.w(TAG, "Changing IPv6 ND offload on " + iface + "failed: " + e);
}
}
@Override @Override
public void interfaceAdded(String iface) { public void interfaceAdded(String iface) {
// Called by the InterfaceObserver on its own thread, so can race with stop(). // Called by the InterfaceObserver on its own thread, so can race with stop().
if (isStarted() && mIface.equals(iface)) { if (isStarted() && mIface.equals(iface)) {
Slog.i(TAG, "interface " + iface + " added, mIsRunning " + mIsRunning + "->true"); Slog.i(TAG, "interface " + iface + " added, mIsRunning " + mIsRunning + "->true");
LinkAddress clatAddress; if (!mIsRunning) {
try { LinkAddress clatAddress = getLinkAddress(iface);
InterfaceConfiguration config = mNMService.getInterfaceConfig(iface); if (clatAddress == null) {
clatAddress = config.getLinkAddress();
} catch(RemoteException e) {
Slog.e(TAG, "Error getting link properties: " + e);
return; return;
} }
if (!mIsRunning) {
mIsRunning = true; mIsRunning = true;
maybeSetIpv6NdOffload(mBaseIface, false);
LinkProperties lp = new LinkProperties(mNetwork.linkProperties); LinkProperties lp = new LinkProperties(mNetwork.linkProperties);
lp.addStackedLink(makeLinkProperties(clatAddress)); lp.addStackedLink(makeLinkProperties(clatAddress));
Slog.i(TAG, "Adding stacked link " + mIface + " on top of " + mBaseIface); Slog.i(TAG, "Adding stacked link " + mIface + " on top of " + mBaseIface);
@@ -255,6 +274,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
} catch (RemoteException|IllegalStateException e) { } catch (RemoteException|IllegalStateException e) {
// Well, we tried. // Well, we tried.
} }
maybeSetIpv6NdOffload(mBaseIface, true);
LinkProperties lp = new LinkProperties(mNetwork.linkProperties); LinkProperties lp = new LinkProperties(mNetwork.linkProperties);
lp.removeStackedLink(mIface); lp.removeStackedLink(mIface);
clear(); clear();