blob: 53d4e916f5f1a8cd6274aae403759f6085a79810 [file] [log] [blame]
Ratan Gupta935bc332017-07-11 17:47:14 +05301#include "dhcp_configuration.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07002
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -07003#include "config_parser.hpp"
Ratan Gupta935bc332017-07-11 17:47:14 +05304#include "network_manager.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07005
Nagaraju Goruganti210420a2018-03-07 09:22:28 -06006#include <phosphor-logging/elog-errors.hpp>
Patrick Venture189d44e2018-07-09 12:30:59 -07007#include <phosphor-logging/log.hpp>
8#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta935bc332017-07-11 17:47:14 +05309
10namespace phosphor
11{
12namespace network
13{
14namespace dhcp
15{
16
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060017using namespace phosphor::network;
18using namespace phosphor::logging;
19using namespace sdbusplus::xyz::openbmc_project::Common::Error;
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070020
21Configuration::Configuration(sdbusplus::bus_t& bus, const std::string& objPath,
22 Manager& parent) :
23 Iface(bus, objPath.c_str(), Iface::action::defer_emit),
24 bus(bus), manager(parent)
25{
26 config::Parser conf;
27 {
28 auto interfaceStrList = getInterfaces();
29 if (!interfaceStrList.empty())
30 {
31 conf.setFile(config::pathForIntfConf(manager.getConfDir(),
32 *interfaceStrList.begin()));
33 }
34 }
35
36 ConfigIntf::dnsEnabled(getDHCPProp(conf, "UseDNS"));
37 ConfigIntf::ntpEnabled(getDHCPProp(conf, "UseNTP"));
38 ConfigIntf::hostNameEnabled(getDHCPProp(conf, "UseHostname"));
39 ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, "SendHostname"));
40 emit_object_added();
41}
42
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060043bool Configuration::sendHostNameEnabled(bool value)
44{
45 if (value == sendHostNameEnabled())
46 {
47 return value;
48 }
49
50 auto name = ConfigIntf::sendHostNameEnabled(value);
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070051
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060052 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070053 manager.reloadConfigs();
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060054
55 return name;
56}
57
Ratan Gupta935bc332017-07-11 17:47:14 +053058bool Configuration::hostNameEnabled(bool value)
59{
60 if (value == hostNameEnabled())
61 {
62 return value;
63 }
64
65 auto name = ConfigIntf::hostNameEnabled(value);
66 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070067 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053068
69 return name;
70}
71
Patrick Williams6aef7692021-05-01 06:39:41 -050072bool Configuration::ntpEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053073{
Patrick Williams6aef7692021-05-01 06:39:41 -050074 if (value == ntpEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053075 {
76 return value;
77 }
78
Patrick Williams6aef7692021-05-01 06:39:41 -050079 auto ntp = ConfigIntf::ntpEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053080 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070081 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053082
83 return ntp;
84}
85
Patrick Williams6aef7692021-05-01 06:39:41 -050086bool Configuration::dnsEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053087{
Patrick Williams6aef7692021-05-01 06:39:41 -050088 if (value == dnsEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053089 {
90 return value;
91 }
92
Patrick Williams6aef7692021-05-01 06:39:41 -050093 auto dns = ConfigIntf::dnsEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053094 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070095 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053096
97 return dns;
98}
99
Gunnar Mills57d9c502018-09-14 14:42:34 -0500100} // namespace dhcp
101} // namespace network
102} // namespace phosphor