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 | |
William A. Kennington III | 25511a1 | 2022-08-04 16:32:28 -0700 | [diff] [blame] | 7 | #include <fmt/format.h> |
| 8 | |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 9 | #include <phosphor-logging/elog-errors.hpp> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 10 | #include <phosphor-logging/log.hpp> |
| 11 | #include <xyz/openbmc_project/Common/error.hpp> |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 12 | |
| 13 | namespace phosphor |
| 14 | { |
| 15 | namespace network |
| 16 | { |
| 17 | namespace dhcp |
| 18 | { |
| 19 | |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 20 | using namespace phosphor::network; |
| 21 | using namespace phosphor::logging; |
| 22 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 23 | bool Configuration::sendHostNameEnabled(bool value) |
| 24 | { |
| 25 | if (value == sendHostNameEnabled()) |
| 26 | { |
| 27 | return value; |
| 28 | } |
| 29 | |
| 30 | auto name = ConfigIntf::sendHostNameEnabled(value); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 31 | |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 32 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 33 | manager.reloadConfigs(); |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 34 | |
| 35 | return name; |
| 36 | } |
| 37 | |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 38 | bool Configuration::hostNameEnabled(bool value) |
| 39 | { |
| 40 | if (value == hostNameEnabled()) |
| 41 | { |
| 42 | return value; |
| 43 | } |
| 44 | |
| 45 | auto name = ConfigIntf::hostNameEnabled(value); |
| 46 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 47 | manager.reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 48 | |
| 49 | return name; |
| 50 | } |
| 51 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 52 | bool Configuration::ntpEnabled(bool value) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 53 | { |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 54 | if (value == ntpEnabled()) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 55 | { |
| 56 | return value; |
| 57 | } |
| 58 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 59 | auto ntp = ConfigIntf::ntpEnabled(value); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 60 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 61 | manager.reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 62 | |
| 63 | return ntp; |
| 64 | } |
| 65 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 66 | bool Configuration::dnsEnabled(bool value) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 67 | { |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 68 | if (value == dnsEnabled()) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 69 | { |
| 70 | return value; |
| 71 | } |
| 72 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 73 | auto dns = ConfigIntf::dnsEnabled(value); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 74 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 75 | manager.reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 76 | |
| 77 | return dns; |
| 78 | } |
| 79 | |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 80 | bool Configuration::getDHCPPropFromConf(const std::string& prop) |
| 81 | { |
| 82 | fs::path confPath = manager.getConfDir(); |
| 83 | auto interfaceStrList = getInterfaces(); |
| 84 | // get the first interface name, we need it to know config file name. |
| 85 | auto interface = *interfaceStrList.begin(); |
| 86 | auto fileName = systemd::config::networkFilePrefix + interface + |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 87 | systemd::config::networkFileSuffix; |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 88 | |
| 89 | confPath /= fileName; |
| 90 | // systemd default behaviour is all DHCP fields should be enabled by |
| 91 | // default. |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 92 | config::Parser parser(confPath); |
| 93 | |
William A. Kennington III | 25511a1 | 2022-08-04 16:32:28 -0700 | [diff] [blame] | 94 | const auto& values = parser.getValues("DHCP", prop); |
| 95 | if (values.empty()) |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 96 | { |
William A. Kennington III | 25511a1 | 2022-08-04 16:32:28 -0700 | [diff] [blame] | 97 | auto msg = fmt::format("Missing config section DHCP[{}]", prop); |
| 98 | log<level::NOTICE>(msg.c_str(), entry("PROP=%s", prop.c_str())); |
| 99 | return true; |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 100 | } |
William A. Kennington III | 25511a1 | 2022-08-04 16:32:28 -0700 | [diff] [blame] | 101 | return values.back() != "false"; |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 102 | } |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 103 | } // namespace dhcp |
| 104 | } // namespace network |
| 105 | } // namespace phosphor |