1 #pragma once
2 
3 #include "config_parser.hpp"
4 
5 #include <sdbusplus/bus.hpp>
6 #include <sdbusplus/server/object.hpp>
7 #include <string>
8 #include <xyz/openbmc_project/Network/DHCPConfiguration/server.hpp>
9 
10 #ifndef SDBUSPP_NEW_CAMELCASE
11 #define dnsEnabled dNSEnabled
12 #define ntpEnabled nTPEnabled
13 #endif
14 
15 namespace phosphor
16 {
17 namespace network
18 {
19 
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 
28 using Iface = sdbusplus::server::object::object<ConfigIntf>;
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 {
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;
44 
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     {
55         ConfigIntf::dnsEnabled(getDHCPPropFromConf("UseDNS"));
56         ConfigIntf::ntpEnabled(getDHCPPropFromConf("UseNTP"));
57         ConfigIntf::hostNameEnabled(getDHCPPropFromConf("UseHostname"));
58         ConfigIntf::sendHostNameEnabled(getDHCPPropFromConf("SendHostname"));
59         emit_object_added();
60     }
61 
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      */
68     bool dnsEnabled(bool value) override;
69 
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      */
75     bool ntpEnabled(bool value) override;
76 
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;
84 
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;
91 
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);
96 
97     /* @brief Network Manager needed the below function to know the
98      *        value of the properties (ntpEnabled,dnsEnabled,hostnameEnabled
99               sendHostNameEnabled).
100      *
101      */
102     using ConfigIntf::dnsEnabled;
103     using ConfigIntf::hostNameEnabled;
104     using ConfigIntf::ntpEnabled;
105     using ConfigIntf::sendHostNameEnabled;
106 
107   private:
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 } // namespace dhcp
116 } // namespace network
117 } // namespace phosphor
118