blob: c4a06a986b52278964d777d5c338848a82187b7a [file] [log] [blame]
Ratan Gupta935bc332017-07-11 17:47:14 +05301#pragma once
2
Nagaraju Goruganti210420a2018-03-07 09:22:28 -06003#include "config_parser.hpp"
Ratan Gupta935bc332017-07-11 17:47:14 +05304
Patrick Venture189d44e2018-07-09 12:30:59 -07005#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server/object.hpp>
Ratan Gupta935bc332017-07-11 17:47:14 +05307#include <string>
Patrick Venture189d44e2018-07-09 12:30:59 -07008#include <xyz/openbmc_project/Network/DHCPConfiguration/server.hpp>
Ratan Gupta935bc332017-07-11 17:47:14 +05309
10namespace phosphor
11{
12namespace network
13{
14
Ratan Gupta935bc332017-07-11 17:47:14 +053015class Manager; // forward declaration of network manager.
16
17namespace dhcp
18{
19
20using ConfigIntf =
21 sdbusplus::xyz::openbmc_project::Network::server::DHCPConfiguration;
22
Gunnar Mills57d9c502018-09-14 14:42:34 -050023using Iface = sdbusplus::server::object::object<ConfigIntf>;
Ratan Gupta935bc332017-07-11 17:47:14 +053024
25/** @class Configuration
26 * @brief DHCP configuration.
27 * @details A concrete implementation for the
28 * xyz.openbmc_project.Network.DHCP DBus interface.
29 */
30class Configuration : public Iface
31{
Gunnar Mills57d9c502018-09-14 14:42:34 -050032 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 Gupta935bc332017-07-11 17:47:14 +053039
Gunnar Mills57d9c502018-09-14 14:42:34 -050040 /** @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 Williams6aef7692021-05-01 06:39:41 -050050 ConfigIntf::dnsEnabled(getDHCPPropFromConf("UseDNS"));
51 ConfigIntf::ntpEnabled(getDHCPPropFromConf("UseNTP"));
Gunnar Mills57d9c502018-09-14 14:42:34 -050052 ConfigIntf::hostNameEnabled(getDHCPPropFromConf("UseHostname"));
53 ConfigIntf::sendHostNameEnabled(getDHCPPropFromConf("SendHostname"));
54 emit_object_added();
55 }
Ratan Gupta935bc332017-07-11 17:47:14 +053056
Gunnar Mills57d9c502018-09-14 14:42:34 -050057 /** @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 Williams6aef7692021-05-01 06:39:41 -050063 bool dnsEnabled(bool value) override;
Ratan Gupta935bc332017-07-11 17:47:14 +053064
Gunnar Mills57d9c502018-09-14 14:42:34 -050065 /** @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 Williams6aef7692021-05-01 06:39:41 -050070 bool ntpEnabled(bool value) override;
Ratan Gupta935bc332017-07-11 17:47:14 +053071
Gunnar Mills57d9c502018-09-14 14:42:34 -050072 /** @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 Gupta935bc332017-07-11 17:47:14 +053079
Gunnar Mills57d9c502018-09-14 14:42:34 -050080 /** @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 Gorugantie8fca1d2018-02-05 20:32:45 -060086
Gunnar Mills57d9c502018-09-14 14:42:34 -050087 /** @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 Goruganti210420a2018-03-07 09:22:28 -060091
Gunnar Mills57d9c502018-09-14 14:42:34 -050092 /* @brief Network Manager needed the below function to know the
93 * value of the properties (ntpEnabled,dnsEnabled,hostnameEnabled
94 sendHostNameEnabled).
95 *
96 */
Patrick Williams6aef7692021-05-01 06:39:41 -050097 using ConfigIntf::dnsEnabled;
Gunnar Mills57d9c502018-09-14 14:42:34 -050098 using ConfigIntf::hostNameEnabled;
Patrick Williams6aef7692021-05-01 06:39:41 -050099 using ConfigIntf::ntpEnabled;
Gunnar Mills57d9c502018-09-14 14:42:34 -0500100 using ConfigIntf::sendHostNameEnabled;
Ratan Gupta935bc332017-07-11 17:47:14 +0530101
Gunnar Mills57d9c502018-09-14 14:42:34 -0500102 private:
103 /** @brief sdbusplus DBus bus connection. */
104 sdbusplus::bus::bus& bus;
Ratan Gupta935bc332017-07-11 17:47:14 +0530105
Gunnar Mills57d9c502018-09-14 14:42:34 -0500106 /** @brief Network Manager object. */
107 phosphor::network::Manager& manager;
Ratan Gupta935bc332017-07-11 17:47:14 +0530108};
109
110} // namespace dhcp
111} // namespace network
112} // namespace phosphor