blob: da785ccdd917e128999a18c6bb6eb9358a753396 [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
Patrick Williamsad205022024-08-16 15:20:07 -040020Configuration::Configuration(
21 sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
22 stdplus::PinnedRef<EthernetInterface> parent, DHCPType type) :
23 Iface(bus, objPath.c_str(), Iface::action::defer_emit), parent(parent)
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070024{
William A. Kennington IIIc3c6b4c2024-04-18 18:54:22 -070025 config::Parser conf(config::pathForIntfConf(
26 parent.get().manager.get().getConfDir(), parent.get().interfaceName()));
Ravi Tejab6595b22024-02-23 05:00:23 -060027 ConfigIntf::domainEnabled(getDHCPProp(conf, type, "UseDomains"), true);
Jishnu CM57dfea92023-05-05 06:07:26 -050028 ConfigIntf::dnsEnabled(getDHCPProp(conf, type, "UseDNS"), true);
29 ConfigIntf::ntpEnabled(getDHCPProp(conf, type, "UseNTP"), true);
30 ConfigIntf::hostNameEnabled(getDHCPProp(conf, type, "UseHostname"), true);
William A. Kennington III44937b12024-04-17 00:28:20 -070031 ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, type, "SendHostname"),
32 true);
Jishnu CM57dfea92023-05-05 06:07:26 -050033
William A. Kennington IIIe94c9ff2022-08-18 20:12:27 -070034 emit_object_added();
35}
36
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060037bool Configuration::sendHostNameEnabled(bool value)
38{
39 if (value == sendHostNameEnabled())
40 {
41 return value;
42 }
43
44 auto name = ConfigIntf::sendHostNameEnabled(value);
Jishnu CM57dfea92023-05-05 06:07:26 -050045 parent.get().writeConfigurationFile();
46 parent.get().reloadConfigs();
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060047 return name;
48}
49
Ratan Gupta935bc332017-07-11 17:47:14 +053050bool Configuration::hostNameEnabled(bool value)
51{
52 if (value == hostNameEnabled())
53 {
54 return value;
55 }
56
57 auto name = ConfigIntf::hostNameEnabled(value);
Jishnu CM57dfea92023-05-05 06:07:26 -050058 parent.get().writeConfigurationFile();
59 parent.get().reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053060
61 return name;
62}
63
Patrick Williams6aef7692021-05-01 06:39:41 -050064bool Configuration::ntpEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053065{
Patrick Williams6aef7692021-05-01 06:39:41 -050066 if (value == ntpEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053067 {
68 return value;
69 }
70
Patrick Williams6aef7692021-05-01 06:39:41 -050071 auto ntp = ConfigIntf::ntpEnabled(value);
Jishnu CM57dfea92023-05-05 06:07:26 -050072 parent.get().writeConfigurationFile();
73 parent.get().reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053074
75 return ntp;
76}
77
Patrick Williams6aef7692021-05-01 06:39:41 -050078bool Configuration::dnsEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053079{
Patrick Williams6aef7692021-05-01 06:39:41 -050080 if (value == dnsEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053081 {
82 return value;
83 }
84
Patrick Williams6aef7692021-05-01 06:39:41 -050085 auto dns = ConfigIntf::dnsEnabled(value);
Jishnu CM57dfea92023-05-05 06:07:26 -050086 parent.get().writeConfigurationFile();
87 parent.get().reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053088
89 return dns;
90}
91
Ravi Tejab6595b22024-02-23 05:00:23 -060092bool Configuration::domainEnabled(bool value)
93{
94 if (value == domainEnabled())
95 {
96 return value;
97 }
98
99 auto domain = ConfigIntf::domainEnabled(value);
100 parent.get().writeConfigurationFile();
101 parent.get().reloadConfigs();
102
103 return domain;
104}
105
Gunnar Mills57d9c502018-09-14 14:42:34 -0500106} // namespace dhcp
107} // namespace network
108} // namespace phosphor