Merge "Cleanup in the face of upstream error" am: ed6d75d5f3

am: 76e6f790db

Change-Id: I097318f3edc5257288d582a0f17744e1f984856c
This commit is contained in:
Erik Kline
2017-02-14 06:21:44 +00:00
committed by android-build-merger
2 changed files with 33 additions and 32 deletions

View File

@@ -250,31 +250,33 @@ public class TetherInterfaceStateMachine extends StateMachine {
} }
private void cleanupUpstream() { private void cleanupUpstream() {
if (mMyUpstreamIfaceName != null) { if (mMyUpstreamIfaceName == null) return;
// note that we don't care about errors here.
// sometimes interfaces are gone before we get cleanupUpstreamInterface(mMyUpstreamIfaceName);
// to remove their rules, which generates errors. mMyUpstreamIfaceName = null;
// just do the best we can. }
try {
// about to tear down NAT; gather remaining statistics private void cleanupUpstreamInterface(String upstreamIface) {
mStatsService.forceUpdate(); // Note that we don't care about errors here.
} catch (Exception e) { // Sometimes interfaces are gone before we get
if (VDBG) Log.e(TAG, "Exception in forceUpdate: " + e.toString()); // to remove their rules, which generates errors.
} // Just do the best we can.
try { try {
mNMService.stopInterfaceForwarding(mIfaceName, mMyUpstreamIfaceName); // About to tear down NAT; gather remaining statistics.
} catch (Exception e) { mStatsService.forceUpdate();
if (VDBG) Log.e( } catch (Exception e) {
TAG, "Exception in removeInterfaceForward: " + e.toString()); if (VDBG) Log.e(TAG, "Exception in forceUpdate: " + e.toString());
} }
try { try {
mNMService.disableNat(mIfaceName, mMyUpstreamIfaceName); mNMService.stopInterfaceForwarding(mIfaceName, upstreamIface);
} catch (Exception e) { } catch (Exception e) {
if (VDBG) Log.e(TAG, "Exception in disableNat: " + e.toString()); if (VDBG) Log.e(TAG, "Exception in removeInterfaceForward: " + e.toString());
} }
mMyUpstreamIfaceName = null; try {
mNMService.disableNat(mIfaceName, upstreamIface);
} catch (Exception e) {
if (VDBG) Log.e(TAG, "Exception in disableNat: " + e.toString());
} }
return;
} }
@Override @Override
@@ -306,6 +308,7 @@ public class TetherInterfaceStateMachine extends StateMachine {
newUpstreamIfaceName); newUpstreamIfaceName);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Exception enabling Nat: " + e.toString()); Log.e(TAG, "Exception enabling Nat: " + e.toString());
cleanupUpstreamInterface(newUpstreamIfaceName);
mLastError = ConnectivityManager.TETHER_ERROR_ENABLE_NAT_ERROR; mLastError = ConnectivityManager.TETHER_ERROR_ENABLE_NAT_ERROR;
transitionTo(mInitialState); transitionTo(mInitialState);
return true; return true;

View File

@@ -210,10 +210,9 @@ public class TetherInterfaceStateMachineTest {
inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE); inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE);
inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE); inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE);
inOrder.verify(mNMService).enableNat(IFACE_NAME, UPSTREAM_IFACE2); inOrder.verify(mNMService).enableNat(IFACE_NAME, UPSTREAM_IFACE2);
// TODO: Verify proper cleanup is performed: inOrder.verify(mStatsService).forceUpdate();
// inOrder.verify(mStatsService).forceUpdate(); inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2);
// inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2); inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE2);
// inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE2);
} }
@Test @Test
@@ -230,10 +229,9 @@ public class TetherInterfaceStateMachineTest {
inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE); inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE);
inOrder.verify(mNMService).enableNat(IFACE_NAME, UPSTREAM_IFACE2); inOrder.verify(mNMService).enableNat(IFACE_NAME, UPSTREAM_IFACE2);
inOrder.verify(mNMService).startInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2); inOrder.verify(mNMService).startInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2);
// TODO: Verify proper cleanup is performed: inOrder.verify(mStatsService).forceUpdate();
// inOrder.verify(mStatsService).forceUpdate(); inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2);
// inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2); inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE2);
// inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE2);
} }
@Test @Test