Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame^] | 1 | #include "config.h" |
| 2 | |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 3 | #include "dhcp_configuration.hpp" |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 4 | |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 5 | #include "network_manager.hpp" |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 6 | |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 7 | #include <phosphor-logging/elog-errors.hpp> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 8 | #include <phosphor-logging/log.hpp> |
| 9 | #include <xyz/openbmc_project/Common/error.hpp> |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace network |
| 14 | { |
| 15 | namespace dhcp |
| 16 | { |
| 17 | |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 18 | using namespace phosphor::network; |
| 19 | using namespace phosphor::logging; |
| 20 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 21 | bool 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 Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 34 | bool Configuration::hostNameEnabled(bool value) |
| 35 | { |
| 36 | if (value == hostNameEnabled()) |
| 37 | { |
| 38 | return value; |
| 39 | } |
| 40 | |
| 41 | auto name = ConfigIntf::hostNameEnabled(value); |
| 42 | manager.writeToConfigurationFile(); |
| 43 | restartSystemdUnit(phosphor::network::networkdService); |
| 44 | |
| 45 | return name; |
| 46 | } |
| 47 | |
| 48 | bool Configuration::nTPEnabled(bool value) |
| 49 | { |
| 50 | if (value == nTPEnabled()) |
| 51 | { |
| 52 | return value; |
| 53 | } |
| 54 | |
| 55 | auto ntp = ConfigIntf::nTPEnabled(value); |
| 56 | manager.writeToConfigurationFile(); |
| 57 | restartSystemdUnit(phosphor::network::networkdService); |
| 58 | restartSystemdUnit(phosphor::network::timeSynchdService); |
| 59 | |
| 60 | return ntp; |
| 61 | } |
| 62 | |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 63 | bool 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 Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 77 | bool 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 Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame^] | 84 | systemd::config::networkFileSuffix; |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 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", |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame^] | 99 | entry("PROP=%s", prop.c_str()), entry("RC=%d", rc)); |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 100 | return propValue; |
| 101 | } |
| 102 | |
| 103 | if (values[0] == "false") |
| 104 | { |
| 105 | propValue = false; |
| 106 | } |
| 107 | return propValue; |
| 108 | } |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame^] | 109 | } // namespace dhcp |
| 110 | } // namespace network |
| 111 | } // namespace phosphor |