Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 1 | #pragma once |
William A. Kennington III | c2e5e0e | 2019-04-22 01:26:06 -0700 | [diff] [blame] | 2 | #include "types.hpp" |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 3 | |
William A. Kennington III | c2e5e0e | 2019-04-22 01:26:06 -0700 | [diff] [blame] | 4 | #include <linux/netlink.h> |
| 5 | |
| 6 | #include <cstdint> |
| 7 | #include <optional> |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
| 9 | #include <sdbusplus/server/object.hpp> |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 10 | #include <string> |
William A. Kennington III | c2e5e0e | 2019-04-22 01:26:06 -0700 | [diff] [blame] | 11 | #include <string_view> |
| 12 | #include <vector> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 13 | #include <xyz/openbmc_project/Network/IP/server.hpp> |
| 14 | #include <xyz/openbmc_project/Object/Delete/server.hpp> |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace network |
| 19 | { |
| 20 | |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 21 | using IPIfaces = sdbusplus::server::object_t< |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 22 | sdbusplus::xyz::openbmc_project::Network::server::IP, |
| 23 | sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 24 | |
| 25 | using IP = sdbusplus::xyz::openbmc_project::Network::server::IP; |
| 26 | |
| 27 | class EthernetInterface; |
| 28 | |
William A. Kennington III | c2e5e0e | 2019-04-22 01:26:06 -0700 | [diff] [blame] | 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 | |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 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 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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; |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 68 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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 | * @param[in] gateway - gateway address. |
| 78 | */ |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 79 | IPAddress(sdbusplus::bus_t& bus, const char* objPath, |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 80 | EthernetInterface& parent, IP::Protocol type, |
| 81 | const std::string& ipAddress, IP::AddressOrigin origin, |
| 82 | uint8_t prefixLength, const std::string& gateway); |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 83 | |
William A. Kennington III | 5e72d08 | 2022-09-01 13:10:17 -0700 | [diff] [blame] | 84 | std::string address(std::string ipAddress) override; |
| 85 | uint8_t prefixLength(uint8_t) override; |
| 86 | std::string gateway(std::string gateway) override; |
| 87 | IP::Protocol type(IP::Protocol type) override; |
| 88 | IP::AddressOrigin origin(IP::AddressOrigin origin) override; |
| 89 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 90 | /** @brief Delete this d-bus object. |
| 91 | */ |
| 92 | void delete_() override; |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 93 | |
Ravi Teja | 2fd2f7d | 2019-06-06 03:27:55 -0500 | [diff] [blame] | 94 | using IP::address; |
| 95 | using IP::gateway; |
| 96 | using IP::origin; |
| 97 | using IP::prefixLength; |
| 98 | using IP::type; |
| 99 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 100 | private: |
| 101 | /** @brief Parent Object. */ |
| 102 | EthernetInterface& parent; |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 103 | }; |
| 104 | |
William A. Kennington III | c2e5e0e | 2019-04-22 01:26:06 -0700 | [diff] [blame] | 105 | namespace detail |
| 106 | { |
| 107 | |
| 108 | void parseAddress(const AddressFilter& filter, const nlmsghdr& hdr, |
| 109 | std::string_view msg, std::vector<AddressInfo>& addresses); |
| 110 | |
| 111 | } // namespace detail |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 112 | } // namespace network |
| 113 | } // namespace phosphor |