ethernet_interface: Fix updating neighbor
Sometimes our MAC for a neighbor get re-assigned. We want to update the
MAC and not fail to create the object twice.
Change-Id: Ic23c0117fadcd18a39833a5bfeb1561727091365
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 2accc74..5da1440 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -212,10 +212,18 @@
log<level::ERR>(msg.c_str());
return;
}
- staticNeighbors.emplace(
- *info.addr, std::make_unique<Neighbor>(bus, std::string_view(objPath),
- *this, *info.addr, *info.mac,
- Neighbor::State::Permanent));
+
+ if (auto it = staticNeighbors.find(*info.addr); it != staticNeighbors.end())
+ {
+ it->second->NeighborObj::macAddress(std::to_string(*info.mac));
+ }
+ else
+ {
+ staticNeighbors.emplace(*info.addr, std::make_unique<Neighbor>(
+ bus, std::string_view(objPath),
+ *this, *info.addr, *info.mac,
+ Neighbor::State::Permanent));
+ }
}
void EthernetInterface::createStaticNeighborObjects()