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                    stdplus::PinnedRef<EthernetInterface> parent, InAddrAny addr,
25                    ether_addr lladdr, 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                    stdplus::PinnedRef<EthernetInterface> parent, InAddrAny addr,
33                    ether_addr lladdr, 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), true);
38     NeighborObj::macAddress(std::to_string(lladdr), true);
39     NeighborObj::state(state, true);
40     emit_object_added();
41 }
42 
43 void Neighbor::delete_()
44 {
45     auto& neighbors = parent.get().staticNeighbors;
46     std::unique_ptr<Neighbor> ptr;
47     for (auto it = neighbors.begin(); it != neighbors.end(); ++it)
48     {
49         if (it->second.get() == this)
50         {
51             ptr = std::move(it->second);
52             neighbors.erase(it);
53             break;
54         }
55     }
56 
57     parent.get().writeConfigurationFile();
58     parent.get().manager.get().reloadConfigs();
59 }
60 
61 using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
62 using REASON =
63     phosphor::logging::xyz::openbmc_project::Common::NotAllowed::REASON;
64 using phosphor::logging::elog;
65 
66 std::string Neighbor::ipAddress(std::string /*ipAddress*/)
67 {
68     elog<NotAllowed>(REASON("Property update is not allowed"));
69 }
70 
71 std::string Neighbor::macAddress(std::string /*macAddress*/)
72 {
73     elog<NotAllowed>(REASON("Property update is not allowed"));
74 }
75 
76 Neighbor::State Neighbor::state(State /*state*/)
77 {
78     elog<NotAllowed>(REASON("Property update is not allowed"));
79 }
80 
81 } // namespace network
82 } // namespace phosphor
83