Write DHCP configuration parameters

Write the configuration parameters to the
systemd-networkd conf file.

Resolves openbmc/openbmc#1770

Change-Id: I6c9427034827d612ad7f75961461c2f33688fbf9
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/network_manager.cpp b/network_manager.cpp
index 011e978..e9a62ed 100644
--- a/network_manager.cpp
+++ b/network_manager.cpp
@@ -170,13 +170,13 @@
         // DHCP
         if (intf.second->dHCPEnabled() == true)
         {
-            stream << "DHCP=true\n";
-            // write the dhcp section
-            stream << "[DHCP]\n";
-            stream << "ClientIdentifier=mac\n";
+            // write the dhcp section if interface is
+            // configured as dhcp.
+            writeDHCPSection(stream);
             stream.close();
             continue;
         }
+
         // Static
         for (const auto& addr : addrs)
         {
@@ -225,6 +225,27 @@
     restartSystemdUnit("systemd-networkd.service");
 }
 
+void Manager::writeDHCPSection(std::fstream& stream)
+{
+    using namespace std::string_literals;
+    stream << "DHCP=true\n";
+    // write the dhcp section
+    stream << "[DHCP]\n";
+
+    // Hardcoding the client identifier to mac, to address below issue
+    // https://github.com/openbmc/openbmc/issues/1280
+    stream << "ClientIdentifier=mac\n";
+
+    auto value = dhcpConf->dNSEnabled() ? "true"s : "false"s;
+    stream << "UseDNS="s + value + "\n";
+
+    value = dhcpConf->nTPEnabled() ? "true"s : "false"s;
+    stream << "UseNTP="s + value + "\n";
+
+    value = dhcpConf->hostNameEnabled() ? "true"s : "false"s;
+    stream << "UseHostname="s + value + "\n";
+}
+
 bool Manager::getDHCPValue(const std::string& intf)
 {
     bool dhcp = false;