summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNingyuan Wang <nywang@google.com>2016-03-29 14:30:20 -0700
committerNingyuan Wang <nywang@google.com>2016-03-30 15:34:54 -0700
commitcf157b7512d880b5da8b54443cbbfc13474b795a (patch)
treeaf5fa0160ccec2d5db8bd60357f16f11aca718fa
parentefb0b950416a94e649cf3501b812cd9d282093f5 (diff)
downloaddhcp_client-cf157b7512d880b5da8b54443cbbfc13474b795a.tar.gz
dhcp client: support broadcast address option
This change allows dhcp client to get a broadcast address from dhcp server. This also changes a few loggings from LOG to DLOG. Bug: 25642025 TEST=compile, and test using python scripts Change-Id: I9fc74f4f1fae01addaae0b5c431b70239dcbff81
-rw-r--r--dhcp_message.cc4
-rw-r--r--dhcp_message.h3
-rw-r--r--dhcp_options.h1
-rw-r--r--dhcpv4.cc22
-rw-r--r--dhcpv4.h2
5 files changed, 27 insertions, 5 deletions
diff --git a/dhcp_message.cc b/dhcp_message.cc
index 75a3935..3041363 100644
--- a/dhcp_message.cc
+++ b/dhcp_message.cc
@@ -68,12 +68,16 @@ struct __attribute__((__packed__)) RawDHCPMessage {
DHCPMessage::DHCPMessage()
: subnet_mask_(0),
+ interface_mtu_(0),
+ broadcast_address_(0),
requested_ip_address_(0),
lease_time_(0),
message_type_(0),
server_identifier_(0),
renewal_time_(0),
rebinding_time_(0) {
+ options_map_.insert(std::make_pair(kDHCPOptionBroadcastAddr,
+ ParserContext(new UInt32Parser(), &broadcast_address_)));
options_map_.insert(std::make_pair(kDHCPOptionMessageType,
ParserContext(new UInt8Parser(), &message_type_)));
options_map_.insert(std::make_pair(kDHCPOptionLeaseTime,
diff --git a/dhcp_message.h b/dhcp_message.h
index e86b4b3..6b46f33 100644
--- a/dhcp_message.h
+++ b/dhcp_message.h
@@ -81,6 +81,7 @@ class DHCPMessage {
void SetVendorSpecificInfo(const shill::ByteString& vendor_specific_info);
// DHCP option and field getters
+ uint32_t broadcast_address() const { return broadcast_address_; }
const shill::ByteString& client_hardware_address() const {
return client_hardware_address_;
}
@@ -158,6 +159,8 @@ class DHCPMessage {
std::string domain_name_;
// Option 26: Interface MTU.
uint16_t interface_mtu_;
+ // Option 28: Broadcast Address.
+ uint32_t broadcast_address_;
// Option 43: Vendor Specific Information.
shill::ByteString vendor_specific_info_;
// Option 50: Requested IP Address.
diff --git a/dhcp_options.h b/dhcp_options.h
index 0ed5bf9..cc843de 100644
--- a/dhcp_options.h
+++ b/dhcp_options.h
@@ -25,6 +25,7 @@ const uint8_t kDHCPOptionRouter = 3;
const uint8_t kDHCPOptionDNSServer = 6;
const uint8_t kDHCPOptionDomainName = 15;
const uint8_t kDHCPOptionInterfaceMTU = 26;
+const uint8_t kDHCPOptionBroadcastAddr = 28;
const uint8_t kDHCPOptionVendorSpecificInformation = 43;
const uint8_t kDHCPOptionRequestedIPAddr = 50;
const uint8_t kDHCPOptionLeaseTime = 51;
diff --git a/dhcpv4.cc b/dhcpv4.cc
index c5a3d3a..90d73a5 100644
--- a/dhcpv4.cc
+++ b/dhcpv4.cc
@@ -65,6 +65,7 @@ const size_t kIPHeaderMaxLength = 60;
const uint8_t kDefaultParameterRequestList[] = {
kDHCPOptionSubnetMask,
kDHCPOptionInterfaceMTU,
+ kDHCPOptionBroadcastAddr,
kDHCPOptionRouter,
kDHCPOptionDNSServer,
kDHCPOptionDomainName,
@@ -101,6 +102,8 @@ const char kIPV4LeaseFilePathFormat[] =
// In this way shill can include this header and parse
// the messages.
+const char kConfigurationKeyBroadcastAddress[] =
+ "BroadcastAddress";
const char kConfigurationKeyDNS[] = "DomainNameServers";
const char kConfigurationKeyDomainName[] = "DomainName";
const char kConfigurationKeyIPAddress[] = "IPAddress";
@@ -429,6 +432,7 @@ void DHCPV4::HandleAck(const DHCPMessage& msg) {
// Set the option parameters.
subnet_mask_ = msg.subnet_mask();
interface_mtu_ = msg.interface_mtu();
+ broadcast_address = msg.broadcast_address();
router_ = msg.router();
dns_server_ = msg.dns_server();
vendor_specific_info_ = msg.vendor_specific_info();
@@ -744,16 +748,23 @@ bool DHCPV4::ValidateOptions(const DHCPMessage& msg) {
// Shill will use a default MTU
// in case no MTU is provided by DHCP.
}
- LOG(INFO) << "Interface MTU: " << msg.interface_mtu();
+ DLOG(INFO) << "Interface MTU: " << msg.interface_mtu();
+
+ if (msg.broadcast_address() == 0) {
+ LOG(WARNING) << "Failed to get a valid Broadcast Address";
+ // Shill will use a default broadcast address
+ // in case no broadcast address is provided by DHCP.
+ }
+ DLOG(INFO) << "Broadcast Address: " << IPtoString(msg.broadcast_address());
std::vector<uint32_t> router = msg.router();
if (router.size() == 0) {
LOG(ERROR) << "Failed to get default gateway address";
return false;
}
- LOG(INFO) << "Routers:";
+ DLOG(INFO) << "Routers:";
for (uint32_t ip : router) {
- LOG(INFO) << IPtoString(ip);
+ DLOG(INFO) << IPtoString(ip);
}
std::vector<uint32_t> dns_server = msg.dns_server();
@@ -762,9 +773,9 @@ bool DHCPV4::ValidateOptions(const DHCPMessage& msg) {
// Shill will use Google DNS server
// in case no DNS server is provided by DHCP.
} else {
- LOG(INFO) << "DNS Server:";
+ DLOG(INFO) << "DNS Server:";
for (uint32_t ip : dns_server) {
- LOG(INFO) << IPtoString(ip);
+ DLOG(INFO) << IPtoString(ip);
}
}
return true;
@@ -830,6 +841,7 @@ void DHCPV4::EmitEvent(const std::string& reason) {
if (reason == kReasonBound) {
configs.emplace(kConfigurationKeyIPAddress, client_ip_);
configs.emplace(kConfigurationKeyMTU, interface_mtu_);
+ configs.emplace(kConfigurationKeyBroadcastAddress, broadcast_address_);
configs.emplace(kConfigurationKeyRouters, router_);
configs.emplace(kConfigurationKeyDNS, dns_server_);
configs.emplace(kConfigurationKeyVendorEncapsulatedOptions,
diff --git a/dhcpv4.h b/dhcpv4.h
index 0d29467..411cf66 100644
--- a/dhcpv4.h
+++ b/dhcpv4.h
@@ -131,6 +131,8 @@ class DHCPV4 : public DHCP {
uint32_t server_ip_;
// Interface mtu.
uint16_t interface_mtu_;
+ // Broadcast address.
+ uint32_t broadcast_address_;
// Aka Default Gateway.
std::vector<uint32_t> router_;
// Domain Name Servers.