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" |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 5 | |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 6 | #include <phosphor-logging/elog-errors.hpp> |
Jagpal Singh Gill | a2947b4 | 2023-04-17 21:10:14 -0700 | [diff] [blame] | 7 | #include <phosphor-logging/lg2.hpp> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 8 | #include <xyz/openbmc_project/Common/error.hpp> |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 9 | |
| 10 | namespace phosphor |
| 11 | { |
| 12 | namespace network |
| 13 | { |
| 14 | namespace dhcp |
| 15 | { |
| 16 | |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 17 | using namespace phosphor::network; |
Nagaraju Goruganti | 210420a | 2018-03-07 09:22:28 -0600 | [diff] [blame] | 18 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
William A. Kennington III | e94c9ff | 2022-08-18 20:12:27 -0700 | [diff] [blame] | 19 | |
William A. Kennington III | be3bd2f | 2022-10-11 14:11:27 -0700 | [diff] [blame] | 20 | Configuration::Configuration(sdbusplus::bus_t& bus, |
William A. Kennington III | 9ede1b7 | 2022-11-21 01:59:28 -0800 | [diff] [blame] | 21 | stdplus::const_zstring objPath, |
Jishnu CM | 57dfea9 | 2023-05-05 06:07:26 -0500 | [diff] [blame] | 22 | stdplus::PinnedRef<EthernetInterface> parent, |
| 23 | DHCPType type) : |
William A. Kennington III | e94c9ff | 2022-08-18 20:12:27 -0700 | [diff] [blame] | 24 | Iface(bus, objPath.c_str(), Iface::action::defer_emit), |
William A. Kennington III | f179e70 | 2024-04-17 00:50:28 -0700 | [diff] [blame] | 25 | parent(parent) |
William A. Kennington III | e94c9ff | 2022-08-18 20:12:27 -0700 | [diff] [blame] | 26 | { |
William A. Kennington III | c3c6b4c | 2024-04-18 18:54:22 -0700 | [diff] [blame^] | 27 | config::Parser conf(config::pathForIntfConf( |
| 28 | parent.get().manager.get().getConfDir(), parent.get().interfaceName())); |
Ravi Teja | b6595b2 | 2024-02-23 05:00:23 -0600 | [diff] [blame] | 29 | ConfigIntf::domainEnabled(getDHCPProp(conf, type, "UseDomains"), true); |
Jishnu CM | 57dfea9 | 2023-05-05 06:07:26 -0500 | [diff] [blame] | 30 | ConfigIntf::dnsEnabled(getDHCPProp(conf, type, "UseDNS"), true); |
| 31 | ConfigIntf::ntpEnabled(getDHCPProp(conf, type, "UseNTP"), true); |
| 32 | ConfigIntf::hostNameEnabled(getDHCPProp(conf, type, "UseHostname"), true); |
William A. Kennington III | 44937b1 | 2024-04-17 00:28:20 -0700 | [diff] [blame] | 33 | ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, type, "SendHostname"), |
| 34 | true); |
Jishnu CM | 57dfea9 | 2023-05-05 06:07:26 -0500 | [diff] [blame] | 35 | |
William A. Kennington III | e94c9ff | 2022-08-18 20:12:27 -0700 | [diff] [blame] | 36 | emit_object_added(); |
| 37 | } |
| 38 | |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 39 | bool Configuration::sendHostNameEnabled(bool value) |
| 40 | { |
| 41 | if (value == sendHostNameEnabled()) |
| 42 | { |
| 43 | return value; |
| 44 | } |
| 45 | |
| 46 | auto name = ConfigIntf::sendHostNameEnabled(value); |
Jishnu CM | 57dfea9 | 2023-05-05 06:07:26 -0500 | [diff] [blame] | 47 | parent.get().writeConfigurationFile(); |
| 48 | parent.get().reloadConfigs(); |
Nagaraju Goruganti | e8fca1d | 2018-02-05 20:32:45 -0600 | [diff] [blame] | 49 | return name; |
| 50 | } |
| 51 | |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 52 | bool Configuration::hostNameEnabled(bool value) |
| 53 | { |
| 54 | if (value == hostNameEnabled()) |
| 55 | { |
| 56 | return value; |
| 57 | } |
| 58 | |
| 59 | auto name = ConfigIntf::hostNameEnabled(value); |
Jishnu CM | 57dfea9 | 2023-05-05 06:07:26 -0500 | [diff] [blame] | 60 | parent.get().writeConfigurationFile(); |
| 61 | parent.get().reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 62 | |
| 63 | return name; |
| 64 | } |
| 65 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 66 | bool Configuration::ntpEnabled(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 == ntpEnabled()) |
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 ntp = ConfigIntf::ntpEnabled(value); |
Jishnu CM | 57dfea9 | 2023-05-05 06:07:26 -0500 | [diff] [blame] | 74 | parent.get().writeConfigurationFile(); |
| 75 | parent.get().reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 76 | |
| 77 | return ntp; |
| 78 | } |
| 79 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 80 | bool Configuration::dnsEnabled(bool value) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 81 | { |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 82 | if (value == dnsEnabled()) |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 83 | { |
| 84 | return value; |
| 85 | } |
| 86 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 87 | auto dns = ConfigIntf::dnsEnabled(value); |
Jishnu CM | 57dfea9 | 2023-05-05 06:07:26 -0500 | [diff] [blame] | 88 | parent.get().writeConfigurationFile(); |
| 89 | parent.get().reloadConfigs(); |
Ratan Gupta | 935bc33 | 2017-07-11 17:47:14 +0530 | [diff] [blame] | 90 | |
| 91 | return dns; |
| 92 | } |
| 93 | |
Ravi Teja | b6595b2 | 2024-02-23 05:00:23 -0600 | [diff] [blame] | 94 | bool Configuration::domainEnabled(bool value) |
| 95 | { |
| 96 | if (value == domainEnabled()) |
| 97 | { |
| 98 | return value; |
| 99 | } |
| 100 | |
| 101 | auto domain = ConfigIntf::domainEnabled(value); |
| 102 | parent.get().writeConfigurationFile(); |
| 103 | parent.get().reloadConfigs(); |
| 104 | |
| 105 | return domain; |
| 106 | } |
| 107 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 108 | } // namespace dhcp |
| 109 | } // namespace network |
| 110 | } // namespace phosphor |