blob: 7451ef62d844a9ffda920319da9d05ee7fbaece6 [file] [log] [blame]
Ratan Gupta935bc332017-07-11 17:47:14 +05301#include "dhcp_configuration.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07002
3#include "config.h"
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>
Patrick Venture189d44e2018-07-09 12:30:59 -07007#include <phosphor-logging/log.hpp>
8#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;
18using namespace phosphor::logging;
19using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Nagaraju Gorugantie8fca1d2018-02-05 20:32:45 -060020bool Configuration::sendHostNameEnabled(bool value)
21{
22 if (value == sendHostNameEnabled())
23 {
24 return value;
25 }
26
27 auto name = ConfigIntf::sendHostNameEnabled(value);
28 manager.writeToConfigurationFile();
29
30 return name;
31}
32
Ratan Gupta935bc332017-07-11 17:47:14 +053033bool Configuration::hostNameEnabled(bool value)
34{
35 if (value == hostNameEnabled())
36 {
37 return value;
38 }
39
40 auto name = ConfigIntf::hostNameEnabled(value);
41 manager.writeToConfigurationFile();
42 restartSystemdUnit(phosphor::network::networkdService);
43
44 return name;
45}
46
47bool Configuration::nTPEnabled(bool value)
48{
49 if (value == nTPEnabled())
50 {
51 return value;
52 }
53
54 auto ntp = ConfigIntf::nTPEnabled(value);
55 manager.writeToConfigurationFile();
56 restartSystemdUnit(phosphor::network::networkdService);
57 restartSystemdUnit(phosphor::network::timeSynchdService);
58
59 return ntp;
60}
61
62
63bool Configuration::dNSEnabled(bool value)
64{
65 if (value == dNSEnabled())
66 {
67 return value;
68 }
69
70 auto dns = ConfigIntf::dNSEnabled(value);
71 manager.writeToConfigurationFile();
72 restartSystemdUnit(phosphor::network::networkdService);
73
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 +
84 systemd::config::networkFileSuffix;
85
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",
99 entry("PROP=%s", prop.c_str()),
100 entry("RC=%d", rc));
101 return propValue;
102 }
103
104 if (values[0] == "false")
105 {
106 propValue = false;
107 }
108 return propValue;
109}
Ratan Gupta935bc332017-07-11 17:47:14 +0530110}// namespace dhcp
111}// namespace network
112}// namespace phosphor