Fix race condition for mac setting
We have observed that if systemd-networkd reload is invoked by some
other process after a mac config kick off but before the real
phosphor-networkd reload, the interface will be down and never be
brought back up. This CL ensures that the reload happens by touching
the config file.
Change-Id: I094b4dd71b37bb3b61837ee49a3b6d244cc8fe86
Signed-off-by: Yuxiao Zhang <yuxiaozhang@google.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 1a2944e..7a6f4ea 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -7,9 +7,11 @@
#include "system_queries.hpp"
#include "util.hpp"
+#include <fcntl.h>
#include <linux/rtnetlink.h>
#include <net/if.h>
#include <net/if_arp.h>
+#include <sys/stat.h>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/lg2.hpp>
@@ -799,6 +801,8 @@
stdplus::fromStr<stdplus::EtherAddr>(MacAddressIntf::macAddress());
if (newMAC != oldMAC)
{
+ auto path = config::pathForIntfConf(manager.get().getConfDir(),
+ interface);
// Update everything that depends on the MAC value
for (const auto& [_, intf] : manager.get().interfaces)
{
@@ -810,9 +814,10 @@
MacAddressIntf::macAddress(validMAC);
writeConfigurationFile();
- manager.get().addReloadPreHook([interface]() {
+ manager.get().addReloadPreHook([interface, path]() {
// The MAC and LLADDRs will only update if the NIC is already down
system::setNICUp(interface, false);
+ utimensat(AT_FDCWD, path.c_str(), NULL, 0);
});
manager.get().reloadConfigs();
}