blob: a29218d1655df7be145215e0215350129b84833a [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>
10#include <sdbusplus/server/object.hpp>
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -070011#include <stdplus/zstring.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.
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 IIIbe3bd2f2022-10-11 14:11:27 -070082 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 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 III08505792019-01-30 16:00:04 -080097 private:
98 /** @brief Parent Object. */
99 EthernetInterface& parent;
100};
101
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -0700102namespace detail
103{
104
William A. Kennington IIId7946a72019-04-19 14:24:09 -0700105void parseNeighbor(const NeighborFilter& filter, const nlmsghdr& hdr,
106 std::string_view msg, std::vector<NeighborInfo>& neighbors);
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -0700107
108} // namespace detail
109
William A. Kennington III08505792019-01-30 16:00:04 -0800110} // namespace network
111} // namespace phosphor