DHCPMessage: support DHCP option 'requested ip address'
This allows the client to request that a particular IP
address be assigned.
Bug: 25642025
TEST=compile and unittes
Change-Id: Icfb44480c79fc8810f6d3c064a6cad8e9b94184d
diff --git a/dhcp_message.cc b/dhcp_message.cc
index 7b9a8b2..64e7bdb 100644
--- a/dhcp_message.cc
+++ b/dhcp_message.cc
@@ -67,7 +67,8 @@
} // namespace
DHCPMessage::DHCPMessage()
- : lease_time_(0),
+ : requested_ip_address_(0),
+ lease_time_(0),
message_type_(0),
server_identifier_(0),
renewal_time_(0),
@@ -313,6 +314,14 @@
LOG(ERROR) << "Failed to write message type option";
return false;
}
+ if (requested_ip_address_ != 0) {
+ if (options_writer->WriteUInt32Option(data,
+ kDHCPOptionRequestedIPAddr,
+ requested_ip_address_) == -1) {
+ LOG(ERROR) << "Failed to write requested ip address option";
+ return false;
+ }
+ }
if (lease_time_ != 0) {
if (options_writer->WriteUInt32Option(data,
kDHCPOptionLeaseTime,
@@ -407,6 +416,10 @@
parameter_request_list_ = parameter_request_list;
}
+void DHCPMessage::SetRequestedIpAddress(uint32_t requested_ip_address) {
+ requested_ip_address_ = requested_ip_address;
+}
+
void DHCPMessage::SetServerIdentifier(uint32_t server_identifier) {
server_identifier_ = server_identifier;
}
diff --git a/dhcp_message.h b/dhcp_message.h
index 39b3929..2275105 100644
--- a/dhcp_message.h
+++ b/dhcp_message.h
@@ -74,6 +74,7 @@
void SetMessageType(uint8_t message_type);
void SetParameterRequestList(
const std::vector<uint8_t>& parameter_request_list);
+ void SetRequestedIpAddress(uint32_t requested_ip_address);
void SetServerIdentifier(uint32_t server_identifier);
void SetTransactionID(uint32_t transaction_id);
void SetVendorSpecificInfo(const shill::ByteString& vendor_specific_info);
@@ -155,6 +156,8 @@
std::string domain_name_;
// Option 43: Vendor Specific Information.
shill::ByteString vendor_specific_info_;
+ // Option 50: Requested IP Address.
+ uint32_t requested_ip_address_;
// Option 51: IP address lease time in unit of seconds.
uint32_t lease_time_;
// Option 53: DHCP message type.
diff --git a/dhcp_options.h b/dhcp_options.h
index 9bd7a24..c215253 100644
--- a/dhcp_options.h
+++ b/dhcp_options.h
@@ -25,6 +25,7 @@
const uint8_t kDHCPOptionDNSServer = 6;
const uint8_t kDHCPOptionDomainName = 15;
const uint8_t kDHCPOptionVendorSpecificInformation = 43;
+const uint8_t kDHCPOptionRequestedIPAddr = 50;
const uint8_t kDHCPOptionLeaseTime = 51;
const uint8_t kDHCPOptionMessageType = 53;
const uint8_t kDHCPOptionServerIdentifier = 54;