Fix the deprecationTime and expirationTime of delegated IPv6 link address. Preferred/valid lifetime in the IA Prefix option is in unit of seconds, covert it to milliseconds when populating the deprecationTime and expirationTime for delegated IPv6 link address. Bug: 129660498 Test: atest NetworkStackIntegrationTests Change-Id: I764a63f85896ff509feb09e51564cd95209701d7
diff --git a/src/android/net/ip/IpClient.java b/src/android/net/ip/IpClient.java index f01f505..7beca2d 100644 --- a/src/android/net/ip/IpClient.java +++ b/src/android/net/ip/IpClient.java
@@ -3056,8 +3056,10 @@ @NonNull final IaPrefixOption ipo) { final int flags = IFA_F_NOPREFIXROUTE | IFA_F_MANAGETEMPADDR | IFA_F_NODAD; final long now = SystemClock.elapsedRealtime(); - final long deprecationTime = now + ipo.preferred; - final long expirationTime = now + ipo.valid; + // Per RFC8415 section 21.22 the preferred/valid lifetime in IA Prefix option + // expressed in units of seconds. + final long deprecationTime = now + ipo.preferred * 1000; + final long expirationTime = now + ipo.valid * 1000; final LinkAddress la; try { la = new LinkAddress(address, RFC7421_PREFIX_LENGTH, flags,
diff --git a/tests/integration/common/android/net/ip/IpClientIntegrationTestCommon.java b/tests/integration/common/android/net/ip/IpClientIntegrationTestCommon.java index 7f4e852..2bbb879 100644 --- a/tests/integration/common/android/net/ip/IpClientIntegrationTestCommon.java +++ b/tests/integration/common/android/net/ip/IpClientIntegrationTestCommon.java
@@ -4905,7 +4905,25 @@ handleDhcp6Packets(prefix, true /* shouldReplyRapidCommit */); final ArgumentCaptor<LinkProperties> captor = ArgumentCaptor.forClass(LinkProperties.class); verify(mCb, timeout(TEST_TIMEOUT_MS)).onProvisioningSuccess(captor.capture()); - assertTrue(hasIpv6AddressPrefixedWith(captor.getValue(), prefix)); + final LinkProperties lp = captor.getValue(); + assertTrue(hasIpv6AddressPrefixedWith(lp, prefix)); + + // Only run the test when the flag of parsing netlink events is enabled, where the + // deprecationTime and expirationTime is set. + if (mIsNetlinkEventParseEnabled) { + final long now = SystemClock.elapsedRealtime(); + long when = 0; + for (LinkAddress la : lp.getLinkAddresses()) { + if (la.getAddress().isLinkLocalAddress()) { + assertLinkAddressPermanentLifetime(la); + } else if (la.isGlobalPreferred()) { + when = now + 4500 * 1000; // preferred=4500s + assertLinkAddressDeprecationTime(la, when); + when = now + 7200 * 1000; // valid=7200s + assertLinkAddressExpirationTime(la, when); + } + } + } } @Test