Add two MAC addresses support for Mihawk's 2 NICs
In somes systms, there are 2 MAC addresses for 2 NICs like mihawk. In
order to support system like Mihawk, check the object path of
NetworkInterface to find the corresponding object of NIC.
Tested: Get the 2 MAC addresses of eth0 and eth1 from inventory
Signed-off-by: Alvin Wang <alvinwang@msn.com>
Change-Id: I2ee08c020010bccd7e46b94d69f5fd80a639aef7
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index 8781494..9dcba8e 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -786,7 +786,8 @@
{
try
{
- auto inventoryMAC = mac_address::getfromInventory(bus);
+ auto inventoryMAC =
+ mac_address::getfromInventory(bus, interfaceName());
if (!equal(newMAC, inventoryMAC))
{
log<level::ERR>(
diff --git a/util.cpp b/util.cpp
index f1fd4cd..afbc229 100644
--- a/util.cpp
+++ b/util.cpp
@@ -519,7 +519,8 @@
"xyz.openbmc_project.Inventory.Item.NetworkInterface";
constexpr auto invRoot = "/xyz/openbmc_project/inventory";
-ether_addr getfromInventory(sdbusplus::bus::bus& bus)
+ether_addr getfromInventory(sdbusplus::bus::bus& bus,
+ const std::string& intfName)
{
std::vector<DbusInterface> interfaces;
interfaces.emplace_back(invNetworkIntf);
@@ -548,10 +549,37 @@
elog<InternalFailure>();
}
- // It is expected that only one object has implemented this interface.
+ DbusObjectPath objPath;
+ DbusService service;
- auto objPath = objectTree.begin()->first;
- auto service = objectTree.begin()->second.begin()->first;
+ if (1 == objectTree.size())
+ {
+ objPath = objectTree.begin()->first;
+ service = objectTree.begin()->second.begin()->first;
+ }
+ else
+ {
+ // If there are more than 2 objects, object path must contain the
+ // interface name
+ for (auto const& object : objectTree)
+ {
+ log<level::INFO>("interface", entry("INT=%s", intfName.c_str()));
+ log<level::INFO>("object", entry("OBJ=%s", object.first.c_str()));
+ if (std::string::npos != object.first.find(intfName))
+ {
+ objPath = object.first;
+ service = object.second.begin()->first;
+ break;
+ }
+ }
+
+ if (objPath.empty())
+ {
+ log<level::ERR>("Can't find the object for the interface",
+ entry("intfName=%s", intfName.c_str()));
+ elog<InternalFailure>();
+ }
+ }
auto method = bus.new_method_call(service.c_str(), objPath.c_str(),
propIntf, methodGet);
diff --git a/util.hpp b/util.hpp
index 3aad4a1..251aa0d 100644
--- a/util.hpp
+++ b/util.hpp
@@ -2,6 +2,7 @@
#include "config.h"
+#include "ethernet_interface.hpp"
#include "types.hpp"
#include <netinet/ether.h>
@@ -29,8 +30,10 @@
/** @brief gets the MAC address from the Inventory.
* @param[in] bus - DBUS Bus Object.
+ * @param[in] intfName - Interface name
*/
-ether_addr getfromInventory(sdbusplus::bus::bus& bus);
+ether_addr getfromInventory(sdbusplus::bus::bus& bus,
+ const std::string& intfName);
/** @brief Converts the given mac address into byte form
* @param[in] str - The mac address in human readable form