Add helper method to generate a v6 NAT-T keepalive packet
This is a part of preliminary work for sending a v6 NAT-T
keepalive packet in a v6 only network. This commit
release the constraint on constructing a v6 NAT-T keepalive
packet.
Bug: 196453719
Test: Manually connect to v6 only network and check if the
keepalive packets are sent with subsequent commit
Test: atest FrameworksNetTests with the updated test
Change-Id: I9dc96e840265c5dee6b9e3ef2b3901a0aeb4ff9e
This commit is contained in:
@@ -46,6 +46,8 @@ class NattKeepalivePacketDataTest {
|
||||
private val TEST_SRC_ADDRV4 = "198.168.0.2".address()
|
||||
private val TEST_DST_ADDRV4 = "198.168.0.1".address()
|
||||
private val TEST_ADDRV6 = "2001:db8::1".address()
|
||||
private val TEST_ADDRV4MAPPEDV6 = "::ffff:1.2.3.4".address()
|
||||
private val TEST_ADDRV4 = "1.2.3.4".address()
|
||||
|
||||
private fun String.address() = InetAddresses.parseNumericAddress(this)
|
||||
private fun nattKeepalivePacket(
|
||||
@@ -83,6 +85,28 @@ class NattKeepalivePacketDataTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test @IgnoreUpTo(Build.VERSION_CODES.R)
|
||||
fun testConstructor_afterR() {
|
||||
// v4 mapped v6 will be translated to a v4 address.
|
||||
assertFailsWith<InvalidPacketException> {
|
||||
nattKeepalivePacket(srcAddress = TEST_ADDRV6, dstAddress = TEST_ADDRV4MAPPEDV6)
|
||||
}
|
||||
assertFailsWith<InvalidPacketException> {
|
||||
nattKeepalivePacket(srcAddress = TEST_ADDRV4MAPPEDV6, dstAddress = TEST_ADDRV6)
|
||||
}
|
||||
|
||||
// Both src and dst address will be v4 after translation, so it won't cause exception.
|
||||
val packet1 = nattKeepalivePacket(
|
||||
dstAddress = TEST_ADDRV4MAPPEDV6, srcAddress = TEST_ADDRV4MAPPEDV6)
|
||||
assertEquals(TEST_ADDRV4, packet1.srcAddress)
|
||||
assertEquals(TEST_ADDRV4, packet1.dstAddress)
|
||||
|
||||
// Packet with v6 src and v6 dst address is valid.
|
||||
val packet2 = nattKeepalivePacket(srcAddress = TEST_ADDRV6, dstAddress = TEST_ADDRV6)
|
||||
assertEquals(TEST_ADDRV6, packet2.srcAddress)
|
||||
assertEquals(TEST_ADDRV6, packet2.dstAddress)
|
||||
}
|
||||
|
||||
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
|
||||
fun testParcel() {
|
||||
assertParcelingIsLossless(nattKeepalivePacket())
|
||||
|
||||
Reference in New Issue
Block a user