[CLATJ#32] ClatCoordinator: untag clat raw socket

Untag clat raw socket while stopping clatd.

Bug: 218407445
Test: atest FrameworksNetTests
Test: connect and disconnect to/from IPv6 only network
Check dumpsys tag map and logging for tagging/untagging socket
03-04 16:29:17.247  1330  1714 I jniClatCoordinator: tag uid AID_CLAT to socket fd 420, cookie 16524
03-04 16:29:31.343  1330  1714 I jniClatCoordinator: untag socket cookie 16524

Change-Id: Id5f5bdfc97a15abfa1a49b06dcb3c2c25743c74f
This commit is contained in:
Hungming Chen
2022-03-03 21:00:01 +08:00
parent 89d12060e1
commit 1c257cdb8d
3 changed files with 54 additions and 7 deletions

View File

@@ -26,13 +26,10 @@ import static com.android.testutils.MiscAsserts.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.argThat;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.never;
import android.annotation.NonNull;
import android.net.INetd;
@@ -278,6 +275,16 @@ public class ClatCoordinatorTest {
fail("unsupported arg: " + sock);
return 0;
}
/**
* Untag socket.
*/
@Override
public void untagSocket(long cookie) throws IOException {
if (cookie != RAW_SOCK_COOKIE) {
fail("unsupported arg: " + cookie);
}
}
};
@NonNull
@@ -364,13 +371,12 @@ public class ClatCoordinatorTest {
coordinator.clatStop();
inOrder.verify(mDeps).stopClatd(eq(BASE_IFACE), eq(NAT64_PREFIX_STRING),
eq(XLAT_LOCAL_IPV4ADDR_STRING), eq(XLAT_LOCAL_IPV6ADDR_STRING), eq(CLATD_PID));
inOrder.verify(mDeps).untagSocket(eq(RAW_SOCK_COOKIE));
inOrder.verifyNoMoreInteractions();
// [4] Expect an IO exception while stopping a clatd that doesn't exist.
assertThrows("java.io.IOException: Clatd has not started", IOException.class,
() -> coordinator.clatStop());
inOrder.verify(mDeps, never()).stopClatd(anyString(), anyString(), anyString(),
anyString(), anyInt());
inOrder.verifyNoMoreInteractions();
}