1 #pragma once 2 #include "types.hpp" 3 4 #include <linux/netlink.h> 5 6 #include <cstdint> 7 #include <optional> 8 #include <sdbusplus/bus.hpp> 9 #include <sdbusplus/message/native_types.hpp> 10 #include <sdbusplus/server/object.hpp> 11 #include <string> 12 #include <string_view> 13 #include <vector> 14 #include <xyz/openbmc_project/Network/IP/server.hpp> 15 #include <xyz/openbmc_project/Object/Delete/server.hpp> 16 17 namespace phosphor 18 { 19 namespace network 20 { 21 22 using IPIfaces = sdbusplus::server::object_t< 23 sdbusplus::xyz::openbmc_project::Network::server::IP, 24 sdbusplus::xyz::openbmc_project::Object::server::Delete>; 25 26 using IP = sdbusplus::xyz::openbmc_project::Network::server::IP; 27 28 class EthernetInterface; 29 30 /* @class AddressFilter 31 */ 32 struct AddressFilter 33 { 34 unsigned interface = 0; 35 std::optional<uint8_t> scope; 36 }; 37 38 /** @class AddressInfo 39 * @brief Information about a addresses from the kernel 40 */ 41 struct AddressInfo 42 { 43 unsigned interface; 44 InAddrAny address; 45 uint8_t prefix; 46 uint8_t scope; 47 uint32_t flags; 48 }; 49 50 /** @brief Returns a list of the current system neighbor table 51 */ 52 std::vector<AddressInfo> getCurrentAddresses(const AddressFilter& filter); 53 54 /** @class IPAddress 55 * @brief OpenBMC IPAddress implementation. 56 * @details A concrete implementation for the 57 * xyz.openbmc_project.Network.IPProtocol 58 * xyz.openbmc_project.Network.IP Dbus interfaces. 59 */ 60 class IPAddress : public IPIfaces 61 { 62 public: 63 IPAddress() = delete; 64 IPAddress(const IPAddress&) = delete; 65 IPAddress& operator=(const IPAddress&) = delete; 66 IPAddress(IPAddress&&) = delete; 67 IPAddress& operator=(IPAddress&&) = delete; 68 virtual ~IPAddress() = default; 69 70 /** @brief Constructor to put object onto bus at a dbus path. 71 * @param[in] bus - Bus to attach to. 72 * @param[in] objRoot - Path to attach at. 73 * @param[in] parent - Parent object. 74 * @param[in] addr - The ip address and prefix. 75 * @param[in] origin - origin of ipaddress(dhcp/static/SLAAC/LinkLocal). 76 */ 77 IPAddress(sdbusplus::bus_t& bus, std::string_view objRoot, 78 EthernetInterface& parent, IfAddr addr, IP::AddressOrigin origin); 79 80 std::string address(std::string ipAddress) override; 81 uint8_t prefixLength(uint8_t) override; 82 std::string gateway(std::string gateway) override; 83 IP::Protocol type(IP::Protocol type) override; 84 IP::AddressOrigin origin(IP::AddressOrigin origin) override; 85 86 /** @brief Delete this d-bus object. 87 */ 88 void delete_() override; 89 90 using IP::address; 91 using IP::gateway; 92 using IP::origin; 93 using IP::prefixLength; 94 using IP::type; 95 96 inline const auto& getObjPath() const 97 { 98 return objPath; 99 } 100 101 private: 102 /** @brief Parent Object. */ 103 EthernetInterface& parent; 104 105 /** @brief Dbus object path */ 106 sdbusplus::message::object_path objPath; 107 108 IPAddress(sdbusplus::bus_t& bus, sdbusplus::message::object_path objPath, 109 EthernetInterface& parent, IfAddr addr, IP::AddressOrigin origin); 110 }; 111 112 namespace detail 113 { 114 115 void parseAddress(const AddressFilter& filter, const nlmsghdr& hdr, 116 std::string_view msg, std::vector<AddressInfo>& addresses); 117 118 } // namespace detail 119 } // namespace network 120 } // namespace phosphor 121