1 #pragma once 2 3 #include "config_parser.hpp" 4 5 #include <sdbusplus/bus.hpp> 6 #include <sdbusplus/server/object.hpp> 7 #include <string> 8 #include <xyz/openbmc_project/Network/DHCPConfiguration/server.hpp> 9 10 namespace phosphor 11 { 12 namespace network 13 { 14 15 class Manager; // forward declaration of network manager. 16 17 namespace dhcp 18 { 19 20 using ConfigIntf = 21 sdbusplus::xyz::openbmc_project::Network::server::DHCPConfiguration; 22 23 using Iface = sdbusplus::server::object::object<ConfigIntf>; 24 25 /** @class Configuration 26 * @brief DHCP configuration. 27 * @details A concrete implementation for the 28 * xyz.openbmc_project.Network.DHCP DBus interface. 29 */ 30 class Configuration : public Iface 31 { 32 public: 33 Configuration() = default; 34 Configuration(const Configuration&) = delete; 35 Configuration& operator=(const Configuration&) = delete; 36 Configuration(Configuration&&) = delete; 37 Configuration& operator=(Configuration&&) = delete; 38 virtual ~Configuration() = default; 39 40 /** @brief Constructor to put object onto bus at a dbus path. 41 * @param[in] bus - Bus to attach to. 42 * @param[in] objPath - Path to attach at. 43 * @param[in] parent - Parent object. 44 */ 45 Configuration(sdbusplus::bus::bus& bus, const std::string& objPath, 46 Manager& parent) : 47 Iface(bus, objPath.c_str(), Iface::action::defer_emit), 48 bus(bus), manager(parent) 49 { 50 ConfigIntf::dnsEnabled(getDHCPPropFromConf("UseDNS")); 51 ConfigIntf::ntpEnabled(getDHCPPropFromConf("UseNTP")); 52 ConfigIntf::hostNameEnabled(getDHCPPropFromConf("UseHostname")); 53 ConfigIntf::sendHostNameEnabled(getDHCPPropFromConf("SendHostname")); 54 emit_object_added(); 55 } 56 57 /** @brief If true then DNS servers received from the DHCP server 58 * will be used and take precedence over any statically 59 * configured ones. 60 * @param[in] value - true if DNS server needed from DHCP server 61 * else false. 62 */ 63 bool dnsEnabled(bool value) override; 64 65 /** @brief If true then NTP servers received from the DHCP server 66 will be used by systemd-timesyncd. 67 * @param[in] value - true if NTP server needed from DHCP server 68 * else false. 69 */ 70 bool ntpEnabled(bool value) override; 71 72 /** @brief If true then Hostname received from the DHCP server will 73 * be set as the hostname of the system 74 * @param[in] value - true if hostname needed from the DHCP server 75 * else false. 76 * 77 */ 78 bool hostNameEnabled(bool value) override; 79 80 /** @brief if true then it will cause an Option 12 field, i.e machine's 81 * hostname, will be included in the DHCP packet. 82 * @param[in] value - true if machine's host name needs to be included 83 * in the DHCP packet. 84 */ 85 bool sendHostNameEnabled(bool value) override; 86 87 /** @brief read the DHCP Prop value from the configuration file 88 * @param[in] prop - DHCP Prop name. 89 */ 90 bool getDHCPPropFromConf(const std::string& prop); 91 92 /* @brief Network Manager needed the below function to know the 93 * value of the properties (ntpEnabled,dnsEnabled,hostnameEnabled 94 sendHostNameEnabled). 95 * 96 */ 97 using ConfigIntf::dnsEnabled; 98 using ConfigIntf::hostNameEnabled; 99 using ConfigIntf::ntpEnabled; 100 using ConfigIntf::sendHostNameEnabled; 101 102 private: 103 /** @brief sdbusplus DBus bus connection. */ 104 sdbusplus::bus::bus& bus; 105 106 /** @brief Network Manager object. */ 107 phosphor::network::Manager& manager; 108 }; 109 110 } // namespace dhcp 111 } // namespace network 112 } // namespace phosphor 113