blob: 4cd368261c0ef5c37eab453e6eab2318f4e73f6a [file] [log] [blame]
William A. Kennington III08505792019-01-30 16:00:04 -08001#pragma once
William A. Kennington III08505792019-01-30 16:00:04 -08002#include "types.hpp"
William A. Kennington III08505792019-01-30 16:00:04 -08003
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -07004#include <linux/netlink.h>
William A. Kennington III6ca08d82019-04-20 16:04:18 -07005#include <net/ethernet.h>
William A. Kennington III08505792019-01-30 16:00:04 -08006
William A. Kennington IIId7946a72019-04-19 14:24:09 -07007#include <cstdint>
William A. Kennington III08505792019-01-30 16:00:04 -08008#include <optional>
9#include <sdbusplus/bus.hpp>
William A. Kennington III434a9432022-11-04 18:38:46 -070010#include <sdbusplus/message/native_types.hpp>
William A. Kennington III08505792019-01-30 16:00:04 -080011#include <sdbusplus/server/object.hpp>
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -070012#include <string_view>
William A. Kennington III08505792019-01-30 16:00:04 -080013#include <vector>
14#include <xyz/openbmc_project/Network/Neighbor/server.hpp>
15#include <xyz/openbmc_project/Object/Delete/server.hpp>
16
17namespace phosphor
18{
19namespace network
20{
21
22using NeighborIntf = sdbusplus::xyz::openbmc_project::Network::server::Neighbor;
23
Patrick Williamsc38b0712022-07-22 19:26:54 -050024using NeighborObj = sdbusplus::server::object_t<
William A. Kennington III08505792019-01-30 16:00:04 -080025 NeighborIntf, sdbusplus::xyz::openbmc_project::Object::server::Delete>;
26
27class EthernetInterface;
28
William A. Kennington IIId7946a72019-04-19 14:24:09 -070029/* @class NeighborFilter
30 */
31struct 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 III08505792019-01-30 16:00:04 -080042/** @class NeighborInfo
43 * @brief Information about a neighbor from the kernel
44 */
45struct NeighborInfo
46{
William A. Kennington IIId7946a72019-04-19 14:24:09 -070047 unsigned interface;
William A. Kennington III08505792019-01-30 16:00:04 -080048 InAddrAny address;
William A. Kennington III6ca08d82019-04-20 16:04:18 -070049 std::optional<ether_addr> mac;
William A. Kennington IIId7946a72019-04-19 14:24:09 -070050 uint16_t state;
William A. Kennington III08505792019-01-30 16:00:04 -080051};
52
53/** @brief Returns a list of the current system neighbor table
54 */
William A. Kennington IIId7946a72019-04-19 14:24:09 -070055std::vector<NeighborInfo> getCurrentNeighbors(const NeighborFilter& filter);
William A. Kennington III08505792019-01-30 16:00:04 -080056
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 */
62class 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.
William A. Kennington III434a9432022-11-04 18:38:46 -070076 * @param[in] objRoot - Path to attach at.
William A. Kennington III08505792019-01-30 16:00:04 -080077 * @param[in] parent - Parent object.
William A. Kennington III434a9432022-11-04 18:38:46 -070078 * @param[in] addr - IP address.
79 * @param[in] lladdr - Low level MAC address.
William A. Kennington III08505792019-01-30 16:00:04 -080080 * @param[in] state - The state of the neighbor entry.
81 */
William A. Kennington III434a9432022-11-04 18:38:46 -070082 Neighbor(sdbusplus::bus_t& bus, std::string_view objRoot,
83 EthernetInterface& parent, InAddrAny addr, ether_addr lladdr,
84 State state);
William A. Kennington III08505792019-01-30 16:00:04 -080085
86 /** @brief Delete this d-bus object.
87 */
88 void delete_() override;
89
William A. Kennington III8e61ca92022-09-01 13:28:33 -070090 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 III434a9432022-11-04 18:38:46 -070097 inline const auto& getObjPath() const
98 {
99 return objPath;
100 }
101
William A. Kennington III08505792019-01-30 16:00:04 -0800102 private:
103 /** @brief Parent Object. */
104 EthernetInterface& parent;
William A. Kennington III434a9432022-11-04 18:38:46 -0700105
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);
William A. Kennington III08505792019-01-30 16:00:04 -0800112};
113
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -0700114namespace detail
115{
116
William A. Kennington IIId7946a72019-04-19 14:24:09 -0700117void parseNeighbor(const NeighborFilter& filter, const nlmsghdr& hdr,
118 std::string_view msg, std::vector<NeighborInfo>& neighbors);
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -0700119
120} // namespace detail
121
William A. Kennington III08505792019-01-30 16:00:04 -0800122} // namespace network
123} // namespace phosphor