William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "types.hpp" |
| 4 | #include "util.hpp" |
| 5 | |
William A. Kennington III | c920bdb | 2019-04-19 14:23:06 -0700 | [diff] [blame^] | 6 | #include <linux/netlink.h> |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 7 | |
| 8 | #include <optional> |
| 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <sdbusplus/server/object.hpp> |
| 11 | #include <string> |
William A. Kennington III | c920bdb | 2019-04-19 14:23:06 -0700 | [diff] [blame^] | 12 | #include <string_view> |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 13 | #include <vector> |
| 14 | #include <xyz/openbmc_project/Network/Neighbor/server.hpp> |
| 15 | #include <xyz/openbmc_project/Object/Delete/server.hpp> |
| 16 | |
| 17 | namespace phosphor |
| 18 | { |
| 19 | namespace network |
| 20 | { |
| 21 | |
| 22 | using NeighborIntf = sdbusplus::xyz::openbmc_project::Network::server::Neighbor; |
| 23 | |
| 24 | using NeighborObj = sdbusplus::server::object::object< |
| 25 | NeighborIntf, sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
| 26 | |
| 27 | class EthernetInterface; |
| 28 | |
| 29 | /** @class NeighborInfo |
| 30 | * @brief Information about a neighbor from the kernel |
| 31 | */ |
| 32 | struct 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 | */ |
| 42 | std::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 | */ |
| 49 | class 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 III | c920bdb | 2019-04-19 14:23:06 -0700 | [diff] [blame^] | 82 | namespace detail |
| 83 | { |
| 84 | |
| 85 | void parseNeighbor(const nlmsghdr& hdr, std::string_view msg, |
| 86 | std::vector<NeighborInfo>& neighbors); |
| 87 | |
| 88 | } // namespace detail |
| 89 | |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 90 | } // namespace network |
| 91 | } // namespace phosphor |