Reapply "Send ICMPv6 ping to support IPv6-only network"
This reverts commit 98219a4e8af9c3755124508fd6db4b9a4f92fc8d.
Moved the revert past "Only run APF tests on physical devices".
This broke on cuttlefish, as CF does not support IPv6.
Test: TH
Change-Id: I04d1adb4538e6c413a1325432e1c014ca78b41e3
diff --git a/tests/cts/net/src/android/net/cts/ApfIntegrationTest.kt b/tests/cts/net/src/android/net/cts/ApfIntegrationTest.kt
index a70b85e..ffad455 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
@@ -90,7 +90,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
@@ -111,7 +111,7 @@
}
}
- class IcmpPacketReader(
+ class Icmp6PacketReader(
handler: Handler,
private val network: Network
) : PacketReader(handler, RCV_BUFFER_SIZE) {
@@ -120,7 +120,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
@@ -128,6 +128,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()}")
@@ -137,18 +139,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)
@@ -191,7 +193,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()
@@ -252,7 +254,7 @@
runShellCommand("cmd network_stack apf $ifname pause")
caps = getApfCapabilities()
- packetReader = IcmpPacketReader(handler, network)
+ packetReader = Icmp6PacketReader(handler, network)
packetReader.start()
}