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); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 29 | |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 30 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 31 | manager.reloadConfigs(); |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 32 | |
| 33 | return name; |
| 34 | } |
| 35 | |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 36 | bool Configuration::hostNameEnabled(bool value) |
| 37 | { |
| 38 | if (value == hostNameEnabled()) |
| 39 | { |
| 40 | return value; |
| 41 | } |
| 42 | |
| 43 | auto name = ConfigIntf::hostNameEnabled(value); |
| 44 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 45 | manager.reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 46 | |
| 47 | return name; |
| 48 | } |
| 49 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 50 | bool Configuration::ntpEnabled(bool value) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 51 | { |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 52 | if (value == ntpEnabled()) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 53 | { |
| 54 | return value; |
| 55 | } |
| 56 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 57 | auto ntp = ConfigIntf::ntpEnabled(value); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 58 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 59 | manager.reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 60 | |
| 61 | return ntp; |
| 62 | } |
| 63 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 64 | bool Configuration::dnsEnabled(bool value) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 65 | { |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 66 | if (value == dnsEnabled()) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 67 | { |
| 68 | return value; |
| 69 | } |
| 70 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 71 | auto dns = ConfigIntf::dnsEnabled(value); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 72 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 73 | manager.reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 74 | |
| 75 | return dns; |
| 76 | } |
| 77 | |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 78 | bool Configuration::getDHCPPropFromConf(const std::string& prop) |
| 79 | { |
| 80 | fs::path confPath = manager.getConfDir(); |
| 81 | auto interfaceStrList = getInterfaces(); |
| 82 | // get the first interface name, we need it to know config file name. |
| 83 | auto interface = *interfaceStrList.begin(); |
| 84 | auto fileName = systemd::config::networkFilePrefix + interface + |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 85 | systemd::config::networkFileSuffix; |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 86 | |
| 87 | confPath /= fileName; |
| 88 | // systemd default behaviour is all DHCP fields should be enabled by |
| 89 | // default. |
| 90 | auto propValue = true; |
| 91 | config::Parser parser(confPath); |
| 92 | |
| 93 | auto rc = config::ReturnCode::SUCCESS; |
| 94 | config::ValueList values{}; |
| 95 | std::tie(rc, values) = parser.getValues("DHCP", prop); |
| 96 | |
| 97 | if (rc != config::ReturnCode::SUCCESS) |
| 98 | { |
| 99 | log<level::DEBUG>("Unable to get the value from section DHCP", |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 100 | entry("PROP=%s", prop.c_str()), entry("RC=%d", rc)); |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 101 | return propValue; |
| 102 | } |
| 103 | |
| 104 | if (values[0] == "false") |
| 105 | { |
| 106 | propValue = false; |
| 107 | } |
| 108 | return propValue; |
| 109 | } |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 110 | } // namespace dhcp |
| 111 | } // namespace network |
| 112 | } // namespace phosphor |