neighbor: Refactor object creation
Change-Id: Ic46d39f4717799ecce1c1fa84096f27e674e69a6
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/neighbor.cpp b/src/neighbor.cpp
index 58e1a47..c9c1fc9 100644
--- a/src/neighbor.cpp
+++ b/src/neighbor.cpp
@@ -2,6 +2,7 @@
#include "ethernet_interface.hpp"
#include "netlink.hpp"
+#include "network_manager.hpp"
#include "util.hpp"
#include <linux/neighbour.h>
@@ -87,14 +88,29 @@
return neighbors;
}
-Neighbor::Neighbor(sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
- EthernetInterface& parent, std::string_view ipAddress,
- std::string_view macAddress, State state) :
- NeighborObj(bus, objPath.c_str(), NeighborObj::action::defer_emit),
- parent(parent)
+static auto makeObjPath(std::string_view root, InAddrAny addr)
{
- NeighborObj::ipAddress(std::string(ipAddress));
- NeighborObj::macAddress(std::string(macAddress));
+ auto ret = sdbusplus::message::object_path(std::string(root));
+ ret /= std::to_string(addr);
+ return ret;
+}
+
+Neighbor::Neighbor(sdbusplus::bus_t& bus, std::string_view objRoot,
+ EthernetInterface& parent, InAddrAny addr, ether_addr lladdr,
+ State state) :
+ Neighbor(bus, makeObjPath(objRoot, addr), parent, addr, lladdr, state)
+{
+}
+
+Neighbor::Neighbor(sdbusplus::bus_t& bus,
+ sdbusplus::message::object_path objPath,
+ EthernetInterface& parent, InAddrAny addr, ether_addr lladdr,
+ State state) :
+ NeighborObj(bus, objPath.str.c_str(), NeighborObj::action::defer_emit),
+ parent(parent), objPath(std::move(objPath))
+{
+ NeighborObj::ipAddress(std::to_string(addr));
+ NeighborObj::macAddress(std::to_string(lladdr));
NeighborObj::state(state);
// Emit deferred signal.
@@ -103,7 +119,20 @@
void Neighbor::delete_()
{
- parent.deleteStaticNeighborObject(ipAddress());
+ auto& neighbors = parent.staticNeighbors;
+ std::unique_ptr<Neighbor> ptr;
+ for (auto it = neighbors.begin(); it != neighbors.end(); ++it)
+ {
+ if (it->second.get() == this)
+ {
+ ptr = std::move(it->second);
+ neighbors.erase(it);
+ break;
+ }
+ }
+
+ parent.writeConfigurationFile();
+ parent.manager.reloadConfigs();
}
using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;