blob: e933161caebb49c63ed39064d8c74921e3f20a68 [file] [log] [blame]
Ratan Gupta935bc332017-07-11 17:47:14 +05301#include "config.h"
2#include "dhcp_configuration.hpp"
3#include "network_manager.hpp"
Nagaraju Goruganti210420a2018-03-07 09:22:28 -06004#include "xyz/openbmc_project/Common/error.hpp"
5#include <phosphor-logging/log.hpp>
6#include <phosphor-logging/elog-errors.hpp>
Ratan Gupta935bc332017-07-11 17:47:14 +05307
8namespace phosphor
9{
10namespace network
11{
12namespace dhcp
13{
14
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060015using namespace phosphor::network;
16using namespace phosphor::logging;
17using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060018bool Configuration::sendHostNameEnabled(bool value)
19{
20 if (value == sendHostNameEnabled())
21 {
22 return value;
23 }
24
25 auto name = ConfigIntf::sendHostNameEnabled(value);
26 manager.writeToConfigurationFile();
27
28 return name;
29}
30
Ratan Gupta935bc332017-07-11 17:47:14 +053031bool Configuration::hostNameEnabled(bool value)
32{
33 if (value == hostNameEnabled())
34 {
35 return value;
36 }
37
38 auto name = ConfigIntf::hostNameEnabled(value);
39 manager.writeToConfigurationFile();
40 restartSystemdUnit(phosphor::network::networkdService);
41
42 return name;
43}
44
45bool Configuration::nTPEnabled(bool value)
46{
47 if (value == nTPEnabled())
48 {
49 return value;
50 }
51
52 auto ntp = ConfigIntf::nTPEnabled(value);
53 manager.writeToConfigurationFile();
54 restartSystemdUnit(phosphor::network::networkdService);
55 restartSystemdUnit(phosphor::network::timeSynchdService);
56
57 return ntp;
58}
59
60
61bool Configuration::dNSEnabled(bool value)
62{
63 if (value == dNSEnabled())
64 {
65 return value;
66 }
67
68 auto dns = ConfigIntf::dNSEnabled(value);
69 manager.writeToConfigurationFile();
70 restartSystemdUnit(phosphor::network::networkdService);
71
72 return dns;
73}
74
Nagaraju Goruganti210420a2018-03-07 09:22:28 -060075bool Configuration::getDHCPPropFromConf(const std::string& prop)
76{
77 fs::path confPath = manager.getConfDir();
78 auto interfaceStrList = getInterfaces();
79 // get the first interface name, we need it to know config file name.
80 auto interface = *interfaceStrList.begin();
81 auto fileName = systemd::config::networkFilePrefix + interface +
82 systemd::config::networkFileSuffix;
83
84 confPath /= fileName;
85 // systemd default behaviour is all DHCP fields should be enabled by
86 // default.
87 auto propValue = true;
88 config::Parser parser(confPath);
89
90 auto rc = config::ReturnCode::SUCCESS;
91 config::ValueList values{};
92 std::tie(rc, values) = parser.getValues("DHCP", prop);
93
94 if (rc != config::ReturnCode::SUCCESS)
95 {
96 log<level::DEBUG>("Unable to get the value from section DHCP",
97 entry("PROP=%s", prop.c_str()),
98 entry("RC=%d", rc));
99 return propValue;
100 }
101
102 if (values[0] == "false")
103 {
104 propValue = false;
105 }
106 return propValue;
107}
Ratan Gupta935bc332017-07-11 17:47:14 +0530108}// namespace dhcp
109}// namespace network
110}// namespace phosphor