dhcp_configuration: Don't depend on interface queries
We want to depend just on the filesystem as that's where we obtain the
information to populate the DHCP config.
Change-Id: I09bc5e8f7d3497cb4c157aa7c6976e58730fa793
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/dhcp_configuration.cpp b/src/dhcp_configuration.cpp
index df71b31..41c364b 100644
--- a/src/dhcp_configuration.cpp
+++ b/src/dhcp_configuration.cpp
@@ -2,9 +2,11 @@
#include "config_parser.hpp"
#include "network_manager.hpp"
-#include "system_queries.hpp"
#include "util.hpp"
+#include <sys/stat.h>
+
+#include <filesystem>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -26,14 +28,26 @@
bus(bus), manager(parent)
{
config::Parser conf;
+ std::filesystem::directory_entry newest_file;
+ time_t newest_time = 0;
+ for (const auto& dirent :
+ std::filesystem::directory_iterator(manager.getConfDir()))
{
- auto interfaces = system::getInterfaces();
- if (!interfaces.empty())
+ struct stat st = {};
+ stat(dirent.path().native().c_str(), &st);
+ if (st.st_mtime > newest_time)
{
- conf.setFile(config::pathForIntfConf(manager.getConfDir(),
- *interfaces[0].name));
+ newest_file = dirent;
+ newest_time = st.st_mtime;
}
}
+ if (newest_file != std::filesystem::directory_entry{})
+ {
+ log<level::INFO>(fmt::format("Using DHCP options from {}",
+ newest_file.path().native())
+ .c_str());
+ conf.setFile(newest_file.path());
+ }
ConfigIntf::dnsEnabled(getDHCPProp(conf, "UseDNS"));
ConfigIntf::ntpEnabled(getDHCPProp(conf, "UseNTP"));