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