Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9392202 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Automerger Merge Worker
Browse files

Merge "Refactor the Nat464Xlat function for simplicity." am: a941cd53 am: f8a68930

Change-Id: I8cb3fb435baae54f5e811cae1efb603d585a28e9
parents 6d82315d f8a68930
Loading
Loading
Loading
Loading
+38 −23
Original line number Diff line number Diff line
@@ -213,12 +213,10 @@ public class Nat464Xlat extends BaseNetworkObserver {
        }
        mIface = null;
        mBaseIface = null;
        mState = State.IDLE;
        if (requiresClat(mNetwork)) {
            mState = State.DISCOVERING;
        } else {
            stopPrefixDiscovery();
            mState = State.IDLE;
        }
    }

@@ -285,6 +283,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
    private void stopPrefixDiscovery() {
        try {
            mDnsResolver.stopPrefix64Discovery(getNetId());
            mState = State.IDLE;
        } catch (RemoteException | ServiceSpecificException 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.
     */
    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 (!isPrefixDiscoveryStarted()) {
                startPrefixDiscovery();
            } else if (shouldStartClat(mNetwork)) {
                    // Network is detected to be IPv6-only.
                    // TODO: consider going to STARTING directly if the NAT64 prefix is already
                    // 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.
                // TODO: support the NAT64 prefix changing after it's been discovered. There is no
                // need to support this at the moment because it cannot happen without changes to
                // the Dns64Configuration code in netd.
                start();
            } else {
                // NAT64 prefix removed. Stop clatd and go back into DISCOVERING state.
                stop();
                    start();  // Enters STARTING state.
                    return;
                }
        } else {
            // Network no longer requires clat. Stop clat and prefix discovery.
            if (isStarted()) {
                if (!requiresClat(mNetwork)) {
                    // IPv4 address added. Go back to IDLE 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();
            } else if (isPrefixDiscoveryStarted()) {
                leaveStartedState();
                }
                break;
                // TODO: support the NAT64 prefix changing after it's been discovered. There is
                // no need to support this at the moment because it cannot happen without
                // changes to the Dns64Configuration code in netd.
        }
    }