DHCP Config: Add DomainEnabled D-bus property

This commit implements DomainEnabled D-bus property for DHCP
configuration.
When DomainEnabled is set to true then the domain names received from
the DHCP server

Tested by:
Set DomainEnabled D-bus property to true or false
Check domain name configured on BMC

Change-Id: Ia3db5f5054d4c758be336851175b05ddc05d2eda
Signed-off-by: Ravi Teja <raviteja28031990@gmail.com>
diff --git a/src/dhcp_configuration.cpp b/src/dhcp_configuration.cpp
index 04a56a0..4acfa3d 100644
--- a/src/dhcp_configuration.cpp
+++ b/src/dhcp_configuration.cpp
@@ -49,6 +49,7 @@
         conf.setFile(newest_file.path());
     }
 
+    ConfigIntf::domainEnabled(getDHCPProp(conf, type, "UseDomains"), true);
     ConfigIntf::dnsEnabled(getDHCPProp(conf, type, "UseDNS"), true);
     ConfigIntf::ntpEnabled(getDHCPProp(conf, type, "UseNTP"), true);
     ConfigIntf::hostNameEnabled(getDHCPProp(conf, type, "UseHostname"), true);
@@ -116,6 +117,20 @@
     return dns;
 }
 
+bool Configuration::domainEnabled(bool value)
+{
+    if (value == domainEnabled())
+    {
+        return value;
+    }
+
+    auto domain = ConfigIntf::domainEnabled(value);
+    parent.get().writeConfigurationFile();
+    parent.get().reloadConfigs();
+
+    return domain;
+}
+
 } // namespace dhcp
 } // namespace network
 } // namespace phosphor
diff --git a/src/dhcp_configuration.hpp b/src/dhcp_configuration.hpp
index 95aa203..c5bcf8a 100644
--- a/src/dhcp_configuration.hpp
+++ b/src/dhcp_configuration.hpp
@@ -47,6 +47,12 @@
      */
     bool dnsEnabled(bool value) override;
 
+    /** @brief If true then domain names received from the DHCP server
+     *  @param[in] value - true if domain names needed from DHCP server
+     *                     else false.
+     */
+    bool domainEnabled(bool value) override;
+
     /** @brief If true then NTP servers received from the DHCP server
                will be used by systemd-timesyncd.
      *  @param[in] value - true if NTP server needed from DHCP server
@@ -75,6 +81,7 @@
      *
      */
     using ConfigIntf::dnsEnabled;
+    using ConfigIntf::domainEnabled;
     using ConfigIntf::hostNameEnabled;
     using ConfigIntf::ntpEnabled;
     using ConfigIntf::sendHostNameEnabled;
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 65ea7ac..fffb53a 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -758,8 +758,9 @@
         dhcp4["ClientIdentifier"].emplace_back("mac");
         const auto& conf = *dhcpConfigs[static_cast<int>(DHCPType::v4)];
         auto dns_enabled = conf.dnsEnabled() ? "true" : "false";
+        auto domain_enabled = conf.domainEnabled() ? "true" : "false";
         dhcp4["UseDNS"].emplace_back(dns_enabled);
-        dhcp4["UseDomains"].emplace_back(dns_enabled);
+        dhcp4["UseDomains"].emplace_back(domain_enabled);
         dhcp4["UseNTP"].emplace_back(conf.ntpEnabled() ? "true" : "false");
         dhcp4["UseHostname"].emplace_back(conf.hostNameEnabled() ? "true"
                                                                  : "false");
@@ -770,8 +771,9 @@
         auto& dhcp6 = config.map["DHCPv6"].emplace_back();
         const auto& conf = *dhcpConfigs[static_cast<int>(DHCPType::v6)];
         auto dns_enabled = conf.dnsEnabled() ? "true" : "false";
+        auto domain_enabled = conf.domainEnabled() ? "true" : "false";
         dhcp6["UseDNS"].emplace_back(dns_enabled);
-        dhcp6["UseDomains"].emplace_back(dns_enabled);
+        dhcp6["UseDomains"].emplace_back(domain_enabled);
         dhcp6["UseNTP"].emplace_back(conf.ntpEnabled() ? "true" : "false");
         dhcp6["UseHostname"].emplace_back(conf.hostNameEnabled() ? "true"
                                                                  : "false");