William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 1 | #include "neighbor.hpp" |
| 2 | |
| 3 | #include "ethernet_interface.hpp" |
William A. Kennington III | 434a943 | 2022-11-04 18:38:46 -0700 | [diff] [blame] | 4 | #include "network_manager.hpp" |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 5 | |
William A. Kennington III | 8e61ca9 | 2022-09-01 13:28:33 -0700 | [diff] [blame] | 6 | #include <phosphor-logging/elog-errors.hpp> |
| 7 | #include <phosphor-logging/elog.hpp> |
William A. Kennington III | 8e61ca9 | 2022-09-01 13:28:33 -0700 | [diff] [blame] | 8 | #include <xyz/openbmc_project/Common/error.hpp> |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 9 | |
Patrick Williams | 89d734b | 2023-05-10 07:50:25 -0500 | [diff] [blame] | 10 | #include <string> |
| 11 | |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 12 | namespace phosphor |
| 13 | { |
| 14 | namespace network |
| 15 | { |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 16 | |
William A. Kennington III | 9b2a20d | 2023-06-17 14:05:48 -0700 | [diff] [blame] | 17 | static auto makeObjPath(std::string_view root, stdplus::InAnyAddr addr) |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 18 | { |
William A. Kennington III | 434a943 | 2022-11-04 18:38:46 -0700 | [diff] [blame] | 19 | auto ret = sdbusplus::message::object_path(std::string(root)); |
William A. Kennington III | 9b2a20d | 2023-06-17 14:05:48 -0700 | [diff] [blame] | 20 | stdplus::ToStrHandle<stdplus::ToStr<stdplus::InAnyAddr>> tsh; |
| 21 | ret /= tsh(addr); |
William A. Kennington III | 434a943 | 2022-11-04 18:38:46 -0700 | [diff] [blame] | 22 | return ret; |
| 23 | } |
| 24 | |
| 25 | Neighbor::Neighbor(sdbusplus::bus_t& bus, std::string_view objRoot, |
William A. Kennington III | 9b2a20d | 2023-06-17 14:05:48 -0700 | [diff] [blame] | 26 | stdplus::PinnedRef<EthernetInterface> parent, |
| 27 | stdplus::InAnyAddr addr, stdplus::EtherAddr lladdr, |
| 28 | State state) : |
William A. Kennington III | 434a943 | 2022-11-04 18:38:46 -0700 | [diff] [blame] | 29 | Neighbor(bus, makeObjPath(objRoot, addr), parent, addr, lladdr, state) |
Patrick Williams | 89d734b | 2023-05-10 07:50:25 -0500 | [diff] [blame] | 30 | {} |
William A. Kennington III | 434a943 | 2022-11-04 18:38:46 -0700 | [diff] [blame] | 31 | |
| 32 | Neighbor::Neighbor(sdbusplus::bus_t& bus, |
| 33 | sdbusplus::message::object_path objPath, |
William A. Kennington III | 9b2a20d | 2023-06-17 14:05:48 -0700 | [diff] [blame] | 34 | stdplus::PinnedRef<EthernetInterface> parent, |
| 35 | stdplus::InAnyAddr addr, stdplus::EtherAddr lladdr, |
| 36 | State state) : |
William A. Kennington III | 434a943 | 2022-11-04 18:38:46 -0700 | [diff] [blame] | 37 | NeighborObj(bus, objPath.str.c_str(), NeighborObj::action::defer_emit), |
| 38 | parent(parent), objPath(std::move(objPath)) |
| 39 | { |
William A. Kennington III | 9b2a20d | 2023-06-17 14:05:48 -0700 | [diff] [blame] | 40 | NeighborObj::ipAddress(stdplus::toStr(addr), true); |
William A. Kennington III | b7d6a1a | 2023-06-17 02:00:53 -0700 | [diff] [blame] | 41 | NeighborObj::macAddress(stdplus::toStr(lladdr), true); |
William A. Kennington III | d99e6db | 2022-11-15 20:39:45 -0800 | [diff] [blame] | 42 | NeighborObj::state(state, true); |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 43 | emit_object_added(); |
| 44 | } |
| 45 | |
| 46 | void Neighbor::delete_() |
| 47 | { |
William A. Kennington III | 9ede1b7 | 2022-11-21 01:59:28 -0800 | [diff] [blame] | 48 | auto& neighbors = parent.get().staticNeighbors; |
William A. Kennington III | 434a943 | 2022-11-04 18:38:46 -0700 | [diff] [blame] | 49 | 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 III | 9ede1b7 | 2022-11-21 01:59:28 -0800 | [diff] [blame] | 60 | parent.get().writeConfigurationFile(); |
| 61 | parent.get().manager.get().reloadConfigs(); |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 62 | } |
| 63 | |
William A. Kennington III | 8e61ca9 | 2022-09-01 13:28:33 -0700 | [diff] [blame] | 64 | using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; |
| 65 | using REASON = |
| 66 | phosphor::logging::xyz::openbmc_project::Common::NotAllowed::REASON; |
| 67 | using phosphor::logging::elog; |
| 68 | |
| 69 | std::string Neighbor::ipAddress(std::string /*ipAddress*/) |
| 70 | { |
| 71 | elog<NotAllowed>(REASON("Property update is not allowed")); |
| 72 | } |
| 73 | |
| 74 | std::string Neighbor::macAddress(std::string /*macAddress*/) |
| 75 | { |
| 76 | elog<NotAllowed>(REASON("Property update is not allowed")); |
| 77 | } |
| 78 | |
| 79 | Neighbor::State Neighbor::state(State /*state*/) |
| 80 | { |
| 81 | elog<NotAllowed>(REASON("Property update is not allowed")); |
| 82 | } |
| 83 | |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 84 | } // namespace network |
| 85 | } // namespace phosphor |