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
This commit is contained in:
@@ -53,6 +53,9 @@ class DhcpDeclinePacket extends DhcpPacket {
|
||||
* Adds optional parameters to the DECLINE packet.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ class DhcpDiscoverPacket extends DhcpPacket {
|
||||
*/
|
||||
void finishPacket(ByteBuffer buffer) {
|
||||
addTlv(buffer, DHCP_MESSAGE_TYPE, DHCP_MESSAGE_TYPE_DISCOVER);
|
||||
addTlv(buffer, DHCP_CLIENT_IDENTIFIER, getClientId());
|
||||
addCommonClientTlvs(buffer);
|
||||
addTlv(buffer, DHCP_PARAMETER_LIST, mRequestedParams);
|
||||
addTlvEnd(buffer);
|
||||
|
||||
@@ -53,12 +53,9 @@ class DhcpInformPacket extends DhcpPacket {
|
||||
* Adds additional parameters to the INFORM packet.
|
||||
*/
|
||||
void finishPacket(ByteBuffer buffer) {
|
||||
byte[] clientId = new byte[7];
|
||||
|
||||
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_INFORM);
|
||||
addTlv(buffer, DHCP_CLIENT_IDENTIFIER, getClientId());
|
||||
addCommonClientTlvs(buffer);
|
||||
addTlv(buffer, DHCP_PARAMETER_LIST, mRequestedParams);
|
||||
addTlvEnd(buffer);
|
||||
}
|
||||
|
||||
@@ -290,6 +290,16 @@ abstract class DhcpPacket {
|
||||
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
|
||||
* DHCP udp packet. This method relies upon the delegated method
|
||||
|
||||
@@ -56,20 +56,14 @@ class DhcpRequestPacket extends DhcpPacket {
|
||||
* Adds the optional parameters to the client-generated REQUEST packet.
|
||||
*/
|
||||
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_CLIENT_IDENTIFIER, getClientId());
|
||||
if (!INADDR_ANY.equals(mRequestedIp)) {
|
||||
addTlv(buffer, DHCP_REQUESTED_IP, mRequestedIp);
|
||||
}
|
||||
if (!INADDR_ANY.equals(mServerIdentifier)) {
|
||||
addTlv(buffer, DHCP_SERVER_IDENTIFIER, mServerIdentifier);
|
||||
}
|
||||
addTlv(buffer, DHCP_CLIENT_IDENTIFIER, clientId);
|
||||
addCommonClientTlvs(buffer);
|
||||
addTlv(buffer, DHCP_PARAMETER_LIST, mRequestedParams);
|
||||
addTlvEnd(buffer);
|
||||
|
||||
Reference in New Issue
Block a user