blob: b818a59efbc6492b1424c572832e820e828ed472 [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>
Jagpal Singh Gilla2947b42023-04-17 21:10:14 -07007#include <phosphor-logging/lg2.hpp>
Patrick Venture189d44e2018-07-09 12:30:59 -07008#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;
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060018using namespace sdbusplus::xyz::openbmc_project::Common::Error;
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070019
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -070020Configuration::Configuration(sdbusplus::bus_t& bus,
William A. Kennington III9ede1b72022-11-21 01:59:28 -080021 stdplus::const_zstring objPath,
Jishnu CM57dfea92023-05-05 06:07:26 -050022 stdplus::PinnedRef<EthernetInterface> parent,
23 DHCPType type) :
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070024 Iface(bus, objPath.c_str(), Iface::action::defer_emit),
William A. Kennington IIIf179e702024-04-17 00:50:28 -070025 parent(parent)
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070026{
William A. Kennington IIIc3c6b4c2024-04-18 18:54:22 -070027 config::Parser conf(config::pathForIntfConf(
28 parent.get().manager.get().getConfDir(), parent.get().interfaceName()));
Ravi Tejab6595b22024-02-23 05:00:23 -060029 ConfigIntf::domainEnabled(getDHCPProp(conf, type, "UseDomains"), true);
Jishnu CM57dfea92023-05-05 06:07:26 -050030 ConfigIntf::dnsEnabled(getDHCPProp(conf, type, "UseDNS"), true);
31 ConfigIntf::ntpEnabled(getDHCPProp(conf, type, "UseNTP"), true);
32 ConfigIntf::hostNameEnabled(getDHCPProp(conf, type, "UseHostname"), true);
William A. Kennington III44937b12024-04-17 00:28:20 -070033 ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, type, "SendHostname"),
34 true);
Jishnu CM57dfea92023-05-05 06:07:26 -050035
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070036 emit_object_added();
37}
38
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060039bool Configuration::sendHostNameEnabled(bool value)
40{
41 if (value == sendHostNameEnabled())
42 {
43 return value;
44 }
45
46 auto name = ConfigIntf::sendHostNameEnabled(value);
Jishnu CM57dfea92023-05-05 06:07:26 -050047 parent.get().writeConfigurationFile();
48 parent.get().reloadConfigs();
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060049 return name;
50}
51
Ratan Gupta935bc332017-07-11 17:47:14 +053052bool Configuration::hostNameEnabled(bool value)
53{
54 if (value == hostNameEnabled())
55 {
56 return value;
57 }
58
59 auto name = ConfigIntf::hostNameEnabled(value);
Jishnu CM57dfea92023-05-05 06:07:26 -050060 parent.get().writeConfigurationFile();
61 parent.get().reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053062
63 return name;
64}
65
Patrick Williams6aef7692021-05-01 06:39:41 -050066bool Configuration::ntpEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053067{
Patrick Williams6aef7692021-05-01 06:39:41 -050068 if (value == ntpEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053069 {
70 return value;
71 }
72
Patrick Williams6aef7692021-05-01 06:39:41 -050073 auto ntp = ConfigIntf::ntpEnabled(value);
Jishnu CM57dfea92023-05-05 06:07:26 -050074 parent.get().writeConfigurationFile();
75 parent.get().reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053076
77 return ntp;
78}
79
Patrick Williams6aef7692021-05-01 06:39:41 -050080bool Configuration::dnsEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053081{
Patrick Williams6aef7692021-05-01 06:39:41 -050082 if (value == dnsEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053083 {
84 return value;
85 }
86
Patrick Williams6aef7692021-05-01 06:39:41 -050087 auto dns = ConfigIntf::dnsEnabled(value);
Jishnu CM57dfea92023-05-05 06:07:26 -050088 parent.get().writeConfigurationFile();
89 parent.get().reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053090
91 return dns;
92}
93
Ravi Tejab6595b22024-02-23 05:00:23 -060094bool Configuration::domainEnabled(bool value)
95{
96 if (value == domainEnabled())
97 {
98 return value;
99 }
100
101 auto domain = ConfigIntf::domainEnabled(value);
102 parent.get().writeConfigurationFile();
103 parent.get().reloadConfigs();
104
105 return domain;
106}
107
Gunnar Mills57d9c502018-09-14 14:42:34 -0500108} // namespace dhcp
109} // namespace network
110} // namespace phosphor