Merge "Refactor the Nat464Xlat function for simplicity." am: b51a47360b am: 55462d27a2

Change-Id: I8cb3fb435baae54f5e811cae1efb603d585a28e9
This commit is contained in:
Lorenzo Colitti
2020-04-06 11:24:19 +00:00
committed by Automerger Merge Worker

View File

@@ -213,12 +213,10 @@ public class Nat464Xlat extends BaseNetworkObserver {
} }
mIface = null; mIface = null;
mBaseIface = null; mBaseIface = null;
mState = State.IDLE;
if (requiresClat(mNetwork)) { if (requiresClat(mNetwork)) {
mState = State.DISCOVERING; mState = State.DISCOVERING;
} else { } else {
stopPrefixDiscovery(); stopPrefixDiscovery();
mState = State.IDLE;
} }
} }
@@ -285,6 +283,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
private void stopPrefixDiscovery() { private void stopPrefixDiscovery() {
try { try {
mDnsResolver.stopPrefix64Discovery(getNetId()); mDnsResolver.stopPrefix64Discovery(getNetId());
mState = State.IDLE;
} catch (RemoteException | ServiceSpecificException e) { } catch (RemoteException | ServiceSpecificException e) {
Slog.e(TAG, "Error stopping prefix discovery on netId " + getNetId() + ": " + e); Slog.e(TAG, "Error stopping prefix discovery on netId " + getNetId() + ": " + e);
} }
@@ -294,27 +293,43 @@ public class Nat464Xlat extends BaseNetworkObserver {
* Starts/stops NAT64 prefix discovery and clatd as necessary. * Starts/stops NAT64 prefix discovery and clatd as necessary.
*/ */
public void update() { public void update() {
// TODO: turn this class into a proper StateMachine. // http://b/126113090 // TODO: turn this class into a proper StateMachine. http://b/126113090
switch (mState) {
case IDLE:
if (requiresClat(mNetwork)) { if (requiresClat(mNetwork)) {
if (!isPrefixDiscoveryStarted()) { // Network is detected to be IPv6-only.
startPrefixDiscovery(); // TODO: consider going to STARTING directly if the NAT64 prefix is already
} else if (shouldStartClat(mNetwork)) { // known. This would however result in clatd running without prefix discovery
// running, which might be a surprising combination.
startPrefixDiscovery(); // Enters DISCOVERING state.
return;
}
break;
case DISCOVERING:
if (shouldStartClat(mNetwork)) {
// NAT64 prefix detected. Start clatd. // NAT64 prefix detected. Start clatd.
// TODO: support the NAT64 prefix changing after it's been discovered. There is no start(); // Enters STARTING state.
// need to support this at the moment because it cannot happen without changes to return;
// the Dns64Configuration code in netd. }
start(); if (!requiresClat(mNetwork)) {
} else { // IPv4 address added. Go back to IDLE state.
// NAT64 prefix removed. Stop clatd and go back into DISCOVERING state. stopPrefixDiscovery();
return;
}
break;
case STARTING:
case RUNNING:
// NAT64 prefix removed, or IPv4 address added.
// Stop clatd and go back into DISCOVERING or idle.
if (!shouldStartClat(mNetwork)) {
stop(); stop();
} }
} else { break;
// Network no longer requires clat. Stop clat and prefix discovery. // TODO: support the NAT64 prefix changing after it's been discovered. There is
if (isStarted()) { // no need to support this at the moment because it cannot happen without
stop(); // changes to the Dns64Configuration code in netd.
} else if (isPrefixDiscoveryStarted()) {
leaveStartedState();
}
} }
} }