blob: 58334b22f0012985aeb407fe38297241cea62923 [file] [log] [blame]
William A. Kennington III08505792019-01-30 16:00:04 -08001#include "neighbor.hpp"
2
3#include "ethernet_interface.hpp"
William A. Kennington III434a9432022-11-04 18:38:46 -07004#include "network_manager.hpp"
William A. Kennington III08505792019-01-30 16:00:04 -08005
William A. Kennington III8e61ca92022-09-01 13:28:33 -07006#include <phosphor-logging/elog-errors.hpp>
7#include <phosphor-logging/elog.hpp>
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -07008#include <string>
William A. Kennington III8e61ca92022-09-01 13:28:33 -07009#include <xyz/openbmc_project/Common/error.hpp>
William A. Kennington III08505792019-01-30 16:00:04 -080010
11namespace phosphor
12{
13namespace network
14{
William A. Kennington III08505792019-01-30 16:00:04 -080015
William A. Kennington III434a9432022-11-04 18:38:46 -070016static auto makeObjPath(std::string_view root, InAddrAny addr)
William A. Kennington III08505792019-01-30 16:00:04 -080017{
William A. Kennington III434a9432022-11-04 18:38:46 -070018 auto ret = sdbusplus::message::object_path(std::string(root));
19 ret /= std::to_string(addr);
20 return ret;
21}
22
23Neighbor::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
30Neighbor::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));
William A. Kennington III19194622022-09-06 02:13:34 -070039 NeighborObj::state(state);
William A. Kennington III08505792019-01-30 16:00:04 -080040
41 // Emit deferred signal.
42 emit_object_added();
43}
44
45void Neighbor::delete_()
46{
William A. Kennington III434a9432022-11-04 18:38:46 -070047 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();
William A. Kennington IIIbc2502c2022-11-07 16:31:54 -080060 parent.manager.reloadConfigsNoRefresh();
William A. Kennington III08505792019-01-30 16:00:04 -080061}
62
William A. Kennington III8e61ca92022-09-01 13:28:33 -070063using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
64using REASON =
65 phosphor::logging::xyz::openbmc_project::Common::NotAllowed::REASON;
66using phosphor::logging::elog;
67
68std::string Neighbor::ipAddress(std::string /*ipAddress*/)
69{
70 elog<NotAllowed>(REASON("Property update is not allowed"));
71}
72
73std::string Neighbor::macAddress(std::string /*macAddress*/)
74{
75 elog<NotAllowed>(REASON("Property update is not allowed"));
76}
77
78Neighbor::State Neighbor::state(State /*state*/)
79{
80 elog<NotAllowed>(REASON("Property update is not allowed"));
81}
82
William A. Kennington III08505792019-01-30 16:00:04 -080083} // namespace network
84} // namespace phosphor