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> |
William A. Kennington III | 59e5b91 | 2022-11-02 02:49:46 -0700 | [diff] [blame] | 9 | #include <sdbusplus/message/native_types.hpp> |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 10 | #include <sdbusplus/server/object.hpp> |
William A. Kennington III | 59e5b91 | 2022-11-02 02:49:46 -0700 | [diff] [blame] | 11 | #include <string> |
William A. Kennington III | c2e5e0e | 2019-04-22 01:26:06 -0700 | [diff] [blame] | 12 | #include <string_view> |
| 13 | #include <vector> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 14 | #include <xyz/openbmc_project/Network/IP/server.hpp> |
| 15 | #include <xyz/openbmc_project/Object/Delete/server.hpp> |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 16 | |
| 17 | namespace phosphor |
| 18 | { |
| 19 | namespace network |
| 20 | { |
| 21 | |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 22 | using IPIfaces = sdbusplus::server::object_t< |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 23 | sdbusplus::xyz::openbmc_project::Network::server::IP, |
| 24 | sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 25 | |
| 26 | using IP = sdbusplus::xyz::openbmc_project::Network::server::IP; |
| 27 | |
| 28 | class EthernetInterface; |
| 29 | |
William A. Kennington III | c2e5e0e | 2019-04-22 01:26:06 -0700 | [diff] [blame] | 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 | |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 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 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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; |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 69 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 70 | /** @brief Constructor to put object onto bus at a dbus path. |
| 71 | * @param[in] bus - Bus to attach to. |
William A. Kennington III | 59e5b91 | 2022-11-02 02:49:46 -0700 | [diff] [blame] | 72 | * @param[in] objRoot - Path to attach at. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 73 | * @param[in] parent - Parent object. |
William A. Kennington III | 59e5b91 | 2022-11-02 02:49:46 -0700 | [diff] [blame] | 74 | * @param[in] addr - The ip address and prefix. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 75 | * @param[in] origin - origin of ipaddress(dhcp/static/SLAAC/LinkLocal). |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 76 | */ |
William A. Kennington III | 59e5b91 | 2022-11-02 02:49:46 -0700 | [diff] [blame] | 77 | IPAddress(sdbusplus::bus_t& bus, std::string_view objRoot, |
| 78 | EthernetInterface& parent, IfAddr addr, IP::AddressOrigin origin); |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 79 | |
William A. Kennington III | 5e72d08 | 2022-09-01 13:10:17 -0700 | [diff] [blame] | 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 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 86 | /** @brief Delete this d-bus object. |
| 87 | */ |
| 88 | void delete_() override; |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 89 | |
Ravi Teja | 2fd2f7d | 2019-06-06 03:27:55 -0500 | [diff] [blame] | 90 | using IP::address; |
| 91 | using IP::gateway; |
| 92 | using IP::origin; |
| 93 | using IP::prefixLength; |
| 94 | using IP::type; |
| 95 | |
William A. Kennington III | 59e5b91 | 2022-11-02 02:49:46 -0700 | [diff] [blame] | 96 | inline const auto& getObjPath() const |
| 97 | { |
| 98 | return objPath; |
| 99 | } |
| 100 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 101 | private: |
| 102 | /** @brief Parent Object. */ |
| 103 | EthernetInterface& parent; |
William A. Kennington III | 59e5b91 | 2022-11-02 02:49:46 -0700 | [diff] [blame] | 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); |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 110 | }; |
| 111 | |
William A. Kennington III | c2e5e0e | 2019-04-22 01:26:06 -0700 | [diff] [blame] | 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 |
Ratan Gupta | 4af3676 | 2017-04-20 19:12:29 +0530 | [diff] [blame] | 119 | } // namespace network |
| 120 | } // namespace phosphor |