blob: cca9c114361872250493d66e58110ad6f4b99e72 [file] [log] [blame]
William A. Kennington III08505792019-01-30 16:00:04 -08001#pragma once
2
3#include "types.hpp"
William A. Kennington III08505792019-01-30 16:00:04 -08004
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -07005#include <linux/netlink.h>
William A. Kennington III6ca08d82019-04-20 16:04:18 -07006#include <net/ethernet.h>
William A. Kennington III08505792019-01-30 16:00:04 -08007
William A. Kennington IIId7946a72019-04-19 14:24:09 -07008#include <cstdint>
William A. Kennington III08505792019-01-30 16:00:04 -08009#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
William A. Kennington IIId7946a72019-04-19 14:24:09 -070030/* @class NeighborFilter
31 */
32struct NeighborFilter
33{
34 unsigned interface;
35 uint16_t state;
36
37 /* @brief Creates an empty filter */
38 NeighborFilter() : interface(0), state(~UINT16_C(0))
39 {
40 }
41};
42
William A. Kennington III08505792019-01-30 16:00:04 -080043/** @class NeighborInfo
44 * @brief Information about a neighbor from the kernel
45 */
46struct NeighborInfo
47{
William A. Kennington IIId7946a72019-04-19 14:24:09 -070048 unsigned interface;
William A. Kennington III08505792019-01-30 16:00:04 -080049 InAddrAny address;
William A. Kennington III6ca08d82019-04-20 16:04:18 -070050 std::optional<ether_addr> mac;
William A. Kennington IIId7946a72019-04-19 14:24:09 -070051 uint16_t state;
William A. Kennington III08505792019-01-30 16:00:04 -080052};
53
54/** @brief Returns a list of the current system neighbor table
55 */
William A. Kennington IIId7946a72019-04-19 14:24:09 -070056std::vector<NeighborInfo> getCurrentNeighbors(const NeighborFilter& filter);
William A. Kennington III08505792019-01-30 16:00:04 -080057
58/** @class Neighbor
59 * @brief OpenBMC network neighbor implementation.
60 * @details A concrete implementation for the
61 * xyz.openbmc_project.Network.Neighbor dbus interface.
62 */
63class Neighbor : public NeighborObj
64{
65 public:
66 using State = NeighborIntf::State;
67
68 Neighbor() = delete;
69 Neighbor(const Neighbor&) = delete;
70 Neighbor& operator=(const Neighbor&) = delete;
71 Neighbor(Neighbor&&) = delete;
72 Neighbor& operator=(Neighbor&&) = delete;
73 virtual ~Neighbor() = default;
74
75 /** @brief Constructor to put object onto bus at a dbus path.
76 * @param[in] bus - Bus to attach to.
77 * @param[in] objPath - Path to attach at.
78 * @param[in] parent - Parent object.
79 * @param[in] ipAddress - IP address.
80 * @param[in] macAddress - Low level MAC address.
81 * @param[in] state - The state of the neighbor entry.
82 */
83 Neighbor(sdbusplus::bus::bus& bus, const char* objPath,
84 EthernetInterface& parent, const std::string& ipAddress,
85 const std::string& macAddress, State state);
86
87 /** @brief Delete this d-bus object.
88 */
89 void delete_() override;
90
91 private:
92 /** @brief Parent Object. */
93 EthernetInterface& parent;
94};
95
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -070096namespace detail
97{
98
William A. Kennington IIId7946a72019-04-19 14:24:09 -070099void parseNeighbor(const NeighborFilter& filter, const nlmsghdr& hdr,
100 std::string_view msg, std::vector<NeighborInfo>& neighbors);
William A. Kennington IIIc920bdb2019-04-19 14:23:06 -0700101
102} // namespace detail
103
William A. Kennington III08505792019-01-30 16:00:04 -0800104} // namespace network
105} // namespace phosphor