blob: 6fb24d0f56deccc17a821f80e8d4ffbcecc85296 [file] [log] [blame]
Gunnar Mills57d9c502018-09-14 14:42:34 -05001#include "config.h"
2
Ratan Gupta935bc332017-07-11 17:47:14 +05303#include "dhcp_configuration.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07004
Ratan Gupta935bc332017-07-11 17:47:14 +05305#include "network_manager.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;
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060021bool Configuration::sendHostNameEnabled(bool value)
22{
23 if (value == sendHostNameEnabled())
24 {
25 return value;
26 }
27
28 auto name = ConfigIntf::sendHostNameEnabled(value);
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070029
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060030 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070031 manager.reloadConfigs();
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060032
33 return name;
34}
35
Ratan Gupta935bc332017-07-11 17:47:14 +053036bool Configuration::hostNameEnabled(bool value)
37{
38 if (value == hostNameEnabled())
39 {
40 return value;
41 }
42
43 auto name = ConfigIntf::hostNameEnabled(value);
44 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070045 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053046
47 return name;
48}
49
Patrick Williams6aef7692021-05-01 06:39:41 -050050bool Configuration::ntpEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053051{
Patrick Williams6aef7692021-05-01 06:39:41 -050052 if (value == ntpEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053053 {
54 return value;
55 }
56
Patrick Williams6aef7692021-05-01 06:39:41 -050057 auto ntp = ConfigIntf::ntpEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053058 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070059 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053060
61 return ntp;
62}
63
Patrick Williams6aef7692021-05-01 06:39:41 -050064bool Configuration::dnsEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053065{
Patrick Williams6aef7692021-05-01 06:39:41 -050066 if (value == dnsEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053067 {
68 return value;
69 }
70
Patrick Williams6aef7692021-05-01 06:39:41 -050071 auto dns = ConfigIntf::dnsEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053072 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070073 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053074
75 return dns;
76}
77
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060078bool Configuration::getDHCPPropFromConf(const std::string& prop)
79{
80 fs::path confPath = manager.getConfDir();
81 auto interfaceStrList = getInterfaces();
82 // get the first interface name, we need it to know config file name.
83 auto interface = *interfaceStrList.begin();
84 auto fileName = systemd::config::networkFilePrefix + interface +
Gunnar Mills57d9c502018-09-14 14:42:34 -050085 systemd::config::networkFileSuffix;
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060086
87 confPath /= fileName;
88 // systemd default behaviour is all DHCP fields should be enabled by
89 // default.
90 auto propValue = true;
91 config::Parser parser(confPath);
92
93 auto rc = config::ReturnCode::SUCCESS;
94 config::ValueList values{};
95 std::tie(rc, values) = parser.getValues("DHCP", prop);
96
97 if (rc != config::ReturnCode::SUCCESS)
98 {
99 log<level::DEBUG>("Unable to get the value from section DHCP",
Gunnar Mills57d9c502018-09-14 14:42:34 -0500100 entry("PROP=%s", prop.c_str()), entry("RC=%d", rc));
Nagaraju Goruganti210420a2018-03-07 09:22:28 -0600101 return propValue;
102 }
103
104 if (values[0] == "false")
105 {
106 propValue = false;
107 }
108 return propValue;
109}
Gunnar Mills57d9c502018-09-14 14:42:34 -0500110} // namespace dhcp
111} // namespace network
112} // namespace phosphor