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 | |
| 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 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 23 | using Iface = sdbusplus::server::object::object<ConfigIntf>; |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 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 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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; |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 39 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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(), true), |
| 48 | bus(bus), manager(parent) |
| 49 | { |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 50 | ConfigIntf::dnsEnabled(getDHCPPropFromConf("UseDNS")); |
| 51 | ConfigIntf::ntpEnabled(getDHCPPropFromConf("UseNTP")); |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 52 | ConfigIntf::hostNameEnabled(getDHCPPropFromConf("UseHostname")); |
| 53 | ConfigIntf::sendHostNameEnabled(getDHCPPropFromConf("SendHostname")); |
| 54 | emit_object_added(); |
| 55 | } |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 56 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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 | */ |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 63 | bool dnsEnabled(bool value) override; |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 64 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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 | */ |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 70 | bool ntpEnabled(bool value) override; |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 71 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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; |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 79 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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; |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 86 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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); |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 91 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 92 | /* @brief Network Manager needed the below function to know the |
| 93 | * value of the properties (ntpEnabled,dnsEnabled,hostnameEnabled |
| 94 | sendHostNameEnabled). |
| 95 | * |
| 96 | */ |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 97 | using ConfigIntf::dnsEnabled; |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 98 | using ConfigIntf::hostNameEnabled; |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 99 | using ConfigIntf::ntpEnabled; |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 100 | using ConfigIntf::sendHostNameEnabled; |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 101 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 102 | private: |
| 103 | /** @brief sdbusplus DBus bus connection. */ |
| 104 | sdbusplus::bus::bus& bus; |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 105 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 106 | /** @brief Network Manager object. */ |
| 107 | phosphor::network::Manager& manager; |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | } // namespace dhcp |
| 111 | } // namespace network |
| 112 | } // namespace phosphor |