1 #pragma once
2 
3 #include "xyz/openbmc_project/Network/IP/Create/server.hpp"
4 
5 #include <phosphor-logging/elog-errors.hpp>
6 #include <phosphor-logging/elog.hpp>
7 #include <sdbusplus/bus.hpp>
8 #include <xyz/openbmc_project/Common/error.hpp>
9 #include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
10 #include <xyz/openbmc_project/Network/IP/server.hpp>
11 
12 namespace phosphor
13 {
14 namespace network
15 {
16 
17 class HypNetworkMgr; // forward declaration of hypervisor network manager.
18 
19 using namespace phosphor::logging;
20 using HypIP = sdbusplus::xyz::openbmc_project::Network::server::IP;
21 
22 using CreateIface = sdbusplus::server::object_t<
23     sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface,
24     sdbusplus::xyz::openbmc_project::Network::IP::server::Create>;
25 
26 using biosTableType = std::map<std::string, std::variant<int64_t, std::string>>;
27 
28 using HypEthernetIntf =
29     sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface;
30 
31 using ObjectPath = sdbusplus::message::object_path;
32 
33 static std::shared_ptr<sdbusplus::bus::match_t> matchBIOSAttrUpdate;
34 
35 /** @class HypEthernetInterface
36  *  @brief Hypervisor Ethernet Interface implementation.
37  */
38 class HypEthInterface : public CreateIface
39 {
40   public:
41     HypEthInterface() = delete;
42     HypEthInterface(const HypEthInterface&) = delete;
43     HypEthInterface& operator=(const HypEthInterface&) = delete;
44     HypEthInterface(HypEthInterface&&) = delete;
45     HypEthInterface& operator=(HypEthInterface&&) = delete;
46     virtual ~HypEthInterface() = default;
47 
48     /** @brief Constructor to put object onto bus at a dbus path.
49      *  @param[in] bus - Bus to attach to.
50      *  @param[in] path - Path to attach at.
51      *  @param[in] parent - parent object.
52      */
HypEthInterface(sdbusplus::bus_t & bus,const char * path,std::string_view intfName,HypNetworkMgr & parent)53     HypEthInterface(sdbusplus::bus_t& bus, const char* path,
54                     std::string_view intfName, HypNetworkMgr& parent) :
55         CreateIface(bus, path, CreateIface::action::defer_emit), bus(bus),
56         objectPath(path), manager(parent)
57     {
58         HypEthernetIntf::interfaceName(intfName.data(), true);
59         emit_object_added();
60     };
61 
62     /** @brief Function to create ipAddress dbus object.
63      *  @param[in] addressType - Type of ip address.
64      *  @param[in] ipAddress- IP address.
65      *  @param[in] prefixLength - Length of prefix.
66      *  @param[in] gateway - Gateway ip address.
67      */
68 
ip(HypIP::Protocol,std::string,uint8_t,std::string)69     ObjectPath ip(HypIP::Protocol /*addressType*/, std::string /*ipAddress*/,
70                   uint8_t /*prefixLength*/, std::string /*gateway*/) override
71     {
72         return std::string();
73     };
74 
75     /* @brief Function that returns parent's bios attrs map
76      */
77     biosTableType getBiosAttrsMap();
78 
79     /* @brief Returns the dhcp enabled property
80      * @param[in] protocol - ipv4/ipv6
81      * @return bool - true if dhcpEnabled
82      */
83     bool isDHCPEnabled(HypIP::Protocol protocol);
84 
85     /** Set value of DHCPEnabled */
86     HypEthernetIntf::DHCPConf dhcpEnabled() const override;
87     HypEthernetIntf::DHCPConf dhcpEnabled(DHCPConf value) override;
88     using HypEthernetIntf::dhcp4;
89     bool dhcp4(bool value) override;
90     using HypEthernetIntf::dhcp6;
91     bool dhcp6(bool value) override;
92 
93     /** @brief check conf file for Router Advertisements
94      *
95      */
96     bool ipv6AcceptRA(bool value) override;
97     using HypEthernetIntf::ipv6AcceptRA;
98 
99     using HypEthernetIntf::interfaceName;
100 
101   protected:
102     /** @brief sdbusplus DBus bus connection. */
103     sdbusplus::bus_t& bus;
104 
105     /** @brief object path */
106     std::string objectPath;
107 
108     /** @brief Parent of this object */
109     HypNetworkMgr& manager;
110 
111   private:
112     /** @brief Determines if DHCP is active for the IP::Protocol supplied.
113      *  @param[in] protocol - Either IPv4 or IPv6
114      *  @returns true/false value if DHCP is active for the input protocol
115      */
116     bool dhcpIsEnabled(HypIP::Protocol protocol);
117 };
118 
119 } // namespace network
120 } // namespace phosphor
121