blob: 0047d11d8cfbf223e2b3267e52ffa0b46fb06e4b [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>
9#include <sdbusplus/server/object.hpp>
Ratan Gupta4af36762017-04-20 19:12:29 +053010#include <string>
William A. Kennington IIIc2e5e0e2019-04-22 01:26:06 -070011#include <string_view>
12#include <vector>
Patrick Venture189d44e2018-07-09 12:30:59 -070013#include <xyz/openbmc_project/Network/IP/server.hpp>
14#include <xyz/openbmc_project/Object/Delete/server.hpp>
Ratan Gupta4af36762017-04-20 19:12:29 +053015
16namespace phosphor
17{
18namespace network
19{
20
Patrick Williamsc38b0712022-07-22 19:26:54 -050021using IPIfaces = sdbusplus::server::object_t<
Gunnar Mills57d9c502018-09-14 14:42:34 -050022 sdbusplus::xyz::openbmc_project::Network::server::IP,
23 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Ratan Gupta4af36762017-04-20 19:12:29 +053024
25using IP = sdbusplus::xyz::openbmc_project::Network::server::IP;
26
27class EthernetInterface;
28
William A. Kennington IIIc2e5e0e2019-04-22 01:26:06 -070029/* @class AddressFilter
30 */
31struct 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 */
40struct 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 */
51std::vector<AddressInfo> getCurrentAddresses(const AddressFilter& filter);
52
Ratan Gupta4af36762017-04-20 19:12:29 +053053/** @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 */
59class IPAddress : public IPIfaces
60{
Gunnar Mills57d9c502018-09-14 14:42:34 -050061 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 Gupta4af36762017-04-20 19:12:29 +053068
Gunnar Mills57d9c502018-09-14 14:42:34 -050069 /** @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 Williamsc38b0712022-07-22 19:26:54 -050079 IPAddress(sdbusplus::bus_t& bus, const char* objPath,
Gunnar Mills57d9c502018-09-14 14:42:34 -050080 EthernetInterface& parent, IP::Protocol type,
81 const std::string& ipAddress, IP::AddressOrigin origin,
82 uint8_t prefixLength, const std::string& gateway);
Ratan Gupta4af36762017-04-20 19:12:29 +053083
Gunnar Mills57d9c502018-09-14 14:42:34 -050084 /** @brief Delete this d-bus object.
85 */
86 void delete_() override;
Ratan Gupta4af36762017-04-20 19:12:29 +053087
Ravi Teja2fd2f7d2019-06-06 03:27:55 -050088 using IP::address;
89 using IP::gateway;
90 using IP::origin;
91 using IP::prefixLength;
92 using IP::type;
93
Gunnar Mills57d9c502018-09-14 14:42:34 -050094 private:
95 /** @brief Parent Object. */
96 EthernetInterface& parent;
Ratan Gupta4af36762017-04-20 19:12:29 +053097};
98
William A. Kennington IIIc2e5e0e2019-04-22 01:26:06 -070099namespace detail
100{
101
102void parseAddress(const AddressFilter& filter, const nlmsghdr& hdr,
103 std::string_view msg, std::vector<AddressInfo>& addresses);
104
105} // namespace detail
Ratan Gupta4af36762017-04-20 19:12:29 +0530106} // namespace network
107} // namespace phosphor