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