Skip to content

Commit b22e2ff

Browse files
committed
hyp-nw-mgr: Add support for hypervisor nw config
* ibm/hyp-nw-mgr: Add ip objects for ethernet intf In this commit, ip address dbus objects are created under the hypervisor network service. busctl tree xyz.openbmc_project.Network.Hypervisor └─/xyz └─/xyz/openbmc_project └─/xyz/openbmc_project/network └─/xyz/openbmc_project/network/hypervisor ├─/xyz/openbmc_project/network/hypervisor/config ├─/xyz/openbmc_project/network/hypervisor/eth0 │ └─/xyz/openbmc_project/network/hypervisor/eth0/ipv4 │ └─/xyz/openbmc_project/network/hypervisor/eth0/ipv4/addr0 └─/xyz/openbmc_project/network/hypervisor/eth1 └─/xyz/openbmc_project/network/hypervisor/eth1/ipv4 └─/xyz/openbmc_project/network/hypervisor/eth1/ipv4/addr0 The values for the properties of IP interfaces will be initialized by parsing the bios table. * ibm/hyp-nw-mgr: IP create, delete & sync with bios This commit adds: 1. support for creation and deletion of an ip address object 2. update the bios table as and when there is a change in the dbus object * ibm/hyp-nw-mgr: Sync BIOStable with hypervisor app This change would listen on the properties changed signal on BaseBIOSTable property of bios config manager. Whenever there is a signal, the change would be updated on the corresponding ethernet and ip address dbus objects. * ibm/hyp-nw-mgr: Persist Enabled property on reboot The "Enabled" property of xyz.openbmc_project.Object.Enable interface of the ip address object (eg: /xyz/openbmc_project/network/hypervisor/eth<0/1>/ipv4/addr0) will be set by pldm once the host consumes the ip address set by the user. When the system reboots, this value is not persisted and is defaulted to false. Pldm will not be updating this value on reboot, it only sets it when phyp sends the sensor event when the ip is consumed and pldm receives this and sets the "Enabled" property. * ibm/hyp-nw-mgr: Add ipv6 support in hypervisor app Currently, there is no support for ipv6 in the hypervisor application. This commit adds ipv6 support, and the changes mainly includes creation of ipv4 & ipv6 dbus objects when the application starts; adding support in watch method where ipv6 property changes are also monitored; setting default values for ipv6 properties in the bios. * ibm/hyp-nw-mgr: Add Hypervisor IPv6 SLAAC support This commit adds "StatelessAddressAutoConfig" support in the hypervisor app. Earlier there were only 4 values - none, both, v4, v6. Now with the latest dbus interfaces change, there are 2 more values introduced - v6Stateless, v4v6Stateless. v4v6stateless: Enable IPv4 DHCP and IPv6 SLAAC v6stateless: Enable IPv6 SLAAC * ibm/hyp-nw-mgr: Add dependency on pldm service The hypervisor app depends on the bios service currently, that comes up with the bios table. But it is pldm that populates the bios table values. There are cases, where hypervisor app comes up first before pldm populates the bios table, causing the app to have default values (0.0.0.0 ip) in the dbus even when hypervisor network ip has been configured. This commit adds a dependency on pldm service for the hypervisor app to start. Tested By: busctl tree xyz.openbmc_project.Network.Hypervisor * configure static ip and the same has been updated on the biostable ''' PATCH -D patch.txt -d '{"IPv4StaticAddresses":[{"Address": "10.6.6.2", "SubnetMask": "255.255.252.0","Gateway":"10.6.6.1"}]}' https://${bmc}/redfish/v1/Systems/hypervisor/EthernetInterfaces/eth0 ''' * update ip properties on the bios table and the same has reflected on the dbus object * enable dhcp, bios table will be updated with the dhcp server sent ip and the same reflects on the dbus object * Checked both reboot and code update scenarios Signed-off-by: Asmitha Karunanithi <[email protected]>
1 parent e3b287b commit b22e2ff

13 files changed

+2242
-92
lines changed

src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.cpp

+1,161-19
Large diffs are not rendered by default.

src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.hpp

+116-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
#pragma once
22

3-
#include "xyz/openbmc_project/Network/IP/Create/server.hpp"
3+
#include "hyp_ip_interface.hpp"
4+
#include "hyp_network_manager.hpp"
5+
#include "types.hpp"
46

57
#include <phosphor-logging/elog-errors.hpp>
68
#include <phosphor-logging/elog.hpp>
9+
#include <phosphor-logging/lg2.hpp>
710
#include <sdbusplus/bus.hpp>
11+
#include <stdplus/pinned.hpp>
12+
#include <stdplus/str/maps.hpp>
13+
#include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp>
814
#include <xyz/openbmc_project/Common/error.hpp>
915
#include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
16+
#include <xyz/openbmc_project/Network/IP/Create/server.hpp>
1017
#include <xyz/openbmc_project/Network/IP/server.hpp>
1118

1219
namespace phosphor
@@ -16,22 +23,32 @@ namespace network
1623

1724
class HypNetworkMgr; // forward declaration of hypervisor network manager.
1825

26+
class HypIPAddress;
27+
1928
using namespace phosphor::logging;
20-
using HypIP = sdbusplus::xyz::openbmc_project::Network::server::IP;
2129

2230
using CreateIface = sdbusplus::server::object_t<
2331
sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface,
2432
sdbusplus::xyz::openbmc_project::Network::IP::server::Create>;
2533

34+
using biosTableRetAttrValueType = std::variant<std::string, int64_t>;
35+
2636
using biosTableType = std::map<std::string, std::variant<int64_t, std::string>>;
2737

2838
using HypEthernetIntf =
2939
sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface;
3040

41+
using HypIP = sdbusplus::xyz::openbmc_project::Network::server::IP;
42+
3143
using ObjectPath = sdbusplus::message::object_path;
3244

45+
using ipAddrMapType = stdplus::string_umap<std::unique_ptr<HypIPAddress>>;
46+
3347
static std::shared_ptr<sdbusplus::bus::match_t> matchBIOSAttrUpdate;
3448

49+
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
50+
using Argument = xyz::openbmc_project::Common::InvalidArgument;
51+
3552
/** @class HypEthernetInterface
3653
* @brief Hypervisor Ethernet Interface implementation.
3754
*/
@@ -48,39 +65,118 @@ class HypEthInterface : public CreateIface
4865
/** @brief Constructor to put object onto bus at a dbus path.
4966
* @param[in] bus - Bus to attach to.
5067
* @param[in] path - Path to attach at.
68+
* @param[in] intfName - ethernet interface id (eth0/eth1)
5169
* @param[in] parent - parent object.
5270
*/
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)
71+
HypEthInterface(stdplus::PinnedRef<sdbusplus::bus_t> bus,
72+
sdbusplus::message::object_path path,
73+
std::string_view intfName,
74+
stdplus::PinnedRef<HypNetworkMgr> parent) :
75+
CreateIface(bus, path.str.c_str(), CreateIface::action::defer_emit),
76+
bus(bus), objectPath(std::move(path)), manager(parent)
5777
{
5878
HypEthernetIntf::interfaceName(intfName.data(), true);
5979
emit_object_added();
6080
};
6181

82+
/* @brief Method to return the value of the input attribute
83+
* from the BaseBIOSTable
84+
* @param[in] attrName - name of the bios attribute
85+
* @param[out] - value of the bios attribute
86+
*/
87+
biosTableRetAttrValueType getAttrFromBiosTable(const std::string& attrName);
88+
89+
/* @brief Function to watch the Base Bios Table for ip
90+
* address change from the host and refresh the hypervisor networkd
91+
* service
92+
*/
93+
void watchBaseBiosTable();
94+
95+
/* @brief creates the IP dbus object
96+
*/
97+
virtual void createIPAddressObjects();
98+
6299
/** @brief Function to create ipAddress dbus object.
63100
* @param[in] addressType - Type of ip address.
64101
* @param[in] ipAddress- IP address.
65102
* @param[in] prefixLength - Length of prefix.
66103
* @param[in] gateway - Gateway ip address.
67104
*/
68105

69-
ObjectPath ip(HypIP::Protocol /*addressType*/, std::string /*ipAddress*/,
70-
uint8_t /*prefixLength*/, std::string /*gateway*/) override
71-
{
72-
return std::string();
73-
};
106+
ObjectPath ip(HypIP::Protocol addressType, std::string ipAddress,
107+
uint8_t prefixLength, std::string gateway) override;
108+
109+
/* @brief Function to delete the IP dbus object
110+
* @param[in] ipaddress - ipaddress to delete.
111+
*/
112+
bool deleteObject(const std::string& ipaddress);
113+
114+
/* @brief Returns interface id
115+
* @param[out] - if0/if1
116+
*/
117+
std::string getIntfLabel();
118+
119+
/* @brief Function to update the ip address property in
120+
the dbus object
121+
* @detail if there is a change in ip address in bios
122+
table, the ip is updated in the dbus obj path
123+
* @param[in] updatedIp - ip to update
124+
*/
125+
void updateIPAddress(std::string ip, std::string updatedIp);
74126

75127
/* @brief Function that returns parent's bios attrs map
76128
*/
77129
biosTableType getBiosAttrsMap();
78130

79-
/* @brief Returns the dhcp enabled property
80-
* @param[in] protocol - ipv4/ipv6
81-
* @return bool - true if dhcpEnabled
131+
/* @brief Function to set ip address properties in
132+
the parent's bios attrs map
133+
* @detail if there is a change in any properties either in bios
134+
table or on the dbus object, the bios attrs map data member
135+
of the parent should be updated with the latest value
136+
* @param[in] attrName - attrName for which there is a change in value
137+
* @param[in] attrValue - updated value
138+
* @param[in] attrType - type of the attrValue (string/integer)
82139
*/
83-
bool isDHCPEnabled(HypIP::Protocol protocol);
140+
void setIpPropsInMap(std::string attrName,
141+
std::variant<std::string, int64_t> attrValue,
142+
std::string attrType);
143+
144+
template <typename Addr>
145+
static bool validIntfIP(Addr a) noexcept
146+
{
147+
return a.isUnicast() && !a.isLoopback();
148+
}
149+
150+
template <typename Addr>
151+
static void validateGateway(std::string& gw)
152+
{
153+
try
154+
{
155+
auto ip = stdplus::fromStr<Addr>(gw);
156+
if (ip == Addr{})
157+
{
158+
throw std::invalid_argument("Empty gateway");
159+
}
160+
if (!validIntfIP(ip))
161+
{
162+
throw std::invalid_argument("Invalid unicast");
163+
}
164+
gw = stdplus::toStr(ip);
165+
}
166+
catch (const std::exception& e)
167+
{
168+
lg2::error("Invalid Gateway `{GATEWAY}`: {ERROR}", "GATEWAY", gw,
169+
"ERROR", e);
170+
elog<InvalidArgument>(Argument::ARGUMENT_NAME("GATEWAY"),
171+
Argument::ARGUMENT_VALUE(gw.c_str()));
172+
}
173+
}
174+
175+
/** @brief set the default v6 gateway of the interface.
176+
* @param[in] gateway - default v6 gateway of the interface.
177+
*/
178+
std::string defaultGateway6(std::string gateway) override;
179+
using HypEthernetIntf::defaultGateway6;
84180

85181
/** Set value of DHCPEnabled */
86182
HypEthernetIntf::DHCPConf dhcpEnabled() const override;
@@ -100,20 +196,16 @@ class HypEthInterface : public CreateIface
100196

101197
protected:
102198
/** @brief sdbusplus DBus bus connection. */
103-
sdbusplus::bus_t& bus;
199+
stdplus::PinnedRef<sdbusplus::bus_t> bus;
104200

105201
/** @brief object path */
106-
std::string objectPath;
202+
sdbusplus::message::object_path objectPath;
107203

108204
/** @brief Parent of this object */
109-
HypNetworkMgr& manager;
205+
stdplus::PinnedRef<HypNetworkMgr> manager;
110206

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);
207+
/** @brief List of the ipaddress and the ip dbus objects */
208+
ipAddrMapType addrs;
117209
};
118210

119211
} // namespace network

0 commit comments

Comments
 (0)