Skip to content

Commit

Permalink
Add support for IPv6 on hypervisor eth interfaces (openbmc#61)
Browse files Browse the repository at this point in the history
This commit adds support for ipv6 addresses on the hypervisor
ethernet interfaces. It includes the following changes:
[1] https://gerrit.openbmc.org/c/openbmc/phosphor-networkd/+/54393
[2] ibm-openbmc#46

Tested By:

[1] PATCH -d '{"DHCPv4": {"DHCPEnabled":false}}' https://${bmc}/redfish/v1/Systems/hypervisor/EthernetInterfaces/eth1
[2] PATCH -d '{"DHCPv4": {"DHCPEnabled":true}}' https://${bmc}/redfish/v1/Systems/hypervisor/EthernetInterfaces/eth1
[3] PATCH -d '{"DHCPv6": {"OperatingMode":"Enabled"}}' https://${bmc}/redfish/v1/Systems/hypervisor/EthernetInterfaces/eth1
[4] PATCH -d '{"DHCPv6": {"OperatingMode":"Disabled"}}' https://${bmc}/redfish/v1/Systems/hypervisor/EthernetInterfaces/eth1
[5] PATCH -d '{"IPv4StaticAddresses": [{"Address": "<>","SubnetMask": "<>","Gateway":"<>"}]}' https://${bmc}/redfish/v1/Systems/hypervisor/EthernetInterfaces/eth1

Signed-off-by: Asmitha Karunanithi <[email protected]>
  • Loading branch information
asmithakarun authored Mar 3, 2023
1 parent 63af40a commit c9d1813
Show file tree
Hide file tree
Showing 7 changed files with 595 additions and 197 deletions.
646 changes: 480 additions & 166 deletions src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.cpp

Large diffs are not rendered by default.

103 changes: 84 additions & 19 deletions src/ibm/hypervisor-network-mgr-src/hyp_ip_interface.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "hyp_ip_interface.hpp"

#include "util.hpp"

#include <phosphor-logging/elog-errors.hpp>
Expand Down Expand Up @@ -176,34 +177,63 @@ void HypIPAddress::resetIPObjProps()
// Reset the ip obj properties
log<level::INFO>("Resetting the ip addr object properties");

std::string zeroIp = "0.0.0.0";
HypIP::address(zeroIp);
HypIP::gateway(zeroIp);
HypIP::prefixLength(0);
std::string defaultIp;
uint8_t defaultPrefixLen = 0;
std::string defaultMethod;
if (HypIP::type() == HypIP::Protocol::IPv4)
{
defaultIp = "0.0.0.0";
defaultMethod = "IPv4Static";
}
else if (HypIP::type() == HypIP::Protocol::IPv6)
{
defaultIp = "::";
defaultPrefixLen = 128;
defaultMethod = "IPv6Static";
}
HypIP::address(defaultIp);
HypIP::gateway(defaultIp);
HypIP::prefixLength(defaultPrefixLen);
HypIP::origin(IP::AddressOrigin::Static);

std::string prefix = getHypPrefix();

std::string attrIpaddr = prefix + "ipaddr";
parent.setIpPropsInMap(attrIpaddr, zeroIp, "String");

std::string attrPrefixLen = prefix + "prefix_length";
parent.setIpPropsInMap(attrPrefixLen, 0, "Integer");
parent.setIpPropsInMap(attrIpaddr, defaultIp, "String");

std::string attrGateway = prefix + "gateway";
parent.setIpPropsInMap(attrGateway, zeroIp, "String");
parent.setIpPropsInMap(attrGateway, defaultIp, "String");

std::string attrPrefixLen = prefix + "prefix_length";
parent.setIpPropsInMap(attrPrefixLen, defaultPrefixLen, "Integer");

std::string attrMethod = prefix + "method";
parent.setIpPropsInMap(attrMethod, "IPv4Static", "String");
parent.setIpPropsInMap(attrMethod, defaultMethod, "String");
}

void HypIPAddress::resetBaseBiosTableAttrs()
void HypIPAddress::resetBaseBiosTableAttrs(std::string protocol)
{
// clear all the entries
log<level::INFO>("Resetting the bios table attrs of the ip object");
updateBaseBiosTable(mapDbusToBiosAttr("address"), "0.0.0.0");
updateBaseBiosTable(mapDbusToBiosAttr("gateway"), "0.0.0.0");
updateBaseBiosTable(mapDbusToBiosAttr("prefixLength"), 0);

if (protocol.empty())
{
protocol = convertProtocolToString(HypIP::type());
protocol = protocol.substr(protocol.rfind(".") + 1);
}

if (protocol == "IPv4")
{
updateBaseBiosTable(mapDbusToBiosAttr("address"), "0.0.0.0");
updateBaseBiosTable(mapDbusToBiosAttr("gateway"), "0.0.0.0");
updateBaseBiosTable(mapDbusToBiosAttr("prefixLength"), 0);
}
if (protocol == "IPv6")
{
updateBaseBiosTable(mapDbusToBiosAttr("address"), "::");
updateBaseBiosTable(mapDbusToBiosAttr("gateway"), "::");
updateBaseBiosTable(mapDbusToBiosAttr("prefixLength"), 128);
}
}

InAddrAny HypIPAddress::getIpAddress(std::string ip)
Expand Down Expand Up @@ -373,21 +403,49 @@ HypIP::AddressOrigin HypIPAddress::origin(HypIP::AddressOrigin origin)
std::string originBiosAttr;
if (originStr.substr(originStr.rfind(".") + 1) == "Static")
{
originBiosAttr = "IPv4Static";
if (HypIP::type() == HypIP::Protocol::IPv4)
{
originBiosAttr = "IPv4Static";
}
else if (HypIP::type() == HypIP::Protocol::IPv6)
{
originBiosAttr = "IPv6Static";
}
}
else if (originStr.substr(originStr.rfind(".") + 1) == "DHCP")
{
originBiosAttr = "IPv4DHCP";
if (HypIP::type() == HypIP::Protocol::IPv4)
{
originBiosAttr = "IPv4DHCP";
}
else if (HypIP::type() == HypIP::Protocol::IPv6)
{
originBiosAttr = "IPv6DHCP";
}
}

std::string currOriginValue;
if (addrOrigin == HypIP::AddressOrigin::Static)
{
currOriginValue = "IPv4Static";
if (HypIP::type() == HypIP::Protocol::IPv4)
{
currOriginValue = "IPv4Static";
}
else if (HypIP::type() == HypIP::Protocol::IPv6)
{
currOriginValue = "IPv6Static";
}
}
else if (addrOrigin == HypIP::AddressOrigin::DHCP)
{
currOriginValue = "IPv4DHCP";
if (HypIP::type() == HypIP::Protocol::IPv4)
{
currOriginValue = "IPv4DHCP";
}
else if (HypIP::type() == HypIP::Protocol::IPv6)
{
currOriginValue = "IPv6DHCP";
}
}

origin = HypIP::origin(origin);
Expand Down Expand Up @@ -422,7 +480,14 @@ void HypIPAddress::delete_()
resetIPObjProps();

// update bios table attrs to default
resetBaseBiosTableAttrs();
if (HypIP::type() == HypIP::Protocol::IPv4)
{
resetBaseBiosTableAttrs("IPv4");
}
if (HypIP::type() == HypIP::Protocol::IPv6)
{
resetBaseBiosTableAttrs("IPv6");
}
}

} // namespace network
Expand Down
5 changes: 3 additions & 2 deletions src/ibm/hypervisor-network-mgr-src/hyp_ip_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class HypIPAddress : public HypIPIfaces
/** @brief Method that maps the dbus object's properties
* with properties of the bios table.
* @param[in] dbusProp - dbus property name
* @result bios table property equivalent to the dbus property.
* @result bios table property equivalent to the dbus property.
*/
std::string mapDbusToBiosAttr(std::string dbusProp);

Expand All @@ -105,8 +105,9 @@ class HypIPAddress : public HypIPIfaces
void resetIPObjProps();

/** @brief Method to reset the base bios table attributes
* @param[in] protocol - IPv4/IPv6
*/
void resetBaseBiosTableAttrs();
void resetBaseBiosTableAttrs(std::string protocol);

/** @brief Method to set the enabled prop onto dbus from the
* persisted file whenever the service starts
Expand Down
21 changes: 16 additions & 5 deletions src/ibm/hypervisor-network-mgr-src/hyp_network_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,23 @@ void HypNetworkMgr::setBIOSTableAttr(
}
}

void HypNetworkMgr::setDefaultBIOSTableAttrsOnIntf(const std::string& intf)
void HypNetworkMgr::setDefaultBIOSTableAttrsOnIntf(const std::string& intf,
const std::string& protocol)
{
biosTableAttrs.emplace("vmi_" + intf + "_ipv4_ipaddr", "0.0.0.0");
biosTableAttrs.emplace("vmi_" + intf + "_ipv4_gateway", "0.0.0.0");
biosTableAttrs.emplace("vmi_" + intf + "_ipv4_prefix_length", 0);
biosTableAttrs.emplace("vmi_" + intf + "_ipv4_method", "IPv4Static");
if (protocol == "ipv4")
{
biosTableAttrs.emplace("vmi_" + intf + "_ipv4_ipaddr", "0.0.0.0");
biosTableAttrs.emplace("vmi_" + intf + "_ipv4_gateway", "0.0.0.0");
biosTableAttrs.emplace("vmi_" + intf + "_ipv4_prefix_length", 0);
biosTableAttrs.emplace("vmi_" + intf + "_ipv4_method", "IPv4Static");
}
else if (protocol == "ipv6")
{
biosTableAttrs.emplace("vmi_" + intf + "_ipv6_ipaddr", "::");
biosTableAttrs.emplace("vmi_" + intf + "_ipv6_gateway", "::");
biosTableAttrs.emplace("vmi_" + intf + "_ipv6_prefix_length", 128);
biosTableAttrs.emplace("vmi_" + intf + "_ipv6_method", "IPv6Static");
}
}

void HypNetworkMgr::setDefaultHostnameInBIOSTableAttrs()
Expand Down
5 changes: 4 additions & 1 deletion src/ibm/hypervisor-network-mgr-src/hyp_network_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ class HypNetworkMgr

/** @brief Method to set all the interface 0 attributes
* to its default value in biosTableAttrs data member
* @param[in] intf - interface if0/1
* @param[in] protocol - ipv4/ipv6
*/
void setDefaultBIOSTableAttrsOnIntf(const std::string& intf);
void setDefaultBIOSTableAttrsOnIntf(const std::string& intf,
const std::string& protocol);

/** @brief Method to set the hostname attribute
* to its default value in biosTableAttrs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class TestHypEthernetInterface : public testing::Test
manager(bus, "/xyz/openbmc_test/network/hypervisor"),
interface(makeInterface(bus, manager))
{
manager.setDefaultBIOSTableAttrsOnIntf("if0");
manager.setDefaultBIOSTableAttrsOnIntf("if1");
manager.setDefaultBIOSTableAttrsOnIntf("if0", "ipv4");
manager.setDefaultBIOSTableAttrsOnIntf("if0", "ipv6");
manager.setDefaultBIOSTableAttrsOnIntf("if1", "ipv4");
manager.setDefaultBIOSTableAttrsOnIntf("if1", "ipv6");
manager.setDefaultHostnameInBIOSTableAttrs();
interface.createIPAddrObj();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ class TestHypNetworkManager : public testing::Test
// method call to set default values in the local copy
// of the bios attributes should be called for ipv6 as well

manager.setDefaultBIOSTableAttrsOnIntf("if0");
manager.setDefaultBIOSTableAttrsOnIntf("if1");
manager.setDefaultBIOSTableAttrsOnIntf("if0", "ipv4");
manager.setDefaultBIOSTableAttrsOnIntf("if0", "ipv6");
manager.setDefaultBIOSTableAttrsOnIntf("if1", "ipv4");
manager.setDefaultBIOSTableAttrsOnIntf("if1", "ipv6");
manager.setDefaultHostnameInBIOSTableAttrs();
}

Expand Down

0 comments on commit c9d1813

Please sign in to comment.