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

Commit f443bfc2 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Always send the DHCP client identifier.

Currently we send it only in request packets, but not in discover
packets. This might confuse servers because they might think that
the discover and the request come from different clients.

Also reorder the options in the request packet to match the order
used by the legacy DHCP client.

While I'm at it, fix the generation code for inform and decline
packets, which we do not use.

Bug: 19704592
Bug: 20335221
Change-Id: I1d45306e76dbd5da9cc4611e6df84a9f67346b2c
parent 7428de19
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -53,6 +53,9 @@ class DhcpDeclinePacket extends DhcpPacket {
     * Adds optional parameters to the DECLINE packet.
     * Adds optional parameters to the DECLINE packet.
     */
     */
    void finishPacket(ByteBuffer buffer) {
    void finishPacket(ByteBuffer buffer) {
        // None needed
        addTlv(buffer, DHCP_MESSAGE_TYPE, DHCP_MESSAGE_TYPE_DECLINE);
        addTlv(buffer, DHCP_CLIENT_IDENTIFIER, getClientId());
        // RFC 2131 says we MUST NOT include our common client TLVs or the parameter request list.
        addTlvEnd(buffer);
    }
    }
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -52,6 +52,7 @@ class DhcpDiscoverPacket extends DhcpPacket {
     */
     */
    void finishPacket(ByteBuffer buffer) {
    void finishPacket(ByteBuffer buffer) {
        addTlv(buffer, DHCP_MESSAGE_TYPE, DHCP_MESSAGE_TYPE_DISCOVER);
        addTlv(buffer, DHCP_MESSAGE_TYPE, DHCP_MESSAGE_TYPE_DISCOVER);
        addTlv(buffer, DHCP_CLIENT_IDENTIFIER, getClientId());
        addCommonClientTlvs(buffer);
        addCommonClientTlvs(buffer);
        addTlv(buffer, DHCP_PARAMETER_LIST, mRequestedParams);
        addTlv(buffer, DHCP_PARAMETER_LIST, mRequestedParams);
        addTlvEnd(buffer);
        addTlvEnd(buffer);
+3 −6
Original line number Original line Diff line number Diff line
@@ -53,12 +53,9 @@ class DhcpInformPacket extends DhcpPacket {
     * Adds additional parameters to the INFORM packet.
     * Adds additional parameters to the INFORM packet.
     */
     */
    void finishPacket(ByteBuffer buffer) {
    void finishPacket(ByteBuffer buffer) {
        byte[] clientId = new byte[7];
        addTlv(buffer, DHCP_MESSAGE_TYPE, DHCP_MESSAGE_TYPE_INFORM);

        addTlv(buffer, DHCP_CLIENT_IDENTIFIER, getClientId());
        clientId[0] = CLIENT_ID_ETHER;
        addCommonClientTlvs(buffer);
        System.arraycopy(mClientMac, 0, clientId, 1, 6);

        addTlv(buffer, DHCP_MESSAGE_TYPE, DHCP_MESSAGE_TYPE_REQUEST);
        addTlv(buffer, DHCP_PARAMETER_LIST, mRequestedParams);
        addTlv(buffer, DHCP_PARAMETER_LIST, mRequestedParams);
        addTlvEnd(buffer);
        addTlvEnd(buffer);
    }
    }
+10 −0
Original line number Original line Diff line number Diff line
@@ -284,6 +284,16 @@ abstract class DhcpPacket {
        return mClientMac;
        return mClientMac;
    }
    }


    /**
     * Returns the client ID. This follows RFC 2132 and is based on the hardware address.
     */
    public byte[] getClientId() {
        byte[] clientId = new byte[mClientMac.length + 1];
        clientId[0] = CLIENT_ID_ETHER;
        System.arraycopy(mClientMac, 0, clientId, 1, mClientMac.length);
        return clientId;
    }

    /**
    /**
     * Creates a new L3 packet (including IP header) containing the
     * Creates a new L3 packet (including IP header) containing the
     * DHCP udp packet.  This method relies upon the delegated method
     * DHCP udp packet.  This method relies upon the delegated method
+1 −7
Original line number Original line Diff line number Diff line
@@ -56,20 +56,14 @@ class DhcpRequestPacket extends DhcpPacket {
     * Adds the optional parameters to the client-generated REQUEST packet.
     * Adds the optional parameters to the client-generated REQUEST packet.
     */
     */
    void finishPacket(ByteBuffer buffer) {
    void finishPacket(ByteBuffer buffer) {
        byte[] clientId = new byte[7];

        // assemble client identifier
        clientId[0] = CLIENT_ID_ETHER;
        System.arraycopy(mClientMac, 0, clientId, 1, 6);

        addTlv(buffer, DHCP_MESSAGE_TYPE, DHCP_MESSAGE_TYPE_REQUEST);
        addTlv(buffer, DHCP_MESSAGE_TYPE, DHCP_MESSAGE_TYPE_REQUEST);
        addTlv(buffer, DHCP_CLIENT_IDENTIFIER, getClientId());
        if (!INADDR_ANY.equals(mRequestedIp)) {
        if (!INADDR_ANY.equals(mRequestedIp)) {
            addTlv(buffer, DHCP_REQUESTED_IP, mRequestedIp);
            addTlv(buffer, DHCP_REQUESTED_IP, mRequestedIp);
        }
        }
        if (!INADDR_ANY.equals(mServerIdentifier)) {
        if (!INADDR_ANY.equals(mServerIdentifier)) {
            addTlv(buffer, DHCP_SERVER_IDENTIFIER, mServerIdentifier);
            addTlv(buffer, DHCP_SERVER_IDENTIFIER, mServerIdentifier);
        }
        }
        addTlv(buffer, DHCP_CLIENT_IDENTIFIER, clientId);
        addCommonClientTlvs(buffer);
        addCommonClientTlvs(buffer);
        addTlv(buffer, DHCP_PARAMETER_LIST, mRequestedParams);
        addTlv(buffer, DHCP_PARAMETER_LIST, mRequestedParams);
        addTlvEnd(buffer);
        addTlvEnd(buffer);