| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 1 | #pragma once | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 2 | #include "types.hpp" | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 3 |  | 
| William A. Kennington III | c920bdb | 2019-04-19 14:23:06 -0700 | [diff] [blame] | 4 | #include <linux/netlink.h> | 
| William A. Kennington III | 6ca08d8 | 2019-04-20 16:04:18 -0700 | [diff] [blame] | 5 | #include <net/ethernet.h> | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 6 |  | 
| William A. Kennington III | d7946a7 | 2019-04-19 14:24:09 -0700 | [diff] [blame] | 7 | #include <cstdint> | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 8 | #include <optional> | 
|  | 9 | #include <sdbusplus/bus.hpp> | 
|  | 10 | #include <sdbusplus/server/object.hpp> | 
| William A. Kennington III | be3bd2f | 2022-10-11 14:11:27 -0700 | [diff] [blame] | 11 | #include <stdplus/zstring.hpp> | 
| William A. Kennington III | c920bdb | 2019-04-19 14:23:06 -0700 | [diff] [blame] | 12 | #include <string_view> | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 13 | #include <vector> | 
|  | 14 | #include <xyz/openbmc_project/Network/Neighbor/server.hpp> | 
|  | 15 | #include <xyz/openbmc_project/Object/Delete/server.hpp> | 
|  | 16 |  | 
|  | 17 | namespace phosphor | 
|  | 18 | { | 
|  | 19 | namespace network | 
|  | 20 | { | 
|  | 21 |  | 
|  | 22 | using NeighborIntf = sdbusplus::xyz::openbmc_project::Network::server::Neighbor; | 
|  | 23 |  | 
| Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 24 | using NeighborObj = sdbusplus::server::object_t< | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 25 | NeighborIntf, sdbusplus::xyz::openbmc_project::Object::server::Delete>; | 
|  | 26 |  | 
|  | 27 | class EthernetInterface; | 
|  | 28 |  | 
| William A. Kennington III | d7946a7 | 2019-04-19 14:24:09 -0700 | [diff] [blame] | 29 | /* @class NeighborFilter | 
|  | 30 | */ | 
|  | 31 | struct NeighborFilter | 
|  | 32 | { | 
|  | 33 | unsigned interface; | 
|  | 34 | uint16_t state; | 
|  | 35 |  | 
|  | 36 | /* @brief Creates an empty filter */ | 
|  | 37 | NeighborFilter() : interface(0), state(~UINT16_C(0)) | 
|  | 38 | { | 
|  | 39 | } | 
|  | 40 | }; | 
|  | 41 |  | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 42 | /** @class NeighborInfo | 
|  | 43 | *  @brief Information about a neighbor from the kernel | 
|  | 44 | */ | 
|  | 45 | struct NeighborInfo | 
|  | 46 | { | 
| William A. Kennington III | d7946a7 | 2019-04-19 14:24:09 -0700 | [diff] [blame] | 47 | unsigned interface; | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 48 | InAddrAny address; | 
| William A. Kennington III | 6ca08d8 | 2019-04-20 16:04:18 -0700 | [diff] [blame] | 49 | std::optional<ether_addr> mac; | 
| William A. Kennington III | d7946a7 | 2019-04-19 14:24:09 -0700 | [diff] [blame] | 50 | uint16_t state; | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 51 | }; | 
|  | 52 |  | 
|  | 53 | /** @brief Returns a list of the current system neighbor table | 
|  | 54 | */ | 
| William A. Kennington III | d7946a7 | 2019-04-19 14:24:09 -0700 | [diff] [blame] | 55 | std::vector<NeighborInfo> getCurrentNeighbors(const NeighborFilter& filter); | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 56 |  | 
|  | 57 | /** @class Neighbor | 
|  | 58 | *  @brief OpenBMC network neighbor implementation. | 
|  | 59 | *  @details A concrete implementation for the | 
|  | 60 | *  xyz.openbmc_project.Network.Neighbor dbus interface. | 
|  | 61 | */ | 
|  | 62 | class Neighbor : public NeighborObj | 
|  | 63 | { | 
|  | 64 | public: | 
|  | 65 | using State = NeighborIntf::State; | 
|  | 66 |  | 
|  | 67 | Neighbor() = delete; | 
|  | 68 | Neighbor(const Neighbor&) = delete; | 
|  | 69 | Neighbor& operator=(const Neighbor&) = delete; | 
|  | 70 | Neighbor(Neighbor&&) = delete; | 
|  | 71 | Neighbor& operator=(Neighbor&&) = delete; | 
|  | 72 | virtual ~Neighbor() = default; | 
|  | 73 |  | 
|  | 74 | /** @brief Constructor to put object onto bus at a dbus path. | 
|  | 75 | *  @param[in] bus - Bus to attach to. | 
|  | 76 | *  @param[in] objPath - Path to attach at. | 
|  | 77 | *  @param[in] parent - Parent object. | 
|  | 78 | *  @param[in] ipAddress - IP address. | 
|  | 79 | *  @param[in] macAddress - Low level MAC address. | 
|  | 80 | *  @param[in] state - The state of the neighbor entry. | 
|  | 81 | */ | 
| William A. Kennington III | be3bd2f | 2022-10-11 14:11:27 -0700 | [diff] [blame] | 82 | Neighbor(sdbusplus::bus_t& bus, stdplus::const_zstring objPath, | 
|  | 83 | EthernetInterface& parent, std::string_view ipAddress, | 
|  | 84 | std::string_view macAddress, State state); | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 85 |  | 
|  | 86 | /** @brief Delete this d-bus object. | 
|  | 87 | */ | 
|  | 88 | void delete_() override; | 
|  | 89 |  | 
| William A. Kennington III | 8e61ca9 | 2022-09-01 13:28:33 -0700 | [diff] [blame] | 90 | using NeighborObj::ipAddress; | 
|  | 91 | std::string ipAddress(std::string) override; | 
|  | 92 | using NeighborObj::macAddress; | 
|  | 93 | std::string macAddress(std::string) override; | 
|  | 94 | using NeighborObj::state; | 
|  | 95 | State state(State) override; | 
|  | 96 |  | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 97 | private: | 
|  | 98 | /** @brief Parent Object. */ | 
|  | 99 | EthernetInterface& parent; | 
|  | 100 | }; | 
|  | 101 |  | 
| William A. Kennington III | c920bdb | 2019-04-19 14:23:06 -0700 | [diff] [blame] | 102 | namespace detail | 
|  | 103 | { | 
|  | 104 |  | 
| William A. Kennington III | d7946a7 | 2019-04-19 14:24:09 -0700 | [diff] [blame] | 105 | void parseNeighbor(const NeighborFilter& filter, const nlmsghdr& hdr, | 
|  | 106 | std::string_view msg, std::vector<NeighborInfo>& neighbors); | 
| William A. Kennington III | c920bdb | 2019-04-19 14:23:06 -0700 | [diff] [blame] | 107 |  | 
|  | 108 | } // namespace detail | 
|  | 109 |  | 
| William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 110 | } // namespace network | 
|  | 111 | } // namespace phosphor |