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