1 #include "dhcp_configuration.hpp" 2 3 #include "config_parser.hpp" 4 #include "network_manager.hpp" 5 #include "system_queries.hpp" 6 #include "util.hpp" 7 8 #include <phosphor-logging/elog-errors.hpp> 9 #include <phosphor-logging/log.hpp> 10 #include <xyz/openbmc_project/Common/error.hpp> 11 12 namespace phosphor 13 { 14 namespace network 15 { 16 namespace dhcp 17 { 18 19 using namespace phosphor::network; 20 using namespace phosphor::logging; 21 using namespace sdbusplus::xyz::openbmc_project::Common::Error; 22 23 Configuration::Configuration(sdbusplus::bus_t& bus, 24 stdplus::const_zstring objPath, Manager& parent) : 25 Iface(bus, objPath.c_str(), Iface::action::defer_emit), 26 bus(bus), manager(parent) 27 { 28 config::Parser conf; 29 { 30 auto interfaces = system::getInterfaces(); 31 if (!interfaces.empty()) 32 { 33 conf.setFile(config::pathForIntfConf(manager.getConfDir(), 34 *interfaces[0].name)); 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 45 bool Configuration::sendHostNameEnabled(bool value) 46 { 47 if (value == sendHostNameEnabled()) 48 { 49 return value; 50 } 51 52 auto name = ConfigIntf::sendHostNameEnabled(value); 53 54 manager.writeToConfigurationFile(); 55 manager.reloadConfigsNoRefresh(); 56 57 return name; 58 } 59 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(); 69 manager.reloadConfigsNoRefresh(); 70 71 return name; 72 } 73 74 bool Configuration::ntpEnabled(bool value) 75 { 76 if (value == ntpEnabled()) 77 { 78 return value; 79 } 80 81 auto ntp = ConfigIntf::ntpEnabled(value); 82 manager.writeToConfigurationFile(); 83 manager.reloadConfigsNoRefresh(); 84 85 return ntp; 86 } 87 88 bool Configuration::dnsEnabled(bool value) 89 { 90 if (value == dnsEnabled()) 91 { 92 return value; 93 } 94 95 auto dns = ConfigIntf::dnsEnabled(value); 96 manager.writeToConfigurationFile(); 97 manager.reloadConfigsNoRefresh(); 98 99 return dns; 100 } 101 102 } // namespace dhcp 103 } // namespace network 104 } // namespace phosphor 105