blob: 33b2cbd9f6639d5ae2be6bd4ff74ff221265d57d [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 III2e09d272022-10-14 17:15:00 -07005#include "system_queries.hpp"
William A. Kennington III95530ec2022-08-19 01:44:39 -07006#include "util.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07007
Nagaraju Goruganti210420a2018-03-07 09:22:28 -06008#include <phosphor-logging/elog-errors.hpp>
Patrick Venture189d44e2018-07-09 12:30:59 -07009#include <phosphor-logging/log.hpp>
10#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta935bc332017-07-11 17:47:14 +053011
12namespace phosphor
13{
14namespace network
15{
16namespace dhcp
17{
18
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060019using namespace phosphor::network;
20using namespace phosphor::logging;
21using namespace sdbusplus::xyz::openbmc_project::Common::Error;
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070022
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -070023Configuration::Configuration(sdbusplus::bus_t& bus,
24 stdplus::const_zstring objPath, Manager& parent) :
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070025 Iface(bus, objPath.c_str(), Iface::action::defer_emit),
26 bus(bus), manager(parent)
27{
28 config::Parser conf;
29 {
William A. Kennington III2e09d272022-10-14 17:15:00 -070030 auto interfaceStrList = system::getInterfaces();
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070031 if (!interfaceStrList.empty())
32 {
33 conf.setFile(config::pathForIntfConf(manager.getConfDir(),
34 *interfaceStrList.begin()));
35 }
36 }
37
38 ConfigIntf::dnsEnabled(getDHCPProp(conf, "UseDNS"));
39 ConfigIntf::ntpEnabled(getDHCPProp(conf, "UseNTP"));
40 ConfigIntf::hostNameEnabled(getDHCPProp(conf, "UseHostname"));
41 ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, "SendHostname"));
42 emit_object_added();
43}
44
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060045bool Configuration::sendHostNameEnabled(bool value)
46{
47 if (value == sendHostNameEnabled())
48 {
49 return value;
50 }
51
52 auto name = ConfigIntf::sendHostNameEnabled(value);
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070053
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060054 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070055 manager.reloadConfigs();
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060056
57 return name;
58}
59
Ratan Gupta935bc332017-07-11 17:47:14 +053060bool Configuration::hostNameEnabled(bool value)
61{
62 if (value == hostNameEnabled())
63 {
64 return value;
65 }
66
67 auto name = ConfigIntf::hostNameEnabled(value);
68 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070069 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053070
71 return name;
72}
73
Patrick Williams6aef7692021-05-01 06:39:41 -050074bool Configuration::ntpEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053075{
Patrick Williams6aef7692021-05-01 06:39:41 -050076 if (value == ntpEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053077 {
78 return value;
79 }
80
Patrick Williams6aef7692021-05-01 06:39:41 -050081 auto ntp = ConfigIntf::ntpEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053082 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070083 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053084
85 return ntp;
86}
87
Patrick Williams6aef7692021-05-01 06:39:41 -050088bool Configuration::dnsEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053089{
Patrick Williams6aef7692021-05-01 06:39:41 -050090 if (value == dnsEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053091 {
92 return value;
93 }
94
Patrick Williams6aef7692021-05-01 06:39:41 -050095 auto dns = ConfigIntf::dnsEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053096 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070097 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053098
99 return dns;
100}
101
Gunnar Mills57d9c502018-09-14 14:42:34 -0500102} // namespace dhcp
103} // namespace network
104} // namespace phosphor