Merge "NetBpfLoad: prog names are only valid on 4.15+" into main
diff --git a/tests/cts/net/src/android/net/cts/ApfIntegrationTest.kt b/tests/cts/net/src/android/net/cts/ApfIntegrationTest.kt
index 0e57019..b059d70 100644
--- a/tests/cts/net/src/android/net/cts/ApfIntegrationTest.kt
+++ b/tests/cts/net/src/android/net/cts/ApfIntegrationTest.kt
@@ -35,8 +35,8 @@
import android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY
import android.system.Os
import android.system.OsConstants
-import android.system.OsConstants.AF_INET
-import android.system.OsConstants.IPPROTO_ICMP
+import android.system.OsConstants.AF_INET6
+import android.system.OsConstants.IPPROTO_ICMPV6
import android.system.OsConstants.SOCK_DGRAM
import android.system.OsConstants.SOCK_NONBLOCK
import android.util.Log
@@ -88,7 +88,7 @@
@kotlin.ExperimentalStdlibApi
class ApfIntegrationTest {
companion object {
- private val PING_DESTINATION = InetSocketAddress("8.8.8.8", 0)
+ private val PING_DESTINATION = InetSocketAddress("2001:4860:4860::8888", 0)
@BeforeClass
@JvmStatic
@@ -109,7 +109,7 @@
}
}
- class IcmpPacketReader(
+ class Icmp6PacketReader(
handler: Handler,
private val network: Network
) : PacketReader(handler, RCV_BUFFER_SIZE) {
@@ -118,7 +118,7 @@
override fun createFd(): FileDescriptor {
// sockFd is closed by calling super.stop()
- val sock = Os.socket(AF_INET, SOCK_DGRAM or SOCK_NONBLOCK, IPPROTO_ICMP)
+ val sock = Os.socket(AF_INET6, SOCK_DGRAM or SOCK_NONBLOCK, IPPROTO_ICMPV6)
// APF runs only on WiFi, so make sure the socket is bound to the right network.
network.bindSocket(sock)
sockFd = sock
@@ -126,6 +126,8 @@
}
override fun handlePacket(recvbuf: ByteArray, length: Int) {
+ assertThat(length).isEqualTo(64)
+ assertThat(recvbuf[0]).isEqualTo(0x81.toByte())
// Only copy the ping data and complete the future.
val result = recvbuf.sliceArray(8..<length)
Log.i(TAG, "Received ping reply: ${result.toHexString()}")
@@ -135,18 +137,18 @@
fun sendPing(data: ByteArray) {
require(data.size == 56)
- // rfc792: Echo (type 0x08) or Echo Reply (type 0x00) Message:
- // 0 1 2 3
- // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- // | Type | Code | Checksum |
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- // | Identifier | Sequence Number |
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- // | Data ...
- // +-+-+-+-+-
- val icmpHeader = byteArrayOf(0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
- val packet = icmpHeader + data
+ // rfc4443#section-4.1: Echo Request Message
+ // 0 1 2 3
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // | Type | Code | Checksum |
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // | Identifier | Sequence Number |
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // | Data ...
+ // +-+-+-+-+-
+ val icmp6Header = byteArrayOf(0x80.toByte(), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
+ val packet = icmp6Header + data
Log.i(TAG, "Sent ping: ${packet.toHexString()}")
futureReply = CompletableFuture<ByteArray>()
Os.sendto(sockFd!!, packet, 0, packet.size, 0, PING_DESTINATION)
@@ -189,7 +191,7 @@
private lateinit var caps: ApfCapabilities
private val handlerThread = HandlerThread("$TAG handler thread").apply { start() }
private val handler = Handler(handlerThread.looper)
- private lateinit var packetReader: IcmpPacketReader
+ private lateinit var packetReader: Icmp6PacketReader
fun getApfCapabilities(): ApfCapabilities {
val caps = runShellCommand("cmd network_stack apf $ifname capabilities").trim()
@@ -250,7 +252,7 @@
runShellCommand("cmd network_stack apf $ifname pause")
caps = getApfCapabilities()
- packetReader = IcmpPacketReader(handler, network)
+ packetReader = Icmp6PacketReader(handler, network)
packetReader.start()
}
diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
index ce49533..f9a35fe 100755
--- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
@@ -457,6 +457,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.lang.reflect.Method;
import java.net.DatagramSocket;
import java.net.Inet4Address;
import java.net.Inet6Address;
@@ -19188,6 +19189,25 @@
verifyClatdStop(null /* inOrder */, MOBILE_IFNAME);
}
- // Note : adding tests is ConnectivityServiceTest is deprecated, as it is too big for
+ private static final int EXPECTED_TEST_METHOD_COUNT = 332;
+
+ @Test
+ public void testTestMethodCount() {
+ final Class<?> testClass = this.getClass();
+
+ int actualTestMethodCount = 0;
+ for (final Method method : testClass.getDeclaredMethods()) {
+ if (method.isAnnotationPresent(Test.class)) {
+ actualTestMethodCount++;
+ }
+ }
+
+ assertEquals("Adding tests in ConnectivityServiceTest is deprecated, "
+ + "as it is too big for maintenance. Please consider adding new tests "
+ + "in subclasses of CSTest instead.",
+ EXPECTED_TEST_METHOD_COUNT, actualTestMethodCount);
+ }
+
+ // Note : adding tests in ConnectivityServiceTest is deprecated, as it is too big for
// maintenance. Please consider adding new tests in subclasses of CSTest instead.
}