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 | be3bd2f | 2022-10-11 14:11:27 -0700 | [diff] [blame] | 8 | #include <string> |
William A. Kennington III | 8e61ca9 | 2022-09-01 13:28:33 -0700 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Common/error.hpp> |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace network |
| 14 | { |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 15 | |
William A. Kennington III | 434a943 | 2022-11-04 18:38:46 -0700 | [diff] [blame] | 16 | static auto makeObjPath(std::string_view root, InAddrAny addr) |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 17 | { |
William A. Kennington III | 434a943 | 2022-11-04 18:38:46 -0700 | [diff] [blame] | 18 | auto ret = sdbusplus::message::object_path(std::string(root)); |
| 19 | ret /= std::to_string(addr); |
| 20 | return ret; |
| 21 | } |
| 22 | |
| 23 | Neighbor::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 | |
| 30 | Neighbor::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 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 | 434a943 | 2022-11-04 18:38:46 -0700 | [diff] [blame] | 45 | 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 III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 58 | parent.manager.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 |