1 #include "dhcp_configuration.hpp" 2 3 #include "config_parser.hpp" 4 #include "network_manager.hpp" 5 6 #include <phosphor-logging/elog-errors.hpp> 7 #include <phosphor-logging/lg2.hpp> 8 #include <xyz/openbmc_project/Common/error.hpp> 9 10 namespace phosphor 11 { 12 namespace network 13 { 14 namespace dhcp 15 { 16 17 using namespace phosphor::network; 18 using namespace sdbusplus::xyz::openbmc_project::Common::Error; 19 20 Configuration::Configuration(sdbusplus::bus_t& bus, 21 stdplus::const_zstring objPath, 22 stdplus::PinnedRef<EthernetInterface> parent, 23 DHCPType type) : 24 Iface(bus, objPath.c_str(), Iface::action::defer_emit), 25 parent(parent) 26 { 27 config::Parser conf(config::pathForIntfConf( 28 parent.get().manager.get().getConfDir(), parent.get().interfaceName())); 29 ConfigIntf::domainEnabled(getDHCPProp(conf, type, "UseDomains"), true); 30 ConfigIntf::dnsEnabled(getDHCPProp(conf, type, "UseDNS"), true); 31 ConfigIntf::ntpEnabled(getDHCPProp(conf, type, "UseNTP"), true); 32 ConfigIntf::hostNameEnabled(getDHCPProp(conf, type, "UseHostname"), true); 33 ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, type, "SendHostname"), 34 true); 35 36 emit_object_added(); 37 } 38 39 bool Configuration::sendHostNameEnabled(bool value) 40 { 41 if (value == sendHostNameEnabled()) 42 { 43 return value; 44 } 45 46 auto name = ConfigIntf::sendHostNameEnabled(value); 47 parent.get().writeConfigurationFile(); 48 parent.get().reloadConfigs(); 49 return name; 50 } 51 52 bool Configuration::hostNameEnabled(bool value) 53 { 54 if (value == hostNameEnabled()) 55 { 56 return value; 57 } 58 59 auto name = ConfigIntf::hostNameEnabled(value); 60 parent.get().writeConfigurationFile(); 61 parent.get().reloadConfigs(); 62 63 return name; 64 } 65 66 bool Configuration::ntpEnabled(bool value) 67 { 68 if (value == ntpEnabled()) 69 { 70 return value; 71 } 72 73 auto ntp = ConfigIntf::ntpEnabled(value); 74 parent.get().writeConfigurationFile(); 75 parent.get().reloadConfigs(); 76 77 return ntp; 78 } 79 80 bool Configuration::dnsEnabled(bool value) 81 { 82 if (value == dnsEnabled()) 83 { 84 return value; 85 } 86 87 auto dns = ConfigIntf::dnsEnabled(value); 88 parent.get().writeConfigurationFile(); 89 parent.get().reloadConfigs(); 90 91 return dns; 92 } 93 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 108 } // namespace dhcp 109 } // namespace network 110 } // namespace phosphor 111