blob: 4d899c4fe079fd9c0e7209f79313fd7e2308f152 [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 III8e61ca92022-09-01 13:28:33 -07008#include <xyz/openbmc_project/Common/error.hpp>
William A. Kennington III08505792019-01-30 16:00:04 -08009
Patrick Williams89d734b2023-05-10 07:50:25 -050010#include <string>
11
William A. Kennington III08505792019-01-30 16:00:04 -080012namespace phosphor
13{
14namespace network
15{
William A. Kennington III08505792019-01-30 16:00:04 -080016
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070017static auto makeObjPath(std::string_view root, stdplus::InAnyAddr addr)
William A. Kennington III08505792019-01-30 16:00:04 -080018{
William A. Kennington III434a9432022-11-04 18:38:46 -070019 auto ret = sdbusplus::message::object_path(std::string(root));
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070020 stdplus::ToStrHandle<stdplus::ToStr<stdplus::InAnyAddr>> tsh;
21 ret /= tsh(addr);
William A. Kennington III434a9432022-11-04 18:38:46 -070022 return ret;
23}
24
25Neighbor::Neighbor(sdbusplus::bus_t& bus, std::string_view objRoot,
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070026 stdplus::PinnedRef<EthernetInterface> parent,
27 stdplus::InAnyAddr addr, stdplus::EtherAddr lladdr,
28 State state) :
William A. Kennington III434a9432022-11-04 18:38:46 -070029 Neighbor(bus, makeObjPath(objRoot, addr), parent, addr, lladdr, state)
Patrick Williams89d734b2023-05-10 07:50:25 -050030{}
William A. Kennington III434a9432022-11-04 18:38:46 -070031
32Neighbor::Neighbor(sdbusplus::bus_t& bus,
33 sdbusplus::message::object_path objPath,
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070034 stdplus::PinnedRef<EthernetInterface> parent,
35 stdplus::InAnyAddr addr, stdplus::EtherAddr lladdr,
36 State state) :
William A. Kennington III434a9432022-11-04 18:38:46 -070037 NeighborObj(bus, objPath.str.c_str(), NeighborObj::action::defer_emit),
38 parent(parent), objPath(std::move(objPath))
39{
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070040 NeighborObj::ipAddress(stdplus::toStr(addr), true);
William A. Kennington IIIb7d6a1a2023-06-17 02:00:53 -070041 NeighborObj::macAddress(stdplus::toStr(lladdr), true);
William A. Kennington IIId99e6db2022-11-15 20:39:45 -080042 NeighborObj::state(state, true);
William A. Kennington III08505792019-01-30 16:00:04 -080043 emit_object_added();
44}
45
46void Neighbor::delete_()
47{
William A. Kennington III9ede1b72022-11-21 01:59:28 -080048 auto& neighbors = parent.get().staticNeighbors;
William A. Kennington III434a9432022-11-04 18:38:46 -070049 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
William A. Kennington III9ede1b72022-11-21 01:59:28 -080060 parent.get().writeConfigurationFile();
61 parent.get().manager.get().reloadConfigs();
William A. Kennington III08505792019-01-30 16:00:04 -080062}
63
William A. Kennington III8e61ca92022-09-01 13:28:33 -070064using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
65using REASON =
66 phosphor::logging::xyz::openbmc_project::Common::NotAllowed::REASON;
67using phosphor::logging::elog;
68
69std::string Neighbor::ipAddress(std::string /*ipAddress*/)
70{
71 elog<NotAllowed>(REASON("Property update is not allowed"));
72}
73
74std::string Neighbor::macAddress(std::string /*macAddress*/)
75{
76 elog<NotAllowed>(REASON("Property update is not allowed"));
77}
78
79Neighbor::State Neighbor::state(State /*state*/)
80{
81 elog<NotAllowed>(REASON("Property update is not allowed"));
82}
83
William A. Kennington III08505792019-01-30 16:00:04 -080084} // namespace network
85} // namespace phosphor