blob: 6b8d8536192aefade7c6954b530d348fd7fd46a0 [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{
William A. Kennington IIId99e6db2022-11-15 20:39:45 -080037 NeighborObj::ipAddress(std::to_string(addr), true);
38 NeighborObj::macAddress(std::to_string(lladdr), true);
39 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 III434a9432022-11-04 18:38:46 -070045 auto& neighbors = parent.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.writeConfigurationFile();
William A. Kennington III5b179382022-11-15 15:23:26 -080058 parent.manager.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