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

Commit cc394973 authored by Xiao Ma's avatar Xiao Ma
Browse files

Add a new field changePrefixOnDecline in DhcpServingParamsParcel.

A new boolean flag (changePrefixOnDecline) to be added in
the DhcpServingParamsParcel, indicating whether or not the DHCP
server should request a new prefix (e.g. a different subnet
prefix) from IpServer when receiving DHCPDECLINE message.

Bug: 130741856
Test: atest NetworkStackTests NetworkStackNextTests
Merged-In: I8cb0f844ef98a5f17d4e07e1812a1abf73aa4c07
Change-Id: I8cb0f844ef98a5f17d4e07e1812a1abf73aa4c07
parent 9aef7f0e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,4 +26,5 @@ parcelable DhcpServingParamsParcel {
  int linkMtu;
  boolean metered;
  int clientAddr;
  boolean changePrefixOnDecline;
}
+1 −1
Original line number Diff line number Diff line
@@ -27,5 +27,5 @@ parcelable DhcpServingParamsParcel {
    int linkMtu;
    boolean metered;
    int clientAddr;
    boolean changePrefixOnDecline;
}
+24 −2
Original line number Diff line number Diff line
@@ -90,6 +90,13 @@ public class DhcpServingParams {
    @Nullable
    public final Inet4Address clientAddr;

    /**
     * Indicates whether the DHCP server should request a new prefix from IpServer when receiving
     * DHCPDECLINE message in certain particular link (e.g. there is only one downstream USB
     * tethering client). If it's false, process DHCPDECLINE message as RFC2131#4.3.3 suggests.
     */
    public final boolean changePrefixOnDecline;

    /**
     * Checked exception thrown when some parameters used to build {@link DhcpServingParams} are
     * missing or invalid.
@@ -103,7 +110,8 @@ public class DhcpServingParams {
    private DhcpServingParams(@NonNull LinkAddress serverAddr,
            @NonNull Set<Inet4Address> defaultRouters,
            @NonNull Set<Inet4Address> dnsServers, @NonNull Set<Inet4Address> excludedAddrs,
            long dhcpLeaseTimeSecs, int linkMtu, boolean metered, Inet4Address clientAddr) {
            long dhcpLeaseTimeSecs, int linkMtu, boolean metered, Inet4Address clientAddr,
            boolean changePrefixOnDecline) {
        this.serverAddr = serverAddr;
        this.defaultRouters = defaultRouters;
        this.dnsServers = dnsServers;
@@ -112,6 +120,7 @@ public class DhcpServingParams {
        this.linkMtu = linkMtu;
        this.metered = metered;
        this.clientAddr = clientAddr;
        this.changePrefixOnDecline = changePrefixOnDecline;
    }

    /**
@@ -140,6 +149,7 @@ public class DhcpServingParams {
                .setLinkMtu(parcel.linkMtu)
                .setMetered(parcel.metered)
                .setClientAddr(clientAddr)
                .setChangePrefixOnDecline(parcel.changePrefixOnDecline)
                .build();
    }

@@ -195,6 +205,7 @@ public class DhcpServingParams {
        private int mLinkMtu = MTU_UNSET;
        private boolean mMetered;
        private Inet4Address mClientAddr;
        private boolean mChangePrefixOnDecline;

        /**
         * Set the server address and served prefix for the DHCP server.
@@ -328,6 +339,17 @@ public class DhcpServingParams {
            return this;
        }

        /**
         * Set whether the DHCP server should request a new prefix from IpServer when receiving
         * DHCPDECLINE message in certain particular link.
         *
         * <p>If not set, the default value is false.
         */
        public Builder setChangePrefixOnDecline(boolean changePrefixOnDecline) {
            this.mChangePrefixOnDecline = changePrefixOnDecline;
            return this;
        }

        /**
         * Create a new {@link DhcpServingParams} instance based on parameters set in the builder.
         *
@@ -382,7 +404,7 @@ public class DhcpServingParams {
                    Collections.unmodifiableSet(new HashSet<>(mDefaultRouters)),
                    Collections.unmodifiableSet(new HashSet<>(mDnsServers)),
                    Collections.unmodifiableSet(excl),
                    mDhcpLeaseTimeSecs, mLinkMtu, mMetered, mClientAddr);
                    mDhcpLeaseTimeSecs, mLinkMtu, mMetered, mClientAddr, mChangePrefixOnDecline);
        }
    }

+7 −2
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ public class DhcpServingParamsTest {
    private static final Set<Inet4Address> TEST_EXCLUDED_ADDRS = new HashSet<>(
            Arrays.asList(parseAddr("192.168.0.200"), parseAddr("192.168.0.201")));
    private static final boolean TEST_METERED = true;
    private static final boolean TEST_CHANGE_PREFIX_ON_DECLINE = true;

    @Before
    public void setUp() {
@@ -74,7 +75,8 @@ public class DhcpServingParamsTest {
                .setLinkMtu(TEST_MTU)
                .setExcludedAddrs(TEST_EXCLUDED_ADDRS)
                .setMetered(TEST_METERED)
                .setClientAddr(TEST_CLIENT_ADDR);
                .setClientAddr(TEST_CLIENT_ADDR)
                .setChangePrefixOnDecline(TEST_CHANGE_PREFIX_ON_DECLINE);
    }

    @Test
@@ -101,6 +103,7 @@ public class DhcpServingParamsTest {
        assertEquals(TEST_LINKADDR, params.serverAddr);
        assertEquals(TEST_MTU, params.linkMtu);
        assertEquals(TEST_METERED, params.metered);
        assertEquals(TEST_CHANGE_PREFIX_ON_DECLINE, params.changePrefixOnDecline);

        assertContains(params.excludedAddrs, TEST_EXCLUDED_ADDRS);
        assertContains(params.excludedAddrs, TEST_DEFAULT_ROUTERS);
@@ -182,6 +185,7 @@ public class DhcpServingParamsTest {
        parcel.excludedAddrs = toIntArray(TEST_EXCLUDED_ADDRS);
        parcel.metered = TEST_METERED;
        parcel.clientAddr = inet4AddressToIntHTH(TEST_CLIENT_ADDR);
        parcel.changePrefixOnDecline = TEST_CHANGE_PREFIX_ON_DECLINE;
        final DhcpServingParams parceled = DhcpServingParams.fromParcelableObject(parcel);

        assertEquals(params.defaultRouters, parceled.defaultRouters);
@@ -192,8 +196,9 @@ public class DhcpServingParamsTest {
        assertEquals(params.excludedAddrs, parceled.excludedAddrs);
        assertEquals(params.metered, parceled.metered);
        assertEquals(params.clientAddr, parceled.clientAddr);
        assertEquals(params.changePrefixOnDecline, parceled.changePrefixOnDecline);

        MiscAssertsKt.assertFieldCountEquals(9, DhcpServingParamsParcel.class);
        MiscAssertsKt.assertFieldCountEquals(10, DhcpServingParamsParcel.class);
    }

    @Test(expected = InvalidParameterException.class)