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