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