blob: 441c7b2a3bf05d54629bc2a4c2f7324cc942c90c [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
Patrick Williams6aef7692021-05-01 06:39:41 -050010#ifndef SDBUSPP_NEW_CAMELCASE
11#define dnsEnabled dNSEnabled
12#define ntpEnabled nTPEnabled
13#endif
14
Ratan Gupta935bc332017-07-11 17:47:14 +053015namespace phosphor
16{
17namespace network
18{
19
Ratan Gupta935bc332017-07-11 17:47:14 +053020class Manager; // forward declaration of network manager.
21
22namespace dhcp
23{
24
25using ConfigIntf =
26 sdbusplus::xyz::openbmc_project::Network::server::DHCPConfiguration;
27
Gunnar Mills57d9c502018-09-14 14:42:34 -050028using Iface = sdbusplus::server::object::object<ConfigIntf>;
Ratan Gupta935bc332017-07-11 17:47:14 +053029
30/** @class Configuration
31 * @brief DHCP configuration.
32 * @details A concrete implementation for the
33 * xyz.openbmc_project.Network.DHCP DBus interface.
34 */
35class Configuration : public Iface
36{
Gunnar Mills57d9c502018-09-14 14:42:34 -050037 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 Gupta935bc332017-07-11 17:47:14 +053044
Gunnar Mills57d9c502018-09-14 14:42:34 -050045 /** @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 Williams6aef7692021-05-01 06:39:41 -050055 ConfigIntf::dnsEnabled(getDHCPPropFromConf("UseDNS"));
56 ConfigIntf::ntpEnabled(getDHCPPropFromConf("UseNTP"));
Gunnar Mills57d9c502018-09-14 14:42:34 -050057 ConfigIntf::hostNameEnabled(getDHCPPropFromConf("UseHostname"));
58 ConfigIntf::sendHostNameEnabled(getDHCPPropFromConf("SendHostname"));
59 emit_object_added();
60 }
Ratan Gupta935bc332017-07-11 17:47:14 +053061
Gunnar Mills57d9c502018-09-14 14:42:34 -050062 /** @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 Williams6aef7692021-05-01 06:39:41 -050068 bool dnsEnabled(bool value) override;
Ratan Gupta935bc332017-07-11 17:47:14 +053069
Gunnar Mills57d9c502018-09-14 14:42:34 -050070 /** @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 Williams6aef7692021-05-01 06:39:41 -050075 bool ntpEnabled(bool value) override;
Ratan Gupta935bc332017-07-11 17:47:14 +053076
Gunnar Mills57d9c502018-09-14 14:42:34 -050077 /** @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 Gupta935bc332017-07-11 17:47:14 +053084
Gunnar Mills57d9c502018-09-14 14:42:34 -050085 /** @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 Gorugantie8fca1d2018-02-05 20:32:45 -060091
Gunnar Mills57d9c502018-09-14 14:42:34 -050092 /** @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 Goruganti210420a2018-03-07 09:22:28 -060096
Gunnar Mills57d9c502018-09-14 14:42:34 -050097 /* @brief Network Manager needed the below function to know the
98 * value of the properties (ntpEnabled,dnsEnabled,hostnameEnabled
99 sendHostNameEnabled).
100 *
101 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500102 using ConfigIntf::dnsEnabled;
Gunnar Mills57d9c502018-09-14 14:42:34 -0500103 using ConfigIntf::hostNameEnabled;
Patrick Williams6aef7692021-05-01 06:39:41 -0500104 using ConfigIntf::ntpEnabled;
Gunnar Mills57d9c502018-09-14 14:42:34 -0500105 using ConfigIntf::sendHostNameEnabled;
Ratan Gupta935bc332017-07-11 17:47:14 +0530106
Gunnar Mills57d9c502018-09-14 14:42:34 -0500107 private:
108 /** @brief sdbusplus DBus bus connection. */
109 sdbusplus::bus::bus& bus;
Ratan Gupta935bc332017-07-11 17:47:14 +0530110
Gunnar Mills57d9c502018-09-14 14:42:34 -0500111 /** @brief Network Manager object. */
112 phosphor::network::Manager& manager;
Ratan Gupta935bc332017-07-11 17:47:14 +0530113};
114
115} // namespace dhcp
116} // namespace network
117} // namespace phosphor