Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 1 | #include "dhcp_configuration.hpp" |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 2 | |
William A. Kennington III | e94c9ff | 2022-08-18 20:12:27 -0700 | [diff] [blame] | 3 | #include "config_parser.hpp" |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 4 | #include "network_manager.hpp" |
William A. Kennington III | 95530ec | 2022-08-19 01:44:39 -0700 | [diff] [blame] | 5 | #include "util.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; |
William A. Kennington III | e94c9ff | 2022-08-18 20:12:27 -0700 | [diff] [blame] | 21 | |
| 22 | Configuration::Configuration(sdbusplus::bus_t& bus, const std::string& objPath, |
| 23 | Manager& parent) : |
| 24 | Iface(bus, objPath.c_str(), Iface::action::defer_emit), |
| 25 | bus(bus), manager(parent) |
| 26 | { |
| 27 | config::Parser conf; |
| 28 | { |
| 29 | auto interfaceStrList = getInterfaces(); |
| 30 | if (!interfaceStrList.empty()) |
| 31 | { |
| 32 | conf.setFile(config::pathForIntfConf(manager.getConfDir(), |
| 33 | *interfaceStrList.begin())); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | ConfigIntf::dnsEnabled(getDHCPProp(conf, "UseDNS")); |
| 38 | ConfigIntf::ntpEnabled(getDHCPProp(conf, "UseNTP")); |
| 39 | ConfigIntf::hostNameEnabled(getDHCPProp(conf, "UseHostname")); |
| 40 | ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, "SendHostname")); |
| 41 | emit_object_added(); |
| 42 | } |
| 43 | |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 44 | bool Configuration::sendHostNameEnabled(bool value) |
| 45 | { |
| 46 | if (value == sendHostNameEnabled()) |
| 47 | { |
| 48 | return value; |
| 49 | } |
| 50 | |
| 51 | auto name = ConfigIntf::sendHostNameEnabled(value); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 52 | |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 53 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 54 | manager.reloadConfigs(); |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 55 | |
| 56 | return name; |
| 57 | } |
| 58 | |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 59 | bool Configuration::hostNameEnabled(bool value) |
| 60 | { |
| 61 | if (value == hostNameEnabled()) |
| 62 | { |
| 63 | return value; |
| 64 | } |
| 65 | |
| 66 | auto name = ConfigIntf::hostNameEnabled(value); |
| 67 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 68 | manager.reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 69 | |
| 70 | return name; |
| 71 | } |
| 72 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 73 | bool Configuration::ntpEnabled(bool value) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 74 | { |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 75 | if (value == ntpEnabled()) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 76 | { |
| 77 | return value; |
| 78 | } |
| 79 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 80 | auto ntp = ConfigIntf::ntpEnabled(value); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 81 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 82 | manager.reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 83 | |
| 84 | return ntp; |
| 85 | } |
| 86 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 87 | bool Configuration::dnsEnabled(bool value) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 88 | { |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 89 | if (value == dnsEnabled()) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 90 | { |
| 91 | return value; |
| 92 | } |
| 93 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 94 | auto dns = ConfigIntf::dnsEnabled(value); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 95 | manager.writeToConfigurationFile(); |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 96 | manager.reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 97 | |
| 98 | return dns; |
| 99 | } |
| 100 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 101 | } // namespace dhcp |
| 102 | } // namespace network |
| 103 | } // namespace phosphor |