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