blob: 0605a6a47256203c4ac190354d05f29832fcc38a [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
William A. Kennington III25511a12022-08-04 16:32:28 -07007#include <fmt/format.h>
8
Nagaraju Goruganti210420a2018-03-07 09:22:28 -06009#include <phosphor-logging/elog-errors.hpp>
Patrick Venture189d44e2018-07-09 12:30:59 -070010#include <phosphor-logging/log.hpp>
11#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta935bc332017-07-11 17:47:14 +053012
13namespace phosphor
14{
15namespace network
16{
17namespace dhcp
18{
19
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060020using namespace phosphor::network;
21using namespace phosphor::logging;
22using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060023bool Configuration::sendHostNameEnabled(bool value)
24{
25 if (value == sendHostNameEnabled())
26 {
27 return value;
28 }
29
30 auto name = ConfigIntf::sendHostNameEnabled(value);
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070031
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060032 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070033 manager.reloadConfigs();
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060034
35 return name;
36}
37
Ratan Gupta935bc332017-07-11 17:47:14 +053038bool Configuration::hostNameEnabled(bool value)
39{
40 if (value == hostNameEnabled())
41 {
42 return value;
43 }
44
45 auto name = ConfigIntf::hostNameEnabled(value);
46 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070047 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053048
49 return name;
50}
51
Patrick Williams6aef7692021-05-01 06:39:41 -050052bool Configuration::ntpEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053053{
Patrick Williams6aef7692021-05-01 06:39:41 -050054 if (value == ntpEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053055 {
56 return value;
57 }
58
Patrick Williams6aef7692021-05-01 06:39:41 -050059 auto ntp = ConfigIntf::ntpEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053060 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070061 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053062
63 return ntp;
64}
65
Patrick Williams6aef7692021-05-01 06:39:41 -050066bool Configuration::dnsEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053067{
Patrick Williams6aef7692021-05-01 06:39:41 -050068 if (value == dnsEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053069 {
70 return value;
71 }
72
Patrick Williams6aef7692021-05-01 06:39:41 -050073 auto dns = ConfigIntf::dnsEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053074 manager.writeToConfigurationFile();
William A. Kennington IIIbd649af2021-10-08 17:55:13 -070075 manager.reloadConfigs();
Ratan Gupta935bc332017-07-11 17:47:14 +053076
77 return dns;
78}
79
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060080bool Configuration::getDHCPPropFromConf(const std::string& prop)
81{
82 fs::path confPath = manager.getConfDir();
83 auto interfaceStrList = getInterfaces();
84 // get the first interface name, we need it to know config file name.
85 auto interface = *interfaceStrList.begin();
86 auto fileName = systemd::config::networkFilePrefix + interface +
Gunnar Mills57d9c502018-09-14 14:42:34 -050087 systemd::config::networkFileSuffix;
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060088
89 confPath /= fileName;
90 // systemd default behaviour is all DHCP fields should be enabled by
91 // default.
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060092 config::Parser parser(confPath);
93
William A. Kennington III25511a12022-08-04 16:32:28 -070094 const auto& values = parser.getValues("DHCP", prop);
95 if (values.empty())
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060096 {
William A. Kennington III25511a12022-08-04 16:32:28 -070097 auto msg = fmt::format("Missing config section DHCP[{}]", prop);
98 log<level::NOTICE>(msg.c_str(), entry("PROP=%s", prop.c_str()));
99 return true;
Nagaraju Goruganti210420a2018-03-07 09:22:28 -0600100 }
William A. Kennington III25511a12022-08-04 16:32:28 -0700101 return values.back() != "false";
Nagaraju Goruganti210420a2018-03-07 09:22:28 -0600102}
Gunnar Mills57d9c502018-09-14 14:42:34 -0500103} // namespace dhcp
104} // namespace network
105} // namespace phosphor