blob: 94bdfdb960582590c5930e2454204cce2cf8d233 [file] [log] [blame]
Ratan Gupta4af36762017-04-20 19:12:29 +05301#pragma once
William A. Kennington IIIc2e5e0e2019-04-22 01:26:06 -07002#include "types.hpp"
Ratan Gupta4af36762017-04-20 19:12:29 +05303
William A. Kennington IIIc2e5e0e2019-04-22 01:26:06 -07004#include <linux/netlink.h>
5
6#include <cstdint>
7#include <optional>
Ratan Gupta4af36762017-04-20 19:12:29 +05308#include <sdbusplus/bus.hpp>
William A. Kennington III59e5b912022-11-02 02:49:46 -07009#include <sdbusplus/message/native_types.hpp>
Ratan Gupta4af36762017-04-20 19:12:29 +053010#include <sdbusplus/server/object.hpp>
William A. Kennington III59e5b912022-11-02 02:49:46 -070011#include <string>
William A. Kennington IIIc2e5e0e2019-04-22 01:26:06 -070012#include <string_view>
13#include <vector>
Patrick Venture189d44e2018-07-09 12:30:59 -070014#include <xyz/openbmc_project/Network/IP/server.hpp>
15#include <xyz/openbmc_project/Object/Delete/server.hpp>
Ratan Gupta4af36762017-04-20 19:12:29 +053016
17namespace phosphor
18{
19namespace network
20{
21
Patrick Williamsc38b0712022-07-22 19:26:54 -050022using IPIfaces = sdbusplus::server::object_t<
Gunnar Mills57d9c502018-09-14 14:42:34 -050023 sdbusplus::xyz::openbmc_project::Network::server::IP,
24 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Ratan Gupta4af36762017-04-20 19:12:29 +053025
26using IP = sdbusplus::xyz::openbmc_project::Network::server::IP;
27
28class EthernetInterface;
29
William A. Kennington IIIc2e5e0e2019-04-22 01:26:06 -070030/* @class AddressFilter
31 */
32struct 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 */
41struct 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 */
52std::vector<AddressInfo> getCurrentAddresses(const AddressFilter& filter);
53
Ratan Gupta4af36762017-04-20 19:12:29 +053054/** @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 */
60class IPAddress : public IPIfaces
61{
Gunnar Mills57d9c502018-09-14 14:42:34 -050062 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 Gupta4af36762017-04-20 19:12:29 +053069
Gunnar Mills57d9c502018-09-14 14:42:34 -050070 /** @brief Constructor to put object onto bus at a dbus path.
71 * @param[in] bus - Bus to attach to.
William A. Kennington III59e5b912022-11-02 02:49:46 -070072 * @param[in] objRoot - Path to attach at.
Gunnar Mills57d9c502018-09-14 14:42:34 -050073 * @param[in] parent - Parent object.
William A. Kennington III59e5b912022-11-02 02:49:46 -070074 * @param[in] addr - The ip address and prefix.
Gunnar Mills57d9c502018-09-14 14:42:34 -050075 * @param[in] origin - origin of ipaddress(dhcp/static/SLAAC/LinkLocal).
Gunnar Mills57d9c502018-09-14 14:42:34 -050076 */
William A. Kennington III59e5b912022-11-02 02:49:46 -070077 IPAddress(sdbusplus::bus_t& bus, std::string_view objRoot,
78 EthernetInterface& parent, IfAddr addr, IP::AddressOrigin origin);
Ratan Gupta4af36762017-04-20 19:12:29 +053079
William A. Kennington III5e72d082022-09-01 13:10:17 -070080 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 Mills57d9c502018-09-14 14:42:34 -050086 /** @brief Delete this d-bus object.
87 */
88 void delete_() override;
Ratan Gupta4af36762017-04-20 19:12:29 +053089
Ravi Teja2fd2f7d2019-06-06 03:27:55 -050090 using IP::address;
91 using IP::gateway;
92 using IP::origin;
93 using IP::prefixLength;
94 using IP::type;
95
William A. Kennington III59e5b912022-11-02 02:49:46 -070096 inline const auto& getObjPath() const
97 {
98 return objPath;
99 }
100
Gunnar Mills57d9c502018-09-14 14:42:34 -0500101 private:
102 /** @brief Parent Object. */
103 EthernetInterface& parent;
William A. Kennington III59e5b912022-11-02 02:49:46 -0700104
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 Gupta4af36762017-04-20 19:12:29 +0530110};
111
William A. Kennington IIIc2e5e0e2019-04-22 01:26:06 -0700112namespace detail
113{
114
115void parseAddress(const AddressFilter& filter, const nlmsghdr& hdr,
116 std::string_view msg, std::vector<AddressInfo>& addresses);
117
118} // namespace detail
Ratan Gupta4af36762017-04-20 19:12:29 +0530119} // namespace network
120} // namespace phosphor