Merge "dhcp client: add class DeviceInfo"
diff --git a/service.cc b/service.cc
index 0ad90e7..eb14588 100644
--- a/service.cc
+++ b/service.cc
@@ -14,9 +14,25 @@
// limitations under the License.
//
-#include "dhcp_client/manager.h"
#include "dhcp_client/service.h"
+#include <string>
+
+#include "dhcp_client/manager.h"
+
+using std::string;
+
+namespace {
+const char kConstantInterfaceName[] = "interface_name";
+const char kConstantDHCPType[] = "type";
+const char kConstantNetworkIdentifier[] = "identifier";
+const char kConstantRequestHostname[] = "request_hostname";
+const char kConstantArpGateway[] = "arp_gateway";
+const char kConstantUnicastArp[] = "unicast_arp";
+const char kConstantRequestNontemporaryAddress[] = "request_na";
+const char kConstantRequestPrefixDelegation[] = "request_pf";
+}
+
namespace dhcp_client {
Service::Service(Manager* manager,
@@ -26,6 +42,7 @@
: manager_(manager),
identifier_(service_identifier),
event_dispatcher_(event_dispatcher),
+ request_hostname_(false),
arp_gateway_(false),
unicast_arp_(false),
request_na_(false),
@@ -43,6 +60,33 @@
}
void Service::ParseConfigs(const brillo::VariantDictionary& configs) {
+ for (const auto& key_and_value : configs) {
+ const std::string& key = key_and_value.first;
+ const auto& value = key_and_value.second;
+ if (key == kConstantInterfaceName && value.IsTypeCompatible<string>()) {
+ interface_name_ = value.Get<string>();
+ } else if (key == kConstantDHCPType && value.IsTypeCompatible<int32_t>()) {
+ type_ = value.Get<int32_t>();
+ } else if (key == kConstantNetworkIdentifier &&
+ value.IsTypeCompatible<string>()) {
+ network_id_ = value.Get<string>();
+ } else if (key == kConstantRequestHostname &&
+ value.IsTypeCompatible<bool>()) {
+ request_hostname_ = value.Get<bool>();
+ } else if (key == kConstantArpGateway && value.IsTypeCompatible<bool>()) {
+ arp_gateway_ = value.Get<bool>();
+ } else if (key == kConstantUnicastArp && value.IsTypeCompatible<bool>()) {
+ unicast_arp_ = value.Get<bool>();
+ } else if (key == kConstantRequestNontemporaryAddress &&
+ value.IsTypeCompatible<bool>()) {
+ request_na_ = value.Get<bool>();
+ } else if (key == kConstantRequestPrefixDelegation &&
+ value.IsTypeCompatible<bool>()) {
+ request_pd_ = value.Get<bool>();
+ } else {
+ LOG(ERROR) << "Invalid configuration with key: " << key;
+ }
+ }
}
} // namespace dhcp_client
diff --git a/service.h b/service.h
index 3f68798..1f3f223 100644
--- a/service.h
+++ b/service.h
@@ -42,27 +42,32 @@
private:
Manager* manager_;
+ // Indentifier number of this service.
int identifier_;
EventDispatcherInterface* event_dispatcher_;
-
+ // Name of the network interface.
std::string interface_name_;
+ // Type of the DHCP service.
+ // It can be IPv4 only or IPv6 only or both.
int type_;
+ // Unique network/connection identifier,
+ // lease will persist to storage if this identifier is specified.
std::string network_id_;
// DHCP IPv4 configurations:
- // Request hostname from server
+ // Request hostname from server.
bool request_hostname_;
- // ARP for default gateway
+ // ARP for default gateway.
bool arp_gateway_;
- // Enable unicast ARP on renew
+ // Enable unicast ARP on renew.
bool unicast_arp_;
// DHCP IPv6 configurations:
- // Request non-temporary address
+ // Request non-temporary address.
bool request_na_;
- // Request prefix delegation
+ // Request prefix delegation.
bool request_pd_;
-
+ // Parse DHCP configurations from the VariantDictionary.
void ParseConfigs(const brillo::VariantDictionary& configs);
DISALLOW_COPY_AND_ASSIGN(Service);