1 #pragma once 2 #include "types.hpp" 3 4 #include <linux/netlink.h> 5 #include <net/ethernet.h> 6 7 #include <cstdint> 8 #include <optional> 9 #include <sdbusplus/bus.hpp> 10 #include <sdbusplus/message/native_types.hpp> 11 #include <sdbusplus/server/object.hpp> 12 #include <string_view> 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 24 using NeighborObj = sdbusplus::server::object_t< 25 NeighborIntf, sdbusplus::xyz::openbmc_project::Object::server::Delete>; 26 27 class EthernetInterface; 28 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 42 /** @class NeighborInfo 43 * @brief Information about a neighbor from the kernel 44 */ 45 struct NeighborInfo 46 { 47 unsigned interface; 48 InAddrAny address; 49 std::optional<ether_addr> mac; 50 uint16_t state; 51 }; 52 53 /** @brief Returns a list of the current system neighbor table 54 */ 55 std::vector<NeighborInfo> getCurrentNeighbors(const NeighborFilter& filter); 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] objRoot - Path to attach at. 77 * @param[in] parent - Parent object. 78 * @param[in] addr - IP address. 79 * @param[in] lladdr - Low level MAC address. 80 * @param[in] state - The state of the neighbor entry. 81 */ 82 Neighbor(sdbusplus::bus_t& bus, std::string_view objRoot, 83 EthernetInterface& parent, InAddrAny addr, ether_addr lladdr, 84 State state); 85 86 /** @brief Delete this d-bus object. 87 */ 88 void delete_() override; 89 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 97 inline const auto& getObjPath() const 98 { 99 return objPath; 100 } 101 102 private: 103 /** @brief Parent Object. */ 104 EthernetInterface& parent; 105 106 /** @brief Dbus object path */ 107 sdbusplus::message::object_path objPath; 108 109 Neighbor(sdbusplus::bus_t& bus, sdbusplus::message::object_path objPath, 110 EthernetInterface& parent, InAddrAny addr, ether_addr lladdr, 111 State state); 112 }; 113 114 namespace detail 115 { 116 117 void parseNeighbor(const NeighborFilter& filter, const nlmsghdr& hdr, 118 std::string_view msg, std::vector<NeighborInfo>& neighbors); 119 120 } // namespace detail 121 122 } // namespace network 123 } // namespace phosphor 124