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 | 6ca08d8 | 2019-04-20 16:04:18 -0700 | [diff] [blame] | 7 | #include <net/ethernet.h> |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 8 | |
| 9 | #include <optional> |
| 10 | #include <sdbusplus/bus.hpp> |
| 11 | #include <sdbusplus/server/object.hpp> |
| 12 | #include <string> |
William A. Kennington III | c920bdb | 2019-04-19 14:23:06 -0700 | [diff] [blame] | 13 | #include <string_view> |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 14 | #include <vector> |
| 15 | #include <xyz/openbmc_project/Network/Neighbor/server.hpp> |
| 16 | #include <xyz/openbmc_project/Object/Delete/server.hpp> |
| 17 | |
| 18 | namespace phosphor |
| 19 | { |
| 20 | namespace network |
| 21 | { |
| 22 | |
| 23 | using NeighborIntf = sdbusplus::xyz::openbmc_project::Network::server::Neighbor; |
| 24 | |
| 25 | using NeighborObj = sdbusplus::server::object::object< |
| 26 | NeighborIntf, sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
| 27 | |
| 28 | class EthernetInterface; |
| 29 | |
| 30 | /** @class NeighborInfo |
| 31 | * @brief Information about a neighbor from the kernel |
| 32 | */ |
| 33 | struct NeighborInfo |
| 34 | { |
| 35 | std::string interface; |
| 36 | InAddrAny address; |
William A. Kennington III | 6ca08d8 | 2019-04-20 16:04:18 -0700 | [diff] [blame] | 37 | std::optional<ether_addr> mac; |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 38 | bool permanent; |
| 39 | }; |
| 40 | |
| 41 | /** @brief Returns a list of the current system neighbor table |
| 42 | */ |
| 43 | std::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 | */ |
| 50 | class 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 III | c920bdb | 2019-04-19 14:23:06 -0700 | [diff] [blame] | 83 | namespace detail |
| 84 | { |
| 85 | |
| 86 | void parseNeighbor(const nlmsghdr& hdr, std::string_view msg, |
| 87 | std::vector<NeighborInfo>& neighbors); |
| 88 | |
| 89 | } // namespace detail |
| 90 | |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 91 | } // namespace network |
| 92 | } // namespace phosphor |