blob: 074cae099f2afe4c7ca2c2e6014821b473eb3fd2 [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 III08505792019-01-30 16:00:04 -08007
8#include <optional>
9#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server/object.hpp>
11#include <string>
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
24using NeighborObj = sdbusplus::server::object::object<
25 NeighborIntf, sdbusplus::xyz::openbmc_project::Object::server::Delete>;
26
27class EthernetInterface;
28
29/** @class NeighborInfo
30 * @brief Information about a neighbor from the kernel
31 */
32struct NeighborInfo
33{
34 std::string interface;
35 InAddrAny address;
36 std::optional<MacAddr> mac;
37 bool permanent;
38};
39
40/** @brief Returns a list of the current system neighbor table
41 */
42std::vector<NeighborInfo> getCurrentNeighbors();
43
44/** @class Neighbor
45 * @brief OpenBMC network neighbor implementation.
46 * @details A concrete implementation for the
47 * xyz.openbmc_project.Network.Neighbor dbus interface.
48 */
49class Neighbor : public NeighborObj
50{
51 public:
52 using State = NeighborIntf::State;
53
54 Neighbor() = delete;
55 Neighbor(const Neighbor&) = delete;
56 Neighbor& operator=(const Neighbor&) = delete;
57 Neighbor(Neighbor&&) = delete;
58 Neighbor& operator=(Neighbor&&) = delete;
59 virtual ~Neighbor() = default;
60
61 /** @brief Constructor to put object onto bus at a dbus path.
62 * @param[in] bus - Bus to attach to.
63 * @param[in] objPath - Path to attach at.
64 * @param[in] parent - Parent object.
65 * @param[in] ipAddress - IP address.
66 * @param[in] macAddress - Low level MAC address.
67 * @param[in] state - The state of the neighbor entry.
68 */
69 Neighbor(sdbusplus::bus::bus& bus, const char* objPath,
70 EthernetInterface& parent, const std::string& ipAddress,
71 const std::string& macAddress, State state);
72
73 /** @brief Delete this d-bus object.
74 */
75 void delete_() override;
76
77 private:
78 /** @brief Parent Object. */
79 EthernetInterface& parent;
80};
81
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -070082namespace detail
83{
84
85void parseNeighbor(const nlmsghdr& hdr, std::string_view msg,
86 std::vector<NeighborInfo>& neighbors);
87
88} // namespace detail
89
William A. Kennington III08505792019-01-30 16:00:04 -080090} // namespace network
91} // namespace phosphor