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