1 #include "config.h" 2 3 #include "dhcp_configuration.hpp" 4 5 #include "network_manager.hpp" 6 7 #include <phosphor-logging/elog-errors.hpp> 8 #include <phosphor-logging/log.hpp> 9 #include <xyz/openbmc_project/Common/error.hpp> 10 11 namespace phosphor 12 { 13 namespace network 14 { 15 namespace dhcp 16 { 17 18 using namespace phosphor::network; 19 using namespace phosphor::logging; 20 using namespace sdbusplus::xyz::openbmc_project::Common::Error; 21 bool Configuration::sendHostNameEnabled(bool value) 22 { 23 if (value == sendHostNameEnabled()) 24 { 25 return value; 26 } 27 28 auto name = ConfigIntf::sendHostNameEnabled(value); 29 manager.writeToConfigurationFile(); 30 31 return name; 32 } 33 34 bool Configuration::hostNameEnabled(bool value) 35 { 36 if (value == hostNameEnabled()) 37 { 38 return value; 39 } 40 41 auto name = ConfigIntf::hostNameEnabled(value); 42 manager.writeToConfigurationFile(); 43 manager.restartSystemdUnit(phosphor::network::networkdService); 44 45 return name; 46 } 47 48 bool Configuration::ntpEnabled(bool value) 49 { 50 if (value == ntpEnabled()) 51 { 52 return value; 53 } 54 55 auto ntp = ConfigIntf::ntpEnabled(value); 56 manager.writeToConfigurationFile(); 57 manager.restartSystemdUnit(phosphor::network::networkdService); 58 manager.restartSystemdUnit(phosphor::network::timeSynchdService); 59 60 return ntp; 61 } 62 63 bool Configuration::dnsEnabled(bool value) 64 { 65 if (value == dnsEnabled()) 66 { 67 return value; 68 } 69 70 auto dns = ConfigIntf::dnsEnabled(value); 71 manager.writeToConfigurationFile(); 72 manager.restartSystemdUnit(phosphor::network::networkdService); 73 74 return dns; 75 } 76 77 bool Configuration::getDHCPPropFromConf(const std::string& prop) 78 { 79 fs::path confPath = manager.getConfDir(); 80 auto interfaceStrList = getInterfaces(); 81 // get the first interface name, we need it to know config file name. 82 auto interface = *interfaceStrList.begin(); 83 auto fileName = systemd::config::networkFilePrefix + interface + 84 systemd::config::networkFileSuffix; 85 86 confPath /= fileName; 87 // systemd default behaviour is all DHCP fields should be enabled by 88 // default. 89 auto propValue = true; 90 config::Parser parser(confPath); 91 92 auto rc = config::ReturnCode::SUCCESS; 93 config::ValueList values{}; 94 std::tie(rc, values) = parser.getValues("DHCP", prop); 95 96 if (rc != config::ReturnCode::SUCCESS) 97 { 98 log<level::DEBUG>("Unable to get the value from section DHCP", 99 entry("PROP=%s", prop.c_str()), entry("RC=%d", rc)); 100 return propValue; 101 } 102 103 if (values[0] == "false") 104 { 105 propValue = false; 106 } 107 return propValue; 108 } 109 } // namespace dhcp 110 } // namespace network 111 } // namespace phosphor 112