blob: c14f5470d9be6fffc27f1c9be4ad33704e222415 [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"
William A. Kennington III95530ec2022-08-19 01:44:39 -07005#include "util.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07006
Nagaraju Goruganti210420a2018-03-07 09:22:28 -06007#include <phosphor-logging/elog-errors.hpp>
Patrick Venture189d44e2018-07-09 12:30:59 -07008#include <phosphor-logging/log.hpp>
9#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta935bc332017-07-11 17:47:14 +053010
11namespace phosphor
12{
13namespace network
14{
15namespace dhcp
16{
17
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060018using namespace phosphor::network;
19using namespace phosphor::logging;
20using namespace sdbusplus::xyz::openbmc_project::Common::Error;
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070021
22Configuration::Configuration(sdbusplus::bus_t& bus, const std::string& objPath,
23 Manager& parent) :
24 Iface(bus, objPath.c_str(), Iface::action::defer_emit),
25 bus(bus), manager(parent)
26{
27 config::Parser conf;
28 {
William A. Kennington III96444792022-10-05 15:16:22 -070029 auto interfaceStrList = getSystemInterfaces();
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070030 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
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060044bool Configuration::sendHostNameEnabled(bool value)
45{
46 if (value == sendHostNameEnabled())
47 {
48 return value;
49 }
50
51 auto name = ConfigIntf::sendHostNameEnabled(value);
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070052
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060053 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070054 manager.reloadConfigs();
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060055
56 return name;
57}
58
Ratan Gupta935bc332017-07-11 17:47:14 +053059bool Configuration::hostNameEnabled(bool value)
60{
61 if (value == hostNameEnabled())
62 {
63 return value;
64 }
65
66 auto name = ConfigIntf::hostNameEnabled(value);
67 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070068 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053069
70 return name;
71}
72
Patrick Williams6aef7692021-05-01 06:39:41 -050073bool Configuration::ntpEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053074{
Patrick Williams6aef7692021-05-01 06:39:41 -050075 if (value == ntpEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053076 {
77 return value;
78 }
79
Patrick Williams6aef7692021-05-01 06:39:41 -050080 auto ntp = ConfigIntf::ntpEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053081 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070082 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053083
84 return ntp;
85}
86
Patrick Williams6aef7692021-05-01 06:39:41 -050087bool Configuration::dnsEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053088{
Patrick Williams6aef7692021-05-01 06:39:41 -050089 if (value == dnsEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053090 {
91 return value;
92 }
93
Patrick Williams6aef7692021-05-01 06:39:41 -050094 auto dns = ConfigIntf::dnsEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053095 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070096 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053097
98 return dns;
99}
100
Gunnar Mills57d9c502018-09-14 14:42:34 -0500101} // namespace dhcp
102} // namespace network
103} // namespace phosphor