blob: 5db88e929ff1ca0382607955aa02d1d771ce30c5 [file] [log] [blame]
Ratan Gupta935bc332017-07-11 17:47:14 +05301#pragma once
2
3#include "xyz/openbmc_project/Network/DHCPConfiguration/server.hpp"
4#include <sdbusplus/bus.hpp>
5#include <sdbusplus/server/object.hpp>
Nagaraju Goruganti210420a2018-03-07 09:22:28 -06006#include "config_parser.hpp"
Ratan Gupta935bc332017-07-11 17:47:14 +05307
8#include <string>
9
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
23using 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 */
32class 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 Guptac35481d2017-08-18 06:12:26 +053050 Iface(bus, objPath.c_str(), true),
Ratan Gupta935bc332017-07-11 17:47:14 +053051 bus(bus),
Ratan Guptac35481d2017-08-18 06:12:26 +053052 manager(parent)
53 {
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060054 ConfigIntf::dNSEnabled(getDHCPPropFromConf("UseDNS"));
55 ConfigIntf::nTPEnabled(getDHCPPropFromConf("UseNTP"));
56 ConfigIntf::hostNameEnabled(getDHCPPropFromConf("UseHostname"));
57 ConfigIntf::sendHostNameEnabled(getDHCPPropFromConf("SendHostname"));
Ratan Guptac35481d2017-08-18 06:12:26 +053058 emit_object_added();
59 }
Ratan Gupta935bc332017-07-11 17:47:14 +053060
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 Gorugantie8fca1d2018-02-05 20:32:45 -060084 /** @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 Goruganti210420a2018-03-07 09:22:28 -060091 /** @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 Gupta935bc332017-07-11 17:47:14 +053096 /* @brief Network Manager needed the below function to know the
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060097 * value of the properties (ntpEnabled,dnsEnabled,hostnameEnabled
98 sendHostNameEnabled).
Ratan Gupta935bc332017-07-11 17:47:14 +053099 *
100 */
101 using ConfigIntf::dNSEnabled;
102 using ConfigIntf::nTPEnabled;
103 using ConfigIntf::hostNameEnabled;
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -0600104 using ConfigIntf::sendHostNameEnabled;
Ratan Gupta935bc332017-07-11 17:47:14 +0530105
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