Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 1 | #include "config.h" |
| 2 | #include "dhcp_configuration.hpp" |
| 3 | #include "network_manager.hpp" |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame^] | 4 | #include "xyz/openbmc_project/Common/error.hpp" |
| 5 | #include <phosphor-logging/log.hpp> |
| 6 | #include <phosphor-logging/elog-errors.hpp> |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace network |
| 11 | { |
| 12 | namespace dhcp |
| 13 | { |
| 14 | |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame^] | 15 | using namespace phosphor::network; |
| 16 | using namespace phosphor::logging; |
| 17 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 18 | bool 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 Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 31 | bool 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 | |
| 45 | bool 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 | |
| 61 | bool 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 Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame^] | 75 | bool 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 Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 108 | }// namespace dhcp |
| 109 | }// namespace network |
| 110 | }// namespace phosphor |