Implement the DHCP configuration interface
This commit implements the below dhcp options
1) DNS
2) NTP
3) HostName
Change-Id: Ifb66fbc86ce38abc79454ecbbf6fb3c65f892c19
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index 6903a75..4c7ab37 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,7 +19,8 @@
util.hpp \
routing_table.hpp \
config_parser.hpp \
- system_configuration.hpp
+ system_configuration.hpp \
+ dhcp_configuration.hpp
phosphor_network_manager_SOURCES = \
ethernet_interface.cpp \
@@ -32,7 +33,8 @@
xyz/openbmc_project/Network/IP/Create/server.cpp \
util.cpp \
routing_table.cpp \
- config_parser.cpp
+ config_parser.cpp \
+ dhcp_configuration.cpp
CLEANFILES = \
xyz/openbmc_project/Network/VLAN/Create/server.cpp \
diff --git a/dhcp_configuration.cpp b/dhcp_configuration.cpp
new file mode 100644
index 0000000..9e88e7c
--- /dev/null
+++ b/dhcp_configuration.cpp
@@ -0,0 +1,58 @@
+#include "config.h"
+#include "dhcp_configuration.hpp"
+#include "network_manager.hpp"
+
+namespace phosphor
+{
+namespace network
+{
+namespace dhcp
+{
+
+bool Configuration::hostNameEnabled(bool value)
+{
+ if (value == hostNameEnabled())
+ {
+ return value;
+ }
+
+ auto name = ConfigIntf::hostNameEnabled(value);
+ manager.writeToConfigurationFile();
+ restartSystemdUnit(phosphor::network::networkdService);
+
+ return name;
+}
+
+bool Configuration::nTPEnabled(bool value)
+{
+ if (value == nTPEnabled())
+ {
+ return value;
+ }
+
+ auto ntp = ConfigIntf::nTPEnabled(value);
+ manager.writeToConfigurationFile();
+ restartSystemdUnit(phosphor::network::networkdService);
+ restartSystemdUnit(phosphor::network::timeSynchdService);
+
+ return ntp;
+}
+
+
+bool Configuration::dNSEnabled(bool value)
+{
+ if (value == dNSEnabled())
+ {
+ return value;
+ }
+
+ auto dns = ConfigIntf::dNSEnabled(value);
+ manager.writeToConfigurationFile();
+ restartSystemdUnit(phosphor::network::networkdService);
+
+ return dns;
+}
+
+}// namespace dhcp
+}// namespace network
+}// namespace phosphor
diff --git a/dhcp_configuration.hpp b/dhcp_configuration.hpp
new file mode 100644
index 0000000..e6e549f
--- /dev/null
+++ b/dhcp_configuration.hpp
@@ -0,0 +1,99 @@
+#pragma once
+
+#include "xyz/openbmc_project/Network/DHCPConfiguration/server.hpp"
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server/object.hpp>
+
+#include <string>
+
+namespace phosphor
+{
+namespace network
+{
+
+constexpr auto networkdService = "systemd-networkd.service";
+constexpr auto timeSynchdService = "systemd-timesyncd.service";
+
+class Manager; // forward declaration of network manager.
+
+namespace dhcp
+{
+
+using ConfigIntf =
+ sdbusplus::xyz::openbmc_project::Network::server::DHCPConfiguration;
+
+using Iface =
+ sdbusplus::server::object::object<ConfigIntf>;
+
+
+/** @class Configuration
+ * @brief DHCP configuration.
+ * @details A concrete implementation for the
+ * xyz.openbmc_project.Network.DHCP DBus interface.
+ */
+class Configuration : public Iface
+{
+ public:
+ Configuration() = default;
+ Configuration(const Configuration&) = delete;
+ Configuration& operator=(const Configuration&) = delete;
+ Configuration(Configuration&&) = delete;
+ Configuration& operator=(Configuration&&) = delete;
+ virtual ~Configuration() = default;
+
+ /** @brief Constructor to put object onto bus at a dbus path.
+ * @param[in] bus - Bus to attach to.
+ * @param[in] objPath - Path to attach at.
+ * @param[in] parent - Parent object.
+ */
+ Configuration(sdbusplus::bus::bus& bus,
+ const std::string& objPath,
+ Manager& parent) :
+ Iface(bus, objPath.c_str()),
+ bus(bus),
+ manager(parent){}
+
+ /** @brief If true then DNS servers received from the DHCP server
+ * will be used and take precedence over any statically
+ * configured ones.
+ * @param[in] value - true if DNS server needed from DHCP server
+ * else false.
+ */
+ bool dNSEnabled(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
+ * else false.
+ */
+ bool nTPEnabled(bool value) override;
+
+ /** @brief If true then Hostname received from the DHCP server will
+ * be set as the hostname of the system
+ * @param[in] value - true if hostname needed from the DHCP server
+ * else false.
+ *
+ */
+ bool hostNameEnabled(bool value) override;
+
+ /* @brief Network Manager needed the below function to know the
+ * value of the properties (ntpEnabled,dnsEnabled,hostnameEnabled).
+ *
+ */
+ using ConfigIntf::dNSEnabled;
+ using ConfigIntf::nTPEnabled;
+ using ConfigIntf::hostNameEnabled;
+
+ private:
+
+ /** @brief sdbusplus DBus bus connection. */
+ sdbusplus::bus::bus& bus;
+
+ /** @brief Network Manager object. */
+ phosphor::network::Manager& manager;
+
+};
+
+} // namespace dhcp
+} // namespace network
+} // namespace phosphor
diff --git a/test/Makefile.am b/test/Makefile.am
index bf1a935..c614975 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -33,6 +33,7 @@
$(top_builddir)/routing_table.cpp \
$(top_builddir)/util.cpp \
$(top_builddir)/system_configuration.cpp \
+ $(top_builddir)/dhcp_configuration.cpp \
$(top_builddir)/config_parser.cpp \
$(top_builddir)/xyz/openbmc_project/Network/VLAN/Create/phosphor_network_manager-server.o \
$(top_builddir)/xyz/openbmc_project/Network/IP/Create/phosphor_network_manager-server.o