From 38804ae6a4a44953bb1a5fd2e4baf8a0488c9025 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Mon, 10 Nov 2014 19:17:35 -0800 Subject: [PATCH] Populate 464xlat LinkProperties only when the interface comes up. Currently Nat464Xlat reads the clat IPv4 address and updates the clat LinkProperties when the interface is created. This causes a race condition: because clatd only sets the IPv4 address after creating the interface, it's possible that Nat464Xlat will read the address before clatd has set it, causing the framework to think that the clat IPv4 address is 0.0.0.0/32. This seems to be happening more frequently now, perhaps because clatd takes a bit longer to configure the IPv4 address now that it needs to check that the address is free before using it. Fix this by making Nat464Xlat listen for the interface coming up instead of listening for the interface being added. Bug: 12111730 Change-Id: Ic1c59b5b6dbb851b7431d1b06885f67803373bb9 --- .../com/android/server/connectivity/Nat464Xlat.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/Nat464Xlat.java b/services/core/java/com/android/server/connectivity/Nat464Xlat.java index 576556b306..3fa21d09ee 100644 --- a/services/core/java/com/android/server/connectivity/Nat464Xlat.java +++ b/services/core/java/com/android/server/connectivity/Nat464Xlat.java @@ -63,8 +63,8 @@ public class Nat464Xlat extends BaseNetworkObserver { // - Idle: start() not called. Everything is null. // - Starting: start() called. Interfaces are non-null. isStarted() returns true. // mIsRunning is false. - // - Running: start() called, and interfaceAdded() told us that mIface is up. Clat IP address - // is non-null. mIsRunning is true. + // - Running: start() called, and interfaceLinkStateChanged() told us that mIface is up. + // mIsRunning is true. // // Once mIface is non-null and isStarted() is true, methods called by ConnectivityService on // its handler thread must not modify any internal state variables; they are only updated by the @@ -236,10 +236,10 @@ public class Nat464Xlat extends BaseNetworkObserver { } @Override - public void interfaceAdded(String iface) { + public void interfaceLinkStateChanged(String iface, boolean up) { // Called by the InterfaceObserver on its own thread, so can race with stop(). - if (isStarted() && mIface.equals(iface)) { - Slog.i(TAG, "interface " + iface + " added, mIsRunning " + mIsRunning + "->true"); + if (isStarted() && up && mIface.equals(iface)) { + Slog.i(TAG, "interface " + iface + " is up, mIsRunning " + mIsRunning + "->true"); if (!mIsRunning) { LinkAddress clatAddress = getLinkAddress(iface);