1 #include "dhcp_configuration.hpp"
2 
3 #include "config_parser.hpp"
4 #include "network_manager.hpp"
5 #include "util.hpp"
6 
7 #include <phosphor-logging/elog-errors.hpp>
8 #include <phosphor-logging/log.hpp>
9 #include <xyz/openbmc_project/Common/error.hpp>
10 
11 namespace phosphor
12 {
13 namespace network
14 {
15 namespace dhcp
16 {
17 
18 using namespace phosphor::network;
19 using namespace phosphor::logging;
20 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
21 
22 Configuration::Configuration(sdbusplus::bus_t& bus,
23                              stdplus::const_zstring objPath, Manager& parent) :
24     Iface(bus, objPath.c_str(), Iface::action::defer_emit),
25     bus(bus), manager(parent)
26 {
27     config::Parser conf;
28     {
29         auto interfaceStrList = getSystemInterfaces();
30         if (!interfaceStrList.empty())
31         {
32             conf.setFile(config::pathForIntfConf(manager.getConfDir(),
33                                                  *interfaceStrList.begin()));
34         }
35     }
36 
37     ConfigIntf::dnsEnabled(getDHCPProp(conf, "UseDNS"));
38     ConfigIntf::ntpEnabled(getDHCPProp(conf, "UseNTP"));
39     ConfigIntf::hostNameEnabled(getDHCPProp(conf, "UseHostname"));
40     ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, "SendHostname"));
41     emit_object_added();
42 }
43 
44 bool Configuration::sendHostNameEnabled(bool value)
45 {
46     if (value == sendHostNameEnabled())
47     {
48         return value;
49     }
50 
51     auto name = ConfigIntf::sendHostNameEnabled(value);
52 
53     manager.writeToConfigurationFile();
54     manager.reloadConfigs();
55 
56     return name;
57 }
58 
59 bool Configuration::hostNameEnabled(bool value)
60 {
61     if (value == hostNameEnabled())
62     {
63         return value;
64     }
65 
66     auto name = ConfigIntf::hostNameEnabled(value);
67     manager.writeToConfigurationFile();
68     manager.reloadConfigs();
69 
70     return name;
71 }
72 
73 bool Configuration::ntpEnabled(bool value)
74 {
75     if (value == ntpEnabled())
76     {
77         return value;
78     }
79 
80     auto ntp = ConfigIntf::ntpEnabled(value);
81     manager.writeToConfigurationFile();
82     manager.reloadConfigs();
83 
84     return ntp;
85 }
86 
87 bool Configuration::dnsEnabled(bool value)
88 {
89     if (value == dnsEnabled())
90     {
91         return value;
92     }
93 
94     auto dns = ConfigIntf::dnsEnabled(value);
95     manager.writeToConfigurationFile();
96     manager.reloadConfigs();
97 
98     return dns;
99 }
100 
101 } // namespace dhcp
102 } // namespace network
103 } // namespace phosphor
104