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