1 #include "neighbor.hpp" 2 3 #include "ethernet_interface.hpp" 4 #include "network_manager.hpp" 5 6 #include <phosphor-logging/elog-errors.hpp> 7 #include <phosphor-logging/elog.hpp> 8 #include <string> 9 #include <xyz/openbmc_project/Common/error.hpp> 10 11 namespace phosphor 12 { 13 namespace network 14 { 15 16 static auto makeObjPath(std::string_view root, InAddrAny addr) 17 { 18 auto ret = sdbusplus::message::object_path(std::string(root)); 19 ret /= std::to_string(addr); 20 return ret; 21 } 22 23 Neighbor::Neighbor(sdbusplus::bus_t& bus, std::string_view objRoot, 24 EthernetInterface& parent, InAddrAny addr, ether_addr lladdr, 25 State state) : 26 Neighbor(bus, makeObjPath(objRoot, addr), parent, addr, lladdr, state) 27 { 28 } 29 30 Neighbor::Neighbor(sdbusplus::bus_t& bus, 31 sdbusplus::message::object_path objPath, 32 EthernetInterface& parent, InAddrAny addr, ether_addr lladdr, 33 State state) : 34 NeighborObj(bus, objPath.str.c_str(), NeighborObj::action::defer_emit), 35 parent(parent), objPath(std::move(objPath)) 36 { 37 NeighborObj::ipAddress(std::to_string(addr)); 38 NeighborObj::macAddress(std::to_string(lladdr)); 39 NeighborObj::state(state); 40 41 // Emit deferred signal. 42 emit_object_added(); 43 } 44 45 void Neighbor::delete_() 46 { 47 auto& neighbors = parent.staticNeighbors; 48 std::unique_ptr<Neighbor> ptr; 49 for (auto it = neighbors.begin(); it != neighbors.end(); ++it) 50 { 51 if (it->second.get() == this) 52 { 53 ptr = std::move(it->second); 54 neighbors.erase(it); 55 break; 56 } 57 } 58 59 parent.writeConfigurationFile(); 60 parent.manager.reloadConfigsNoRefresh(); 61 } 62 63 using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; 64 using REASON = 65 phosphor::logging::xyz::openbmc_project::Common::NotAllowed::REASON; 66 using phosphor::logging::elog; 67 68 std::string Neighbor::ipAddress(std::string /*ipAddress*/) 69 { 70 elog<NotAllowed>(REASON("Property update is not allowed")); 71 } 72 73 std::string Neighbor::macAddress(std::string /*macAddress*/) 74 { 75 elog<NotAllowed>(REASON("Property update is not allowed")); 76 } 77 78 Neighbor::State Neighbor::state(State /*state*/) 79 { 80 elog<NotAllowed>(REASON("Property update is not allowed")); 81 } 82 83 } // namespace network 84 } // namespace phosphor 85