blob: ce1d34bff3f740e9cfe4f8dedaae926dc6ad8a95 [file] [log] [blame]
William A. Kennington III08505792019-01-30 16:00:04 -08001#pragma once
2
3#include "types.hpp"
4#include "util.hpp"
5
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -07006#include <linux/netlink.h>
William A. Kennington III6ca08d82019-04-20 16:04:18 -07007#include <net/ethernet.h>
William A. Kennington III08505792019-01-30 16:00:04 -08008
9#include <optional>
10#include <sdbusplus/bus.hpp>
11#include <sdbusplus/server/object.hpp>
12#include <string>
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -070013#include <string_view>
William A. Kennington III08505792019-01-30 16:00:04 -080014#include <vector>
15#include <xyz/openbmc_project/Network/Neighbor/server.hpp>
16#include <xyz/openbmc_project/Object/Delete/server.hpp>
17
18namespace phosphor
19{
20namespace network
21{
22
23using NeighborIntf = sdbusplus::xyz::openbmc_project::Network::server::Neighbor;
24
25using NeighborObj = sdbusplus::server::object::object<
26 NeighborIntf, sdbusplus::xyz::openbmc_project::Object::server::Delete>;
27
28class EthernetInterface;
29
30/** @class NeighborInfo
31 * @brief Information about a neighbor from the kernel
32 */
33struct NeighborInfo
34{
35 std::string interface;
36 InAddrAny address;
William A. Kennington III6ca08d82019-04-20 16:04:18 -070037 std::optional<ether_addr> mac;
William A. Kennington III08505792019-01-30 16:00:04 -080038 bool permanent;
39};
40
41/** @brief Returns a list of the current system neighbor table
42 */
43std::vector<NeighborInfo> getCurrentNeighbors();
44
45/** @class Neighbor
46 * @brief OpenBMC network neighbor implementation.
47 * @details A concrete implementation for the
48 * xyz.openbmc_project.Network.Neighbor dbus interface.
49 */
50class Neighbor : public NeighborObj
51{
52 public:
53 using State = NeighborIntf::State;
54
55 Neighbor() = delete;
56 Neighbor(const Neighbor&) = delete;
57 Neighbor& operator=(const Neighbor&) = delete;
58 Neighbor(Neighbor&&) = delete;
59 Neighbor& operator=(Neighbor&&) = delete;
60 virtual ~Neighbor() = default;
61
62 /** @brief Constructor to put object onto bus at a dbus path.
63 * @param[in] bus - Bus to attach to.
64 * @param[in] objPath - Path to attach at.
65 * @param[in] parent - Parent object.
66 * @param[in] ipAddress - IP address.
67 * @param[in] macAddress - Low level MAC address.
68 * @param[in] state - The state of the neighbor entry.
69 */
70 Neighbor(sdbusplus::bus::bus& bus, const char* objPath,
71 EthernetInterface& parent, const std::string& ipAddress,
72 const std::string& macAddress, State state);
73
74 /** @brief Delete this d-bus object.
75 */
76 void delete_() override;
77
78 private:
79 /** @brief Parent Object. */
80 EthernetInterface& parent;
81};
82
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -070083namespace detail
84{
85
86void parseNeighbor(const nlmsghdr& hdr, std::string_view msg,
87 std::vector<NeighborInfo>& neighbors);
88
89} // namespace detail
90
William A. Kennington III08505792019-01-30 16:00:04 -080091} // namespace network
92} // namespace phosphor