blob: afbc06207417fd831e4b62b5d9229f5842298d95 [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 III434a9432022-11-04 18:38:46 -070017static auto makeObjPath(std::string_view root, InAddrAny 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));
20 ret /= std::to_string(addr);
21 return ret;
22}
23
24Neighbor::Neighbor(sdbusplus::bus_t& bus, std::string_view objRoot,
William A. Kennington III9ede1b72022-11-21 01:59:28 -080025 stdplus::PinnedRef<EthernetInterface> parent, InAddrAny addr,
William A. Kennington IIIb7d6a1a2023-06-17 02:00:53 -070026 stdplus::EtherAddr lladdr, State state) :
William A. Kennington III434a9432022-11-04 18:38:46 -070027 Neighbor(bus, makeObjPath(objRoot, addr), parent, addr, lladdr, state)
Patrick Williams89d734b2023-05-10 07:50:25 -050028{}
William A. Kennington III434a9432022-11-04 18:38:46 -070029
30Neighbor::Neighbor(sdbusplus::bus_t& bus,
31 sdbusplus::message::object_path objPath,
William A. Kennington III9ede1b72022-11-21 01:59:28 -080032 stdplus::PinnedRef<EthernetInterface> parent, InAddrAny addr,
William A. Kennington IIIb7d6a1a2023-06-17 02:00:53 -070033 stdplus::EtherAddr lladdr, State state) :
William A. Kennington III434a9432022-11-04 18:38:46 -070034 NeighborObj(bus, objPath.str.c_str(), NeighborObj::action::defer_emit),
35 parent(parent), objPath(std::move(objPath))
36{
William A. Kennington IIId99e6db2022-11-15 20:39:45 -080037 NeighborObj::ipAddress(std::to_string(addr), true);
William A. Kennington IIIb7d6a1a2023-06-17 02:00:53 -070038 NeighborObj::macAddress(stdplus::toStr(lladdr), true);
William A. Kennington IIId99e6db2022-11-15 20:39:45 -080039 NeighborObj::state(state, true);
William A. Kennington III08505792019-01-30 16:00:04 -080040 emit_object_added();
41}
42
43void Neighbor::delete_()
44{
William A. Kennington III9ede1b72022-11-21 01:59:28 -080045 auto& neighbors = parent.get().staticNeighbors;
William A. Kennington III434a9432022-11-04 18:38:46 -070046 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
William A. Kennington III9ede1b72022-11-21 01:59:28 -080057 parent.get().writeConfigurationFile();
58 parent.get().manager.get().reloadConfigs();
William A. Kennington III08505792019-01-30 16:00:04 -080059}
60
William A. Kennington III8e61ca92022-09-01 13:28:33 -070061using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
62using REASON =
63 phosphor::logging::xyz::openbmc_project::Common::NotAllowed::REASON;
64using phosphor::logging::elog;
65
66std::string Neighbor::ipAddress(std::string /*ipAddress*/)
67{
68 elog<NotAllowed>(REASON("Property update is not allowed"));
69}
70
71std::string Neighbor::macAddress(std::string /*macAddress*/)
72{
73 elog<NotAllowed>(REASON("Property update is not allowed"));
74}
75
76Neighbor::State Neighbor::state(State /*state*/)
77{
78 elog<NotAllowed>(REASON("Property update is not allowed"));
79}
80
William A. Kennington III08505792019-01-30 16:00:04 -080081} // namespace network
82} // namespace phosphor