dhcp client: parse the DHCP configurations
Parse the DHCP configuration parameters upon the start of a service.
Bug: 25642025
TEST=compile
Change-Id: I08cb3f33bb4e1aa69b24f7275198cbcc3dbb791c
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