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