History log of /frameworks/base/tests/net/java/com/android/server/connectivity/Nat464XlatTest.java
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
3fb5f0db3ffe658fe039f0453c6bc0c46fd5441a 01-Sep-2017 Hugo Benichi <hugobenichi@google.com> Nat464Xlat: correct racefree teardown

This patch relays the NetworkBaseObserver notifications about nat
464xlat stacked interfaces onto the ConnectivityService handler.

This allows to process interface up and down notifications in the
same thread context and eliminates several races:

- NPE risk due to race between fixupLinkProperties called on
ConnectivityService thread and interfaceRemoved called on
NetworkManagementService thread.
- stale LinkProperties pointer reads in both NetworkBaseObserver
callbacks not called on ConnectivityService handler.
- removes the race between stop() and interfaceRemoved().
- removes superfluous LinkProperties notifications when stop() is
called before the stacked interface goes up.

The teardown procedure logic common to stop() and interfaceRemoved() is
put into enterStoppedState() and enterIdleState().

This allows to distinguish and correctly handle the following teardown
scenarios:
- an IPv4 appears -> ConnectivityService calls Nat464Xlat#stop()
-> Nat464Xlat calls stopClatd
-> clatd stops
-> if the stacked interface was up, it is removed
-> Nat464Xlat#interfaceRemoved() is triggered and
a LinkProperties update is sent.

- network disconnects -> ConnectivityService calls Nat464Xlat#stop()
-> Nat464Xlat calls stopClatd
-> clatd stops
-> if the stacked interface was up, it is removed
-> Nat464Xlat#interfaceRemoved() is triggered and
a LinkProperties update is sent.

- clatd crashes or exit -> Nat464Xlat#interfaceRemoved() is triggered
-> Nat464Xlat unregisters itself as a network
observer
-> ConnectivityService is updated about the
stacked interface missing, and restarts
Nat464Xlat if needed.

Note that the first two scenarios have two cases: stop() can be called
before the notification for the stacked interface going up (STARTED), or
after (RUNNING). In the first case, Nat464Xlat must unregister
immediately as a network observer to avoid leaks.

This patch also:
- removes/simplifies comments related to the threading model which
are no obsolete.
- extract clatd management logic from ConnectivityService into
NetworkAgentInfo
- add new unit tests where there was none before.

Bug: 62918393
Bug: 62997041
Bug: 64571917
Bug: 65225023
Test: runtest frameworks-net
Merged-In: I27221a8a60fd9760b567ed322cc79228df877e56
Merged-In: I8f07dfbe5ea8259ff9f5793503f534945e67ad74
Merged-In: I8612db5e5050690db8cf41dd04944b4c22da340c
Merged-In: Icb2dc8229b5ea45e319233b588f2dbe39ea40d4c
Merged-In: Ibafea69224e832a6316c17dbb9b2d62a233088ac

(cherry picked from commit ef502887ec58886e9347afb841aa06cb0d13acea)

Change-Id: I9d075048873b0e1c5ed45b5674ada3fb303c2bfb
/frameworks/base/tests/net/java/com/android/server/connectivity/Nat464XlatTest.java