Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e36007ff authored by Xiao Ma's avatar Xiao Ma Committed by Automerger Merge Worker
Browse files

Merge "Follow-up CL to the change at aosp/1523097." am: eacfd4f4 am: 4cee1ba9 am: 25e0643f

Original change: https://android-review.googlesource.com/c/platform/packages/modules/NetworkStack/+/1566861

Change-Id: I1d5cec41e767b2fe27ef45bd1da2acd59e7a416b
parents 88ca3095 25e0643f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ public class ProvisioningConfiguration {
         *
         * @param: options customized DHCP option stable parcelable list.
         */
        public Builder withDhcpOptions(List<DhcpOption> options) {
        public Builder withDhcpOptions(@Nullable List<DhcpOption> options) {
            mConfig.mDhcpOptions = options;
            return this;
        }
+2 −2
Original line number Diff line number Diff line
@@ -403,7 +403,7 @@ public abstract class DhcpPacket {

    // Set in unit tests, to ensure that the test does not break when run on different devices and
    // on different releases.
    static String testOverrideVendorId = null;
    static String sTestOverrideVendorId = null;

    protected DhcpPacket(int transId, short secs, Inet4Address clientIp, Inet4Address yourIp,
                         Inet4Address nextIp, Inet4Address relayIp,
@@ -779,7 +779,7 @@ public abstract class DhcpPacket {
     * with the customized option value if any.
     */
    private static String getVendorId(@Nullable List<DhcpOption> customizedClientOptions) {
        if (testOverrideVendorId != null) return testOverrideVendorId;
        if (sTestOverrideVendorId != null) return sTestOverrideVendorId;

        String vendorId = "android-dhcp-" + Build.VERSION.RELEASE;
        if (customizedClientOptions != null) {
+12 −0
Original line number Diff line number Diff line
@@ -17,10 +17,14 @@
package android.net.ip

import android.net.ipmemorystore.NetworkAttributes
import android.net.ipmemorystore.OnNetworkAttributesRetrievedListener
import android.net.ipmemorystore.Status
import android.net.ipmemorystore.Status.SUCCESS
import android.util.ArrayMap
import java.net.Inet6Address
import kotlin.test.assertEquals
import org.mockito.Mockito.any
import org.mockito.Mockito.doAnswer
import org.mockito.ArgumentCaptor
import org.mockito.Mockito.eq
import org.mockito.Mockito.never
@@ -69,4 +73,12 @@ class IpClientIntegrationTest : IpClientIntegrationTestCommon() {
    override fun assertNeverNotifyNeighborLost() {
        verify(mCallback, never()).notifyLost(any(), any())
    }

    override fun storeNetworkAttributes(l2Key: String, na: NetworkAttributes) {
        doAnswer { inv ->
            val listener = inv.getArgument<OnNetworkAttributesRetrievedListener>(1)
            listener.onNetworkAttributesRetrieved(Status(SUCCESS), l2Key, na)
            true
        }.`when`(mIpMemoryStore).retrieveNetworkAttributes(eq(l2Key), any())
    }
}
+193 −30
Original line number Diff line number Diff line
@@ -516,6 +516,8 @@ public abstract class IpClientIntegrationTestCommon {

    protected abstract NetworkAttributes getStoredNetworkAttributes(String l2Key, long timeout);

    protected abstract void storeNetworkAttributes(String l2Key, NetworkAttributes na);

    protected abstract void assertIpMemoryNeverStoreNetworkAttributes(String l2Key, long timeout);

    protected abstract void assertNotifyNeighborLost(Inet6Address targetIp);
@@ -2681,20 +2683,20 @@ public abstract class IpClientIntegrationTestCommon {
        verifyDhcpPacketRequestsIPv6OnlyPreferredOption(DhcpRequestPacket.class);
    }

    private void startFromInitRebootStateWithIPv6OnlyPreferredOption(final Integer ipv6OnlyWaitTime,
            final long expectedWaitSecs) throws Exception {
        doAnswer(invocation -> {
            ((OnNetworkAttributesRetrievedListener) invocation.getArgument(1))
                    .onNetworkAttributesRetrieved(new Status(SUCCESS), TEST_L2KEY,
                            new NetworkAttributes.Builder()
    private void setUpRetrievedNetworkAttributesForInitRebootState() {
        final NetworkAttributes na = new NetworkAttributes.Builder()
                .setAssignedV4Address(CLIENT_ADDR)
                .setAssignedV4AddressExpiry(Long.MAX_VALUE) // lease is always valid
                .setMtu(new Integer(TEST_DEFAULT_MTU))
                .setCluster(TEST_CLUSTER)
                .setDnsAddresses(Collections.singletonList(SERVER_ADDR))
                                .build());
            return null;
        }).when(mIpMemoryStore).retrieveNetworkAttributes(eq(TEST_L2KEY), any());
                .build();
        storeNetworkAttributes(TEST_L2KEY, na);
    }

    private void startFromInitRebootStateWithIPv6OnlyPreferredOption(final Integer ipv6OnlyWaitTime,
            final long expectedWaitSecs) throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ProvisioningConfiguration config = new ProvisioningConfiguration.Builder()
                .withoutIpReachabilityMonitor()
@@ -2821,7 +2823,7 @@ public abstract class IpClientIntegrationTestCommon {
    );

    private DhcpPacket doCustomizedDhcpOptionsTest(final List<DhcpOption> options,
             final ScanResultInfo info) throws Exception {
             final ScanResultInfo info, boolean isDhcpLeaseCacheEnabled) throws Exception {
        ProvisioningConfiguration.Builder prov = new ProvisioningConfiguration.Builder()
                .withoutIpReachabilityMonitor()
                .withLayer2Information(new Layer2Information(TEST_L2KEY, TEST_CLUSTER,
@@ -2830,7 +2832,7 @@ public abstract class IpClientIntegrationTestCommon {
                .withDhcpOptions(options)
                .withoutIPv6();

        setDhcpFeatures(false /* isDhcpLeaseCacheEnabled */, false /* isRapidCommitEnabled */,
        setDhcpFeatures(isDhcpLeaseCacheEnabled, false /* isRapidCommitEnabled */,
                false /* isDhcpIpConflictDetectEnabled */, false /* isIPv6OnlyPreferredEnabled */);

        startIpClientProvisioning(prov.build());
@@ -2841,10 +2843,11 @@ public abstract class IpClientIntegrationTestCommon {
    }

    @Test
    public void testCustomizedDhcpOptions() throws Exception {
    public void testDiscoverCustomizedDhcpOptions() throws Exception {
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                false /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
@@ -2852,10 +2855,11 @@ public abstract class IpClientIntegrationTestCommon {
    }

    @Test
    public void testCustomizedDhcpOptions_nullDhcpOptions() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_nullDhcpOptions() throws Exception {
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(null /* options */, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(null /* options */, info,
                false /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
@@ -2863,9 +2867,9 @@ public abstract class IpClientIntegrationTestCommon {
    }

    @Test
    public void testCustomizedDhcpOptions_nullScanResultInfo() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_nullScanResultInfo() throws Exception {
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS,
                null /* scanResultInfo */);
                null /* scanResultInfo */, false /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
@@ -2873,10 +2877,11 @@ public abstract class IpClientIntegrationTestCommon {
    }

    @Test
    public void testCustomizedDhcpOptions_disallowedOui() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_disallowedOui() throws Exception {
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */,
                new byte[]{ 0x00, 0x11, 0x22} /* oui */, (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                false /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
@@ -2884,10 +2889,11 @@ public abstract class IpClientIntegrationTestCommon {
    }

    @Test
    public void testCustomizedDhcpOptions_invalidIeId() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_invalidIeId() throws Exception {
        final ScanResultInfo info = makeScanResultInfo(0xde /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                false /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
@@ -2895,10 +2901,11 @@ public abstract class IpClientIntegrationTestCommon {
    }

    @Test
    public void testCustomizedDhcpOptions_invalidVendorSpecificType() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_invalidVendorSpecificType() throws Exception {
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x10 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                false /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
@@ -2906,7 +2913,7 @@ public abstract class IpClientIntegrationTestCommon {
    }

    @Test
    public void testCustomizedDhcpOptions_disallowedOption() throws Exception {
    public void testDisoverCustomizedDhcpOptions_disallowedOption() throws Exception {
        final List<DhcpOption> options = Arrays.asList(
                makeDhcpOption((byte) 60, TEST_OEM_VENDOR_ID.getBytes()),
                makeDhcpOption((byte) 77, TEST_OEM_USER_CLASS_INFO),
@@ -2914,7 +2921,8 @@ public abstract class IpClientIntegrationTestCommon {
                makeDhcpOption((byte) 26, HexDump.toByteArray(TEST_DEFAULT_MTU)));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                false /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
@@ -2923,7 +2931,7 @@ public abstract class IpClientIntegrationTestCommon {
    }

    @Test
    public void testCustomizedDhcpOptions_disallowedParamRequestOption() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_disallowedParamRequestOption() throws Exception {
        final List<DhcpOption> options = Arrays.asList(
                makeDhcpOption((byte) 60, TEST_OEM_VENDOR_ID.getBytes()),
                makeDhcpOption((byte) 77, TEST_OEM_USER_CLASS_INFO),
@@ -2931,14 +2939,169 @@ public abstract class IpClientIntegrationTestCommon {
                makeDhcpOption((byte) 42, null));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                false /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertArrayEquals(packet.mUserClass, TEST_OEM_USER_CLASS_INFO);
        assertFalse(packet.hasRequestedParam((byte) 42 /* NTP_SERVER */));
    }

    @Test
    public void testDiscoverCustomizedDhcpOptions_ParameterRequestListOnly() throws Exception {
        final List<DhcpOption> options = Arrays.asList(
                // DHCP_USER_CLASS
                makeDhcpOption((byte) 77, null));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                false /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertTrue(packet.hasRequestedParam((byte) 77 /* DHCP_USER_CLASS */));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertArrayEquals(packet.mUserClass, TEST_OEM_USER_CLASS_INFO);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_nullDhcpOptions() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(null /* options */, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_nullScanResultInfo() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS,
                null /* scanResultInfo */, true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_disallowedOui() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */,
                new byte[]{ 0x00, 0x11, 0x22} /* oui */, (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_invalidIeId() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ScanResultInfo info = makeScanResultInfo(0xde /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_invalidVendorSpecificType() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x10 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_disallowedOption() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final List<DhcpOption> options = Arrays.asList(
                makeDhcpOption((byte) 60, TEST_OEM_VENDOR_ID.getBytes()),
                makeDhcpOption((byte) 77, TEST_OEM_USER_CLASS_INFO),
                // Option 26: MTU
                makeDhcpOption((byte) 26, HexDump.toByteArray(TEST_DEFAULT_MTU)));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertArrayEquals(packet.mUserClass, TEST_OEM_USER_CLASS_INFO);
        assertNull(packet.mMtu);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_disallowedParamRequestOption() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final List<DhcpOption> options = Arrays.asList(
                makeDhcpOption((byte) 60, TEST_OEM_VENDOR_ID.getBytes()),
                makeDhcpOption((byte) 77, TEST_OEM_USER_CLASS_INFO),
                // NTP_SERVER
                makeDhcpOption((byte) 42, null));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertArrayEquals(packet.mUserClass, TEST_OEM_USER_CLASS_INFO);
        assertFalse(packet.hasRequestedParam((byte) 42 /* NTP_SERVER */));
    }

    @Test
    public void testRequestCustomizedDhcpOptions_ParameterRequestListOnly() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final List<DhcpOption> options = Arrays.asList(
                // DHCP_USER_CLASS
                makeDhcpOption((byte) 77, null));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertTrue(packet.hasRequestedParam((byte) 77 /* DHCP_USER_CLASS */));
        assertNull(packet.mUserClass);
    }

    private void assertGratuitousNa(final NeighborAdvertisement na) throws Exception {
        final MacAddress etherMulticast =
                NetworkStackUtils.ipv6MulticastToEthernetMulticast(IPV6_ADDR_ALL_ROUTERS_MULTICAST);
+4 −0
Original line number Diff line number Diff line
@@ -271,4 +271,8 @@ class IpClientRootTest : IpClientIntegrationTestCommon() {
    override fun assertNeverNotifyNeighborLost() {
        verify(mCb, never()).onReachabilityLost(anyString())
    }

    override fun storeNetworkAttributes(l2Key: String, na: NetworkAttributes) {
        mStore.storeNetworkAttributes(l2Key, na, null /* listener */)
    }
}
Loading