blob: 690ae47beed1b538114da4b94578a2c8cdf64393 [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);
29 manager.writeToConfigurationFile();
30
31 return name;
32}
33
Ratan Gupta935bc332017-07-11 17:47:14 +053034bool Configuration::hostNameEnabled(bool value)
35{
36 if (value == hostNameEnabled())
37 {
38 return value;
39 }
40
41 auto name = ConfigIntf::hostNameEnabled(value);
42 manager.writeToConfigurationFile();
Ratan Gupta895f9e52018-11-26 20:57:34 +053043 manager.restartSystemdUnit(phosphor::network::networkdService);
Ratan Gupta935bc332017-07-11 17:47:14 +053044
45 return name;
46}
47
Patrick Williams6aef7692021-05-01 06:39:41 -050048bool Configuration::ntpEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053049{
Patrick Williams6aef7692021-05-01 06:39:41 -050050 if (value == ntpEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053051 {
52 return value;
53 }
54
Patrick Williams6aef7692021-05-01 06:39:41 -050055 auto ntp = ConfigIntf::ntpEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053056 manager.writeToConfigurationFile();
Ratan Gupta895f9e52018-11-26 20:57:34 +053057 manager.restartSystemdUnit(phosphor::network::networkdService);
58 manager.restartSystemdUnit(phosphor::network::timeSynchdService);
Ratan Gupta935bc332017-07-11 17:47:14 +053059
60 return ntp;
61}
62
Patrick Williams6aef7692021-05-01 06:39:41 -050063bool Configuration::dnsEnabled(bool value)
Ratan Gupta935bc332017-07-11 17:47:14 +053064{
Patrick Williams6aef7692021-05-01 06:39:41 -050065 if (value == dnsEnabled())
Ratan Gupta935bc332017-07-11 17:47:14 +053066 {
67 return value;
68 }
69
Patrick Williams6aef7692021-05-01 06:39:41 -050070 auto dns = ConfigIntf::dnsEnabled(value);
Ratan Gupta935bc332017-07-11 17:47:14 +053071 manager.writeToConfigurationFile();
Ratan Gupta895f9e52018-11-26 20:57:34 +053072 manager.restartSystemdUnit(phosphor::network::networkdService);
Ratan Gupta935bc332017-07-11 17:47:14 +053073
74 return dns;
75}
76
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060077bool Configuration::getDHCPPropFromConf(const std::string& prop)
78{
79 fs::path confPath = manager.getConfDir();
80 auto interfaceStrList = getInterfaces();
81 // get the first interface name, we need it to know config file name.
82 auto interface = *interfaceStrList.begin();
83 auto fileName = systemd::config::networkFilePrefix + interface +
Gunnar Mills57d9c502018-09-14 14:42:34 -050084 systemd::config::networkFileSuffix;
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060085
86 confPath /= fileName;
87 // systemd default behaviour is all DHCP fields should be enabled by
88 // default.
89 auto propValue = true;
90 config::Parser parser(confPath);
91
92 auto rc = config::ReturnCode::SUCCESS;
93 config::ValueList values{};
94 std::tie(rc, values) = parser.getValues("DHCP", prop);
95
96 if (rc != config::ReturnCode::SUCCESS)
97 {
98 log<level::DEBUG>("Unable to get the value from section DHCP",
Gunnar Mills57d9c502018-09-14 14:42:34 -050099 entry("PROP=%s", prop.c_str()), entry("RC=%d", rc));
Nagaraju Goruganti210420a2018-03-07 09:22:28 -0600100 return propValue;
101 }
102
103 if (values[0] == "false")
104 {
105 propValue = false;
106 }
107 return propValue;
108}
Gunnar Mills57d9c502018-09-14 14:42:34 -0500109} // namespace dhcp
110} // namespace network
111} // namespace phosphor