1 #pragma once
2 #include "types.hpp"
3 
4 #include <sdbusplus/bus.hpp>
5 #include <sdbusplus/message/native_types.hpp>
6 #include <sdbusplus/server/object.hpp>
7 #include <stdplus/pinned.hpp>
8 #include <xyz/openbmc_project/Network/IP/server.hpp>
9 #include <xyz/openbmc_project/Object/Delete/server.hpp>
10 
11 #include <string_view>
12 
13 namespace phosphor
14 {
15 namespace network
16 {
17 
18 using IPIfaces = sdbusplus::server::object_t<
19     sdbusplus::xyz::openbmc_project::Network::server::IP,
20     sdbusplus::xyz::openbmc_project::Object::server::Delete>;
21 
22 using IP = sdbusplus::xyz::openbmc_project::Network::server::IP;
23 
24 class EthernetInterface;
25 
26 /** @class IPAddress
27  *  @brief OpenBMC IPAddress implementation.
28  *  @details A concrete implementation for the
29  *  xyz.openbmc_project.Network.IPProtocol
30  *  xyz.openbmc_project.Network.IP Dbus interfaces.
31  */
32 class IPAddress : public IPIfaces
33 {
34   public:
35     /** @brief Constructor to put object onto bus at a dbus path.
36      *  @param[in] bus - Bus to attach to.
37      *  @param[in] objRoot - Path to attach at.
38      *  @param[in] parent - Parent object.
39      *  @param[in] addr - The ip address and prefix.
40      *  @param[in] origin - origin of ipaddress(dhcp/static/SLAAC/LinkLocal).
41      */
42     IPAddress(sdbusplus::bus_t& bus, std::string_view objRoot,
43               stdplus::PinnedRef<EthernetInterface> parent,
44               stdplus::SubnetAny addr, IP::AddressOrigin origin);
45 
46     std::string address(std::string ipAddress) override;
47     uint8_t prefixLength(uint8_t) override;
48     std::string gateway(std::string gateway) override;
49     IP::Protocol type(IP::Protocol type) override;
50     IP::AddressOrigin origin(IP::AddressOrigin origin) override;
51 
52     /** @brief Delete this d-bus object.
53      */
54     void delete_() override;
55 
56     using IP::address;
57     using IP::gateway;
58     using IP::origin;
59     using IP::prefixLength;
60     using IP::type;
61 
getObjPath() const62     inline const auto& getObjPath() const
63     {
64         return objPath;
65     }
66 
67   private:
68     /** @brief Parent Object. */
69     stdplus::PinnedRef<EthernetInterface> parent;
70 
71     /** @brief Dbus object path */
72     sdbusplus::message::object_path objPath;
73 
74     IPAddress(sdbusplus::bus_t& bus, sdbusplus::message::object_path objPath,
75               stdplus::PinnedRef<EthernetInterface> parent,
76               stdplus::SubnetAny addr, IP::AddressOrigin origin);
77 };
78 
79 } // namespace network
80 } // namespace phosphor
81