ethernet_interface: Migrate object creation from network_manager
Change-Id: I861a7e7484b33bfc94fc30ff17fa27fca2b95bfa
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 8476136..e3e7662 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -70,24 +70,25 @@
}
EthernetInterface::EthernetInterface(sdbusplus::bus_t& bus, Manager& manager,
- const InterfaceInfo& info,
+ const AllIntfInfo& info,
std::string_view objRoot,
const config::Parser& config,
bool enabled) :
- EthernetInterface(bus, manager, info, makeObjPath(objRoot, *info.name),
+ EthernetInterface(bus, manager, info, makeObjPath(objRoot, *info.intf.name),
config, enabled)
{
}
EthernetInterface::EthernetInterface(sdbusplus::bus_t& bus, Manager& manager,
- const InterfaceInfo& info,
+ const AllIntfInfo& info,
std::string&& objPath,
const config::Parser& config,
bool enabled) :
Ifaces(bus, objPath.c_str(), Ifaces::action::defer_emit),
- manager(manager), bus(bus), objPath(std::move(objPath)), ifIdx(info.idx)
+ manager(manager), bus(bus), objPath(std::move(objPath)),
+ ifIdx(info.intf.idx)
{
- interfaceName(*info.name);
+ interfaceName(*info.intf.name);
auto dhcpVal = getDHCPValue(config);
EthernetInterfaceIntf::dhcp4(dhcpVal.v4);
EthernetInterfaceIntf::dhcp6(dhcpVal.v6);
@@ -97,15 +98,31 @@
EthernetInterfaceIntf::ntpServers(
config.map.getValueStrings("Network", "NTP"));
- updateInfo(info);
+ updateInfo(info.intf);
- if (info.vlan_id)
+ if (info.intf.vlan_id)
{
- if (!info.parent_idx)
+ if (!info.intf.parent_idx)
{
std::runtime_error("Missing parent link");
}
- vlan.emplace(bus, this->objPath.c_str(), info, *this);
+ vlan.emplace(bus, this->objPath.c_str(), info.intf, *this);
+ }
+ if (info.defgw4)
+ {
+ EthernetInterface::defaultGateway(std::to_string(*info.defgw4));
+ }
+ if (info.defgw6)
+ {
+ EthernetInterface::defaultGateway6(std::to_string(*info.defgw6));
+ }
+ for (const auto& [_, addr] : info.addrs)
+ {
+ addAddr(addr);
+ }
+ for (const auto& [_, neigh] : info.staticNeighs)
+ {
+ addStaticNeigh(neigh);
}
this->emit_object_added();
@@ -540,7 +557,7 @@
{
mac.emplace(ToAddr<ether_addr>{}(macStr));
}
- auto info = InterfaceInfo{
+ auto info = AllIntfInfo{InterfaceInfo{
.idx = 0, // TODO: Query the correct value after creation
.flags = 0,
.name = intfName,
@@ -548,7 +565,7 @@
.mtu = mtu(),
.parent_idx = ifIdx,
.vlan_id = id,
- };
+ }};
// Pass the parents nicEnabled property, so that the child
// VLAN interface can inherit.
diff --git a/src/ethernet_interface.hpp b/src/ethernet_interface.hpp
index 2ef2f95..e617eae 100644
--- a/src/ethernet_interface.hpp
+++ b/src/ethernet_interface.hpp
@@ -80,7 +80,7 @@
* @param[in] enabled - Determine if systemd-networkd is managing this link
*/
EthernetInterface(sdbusplus::bus_t& bus, Manager& manager,
- const InterfaceInfo& info, std::string_view objRoot,
+ const AllIntfInfo& info, std::string_view objRoot,
const config::Parser& config, bool enabled);
/** @brief Network Manager object. */
@@ -243,7 +243,7 @@
private:
EthernetInterface(sdbusplus::bus_t& bus, Manager& manager,
- const InterfaceInfo& info, std::string&& objPath,
+ const AllIntfInfo& info, std::string&& objPath,
const config::Parser& config, bool enabled);
/** @brief Determines if the address is manually assigned
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index 135c002..f999f31 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -142,23 +142,7 @@
}
config::Parser config(config::pathForIntfConf(confDir, *info.intf.name));
auto intf = std::make_unique<EthernetInterface>(
- bus, *this, info.intf, objPath.str, config, enabled);
- if (info.defgw4)
- {
- intf->EthernetInterface::defaultGateway(std::to_string(*info.defgw4));
- }
- if (info.defgw6)
- {
- intf->EthernetInterface::defaultGateway6(std::to_string(*info.defgw6));
- }
- for (const auto& [_, addr] : info.addrs)
- {
- intf->addAddr(addr);
- }
- for (const auto& [_, neigh] : info.staticNeighs)
- {
- intf->addStaticNeigh(neigh);
- }
+ bus, *this, info, objPath.str, config, enabled);
intf->loadNameServers(config);
intf->loadNTPServers(config);
auto ptr = intf.get();
diff --git a/src/network_manager.hpp b/src/network_manager.hpp
index 049a000..98bbd41 100644
--- a/src/network_manager.hpp
+++ b/src/network_manager.hpp
@@ -147,14 +147,6 @@
std::filesystem::path confDir;
/** @brief Map of interface info for undiscovered interfaces */
- struct AllIntfInfo
- {
- InterfaceInfo intf;
- std::optional<in_addr> defgw4 = std::nullopt;
- std::optional<in6_addr> defgw6 = std::nullopt;
- std::unordered_map<IfAddr, AddressInfo> addrs = {};
- std::unordered_map<InAddrAny, NeighborInfo> staticNeighs = {};
- };
std::unordered_map<unsigned, AllIntfInfo> intfInfo;
std::unordered_set<unsigned> ignoredIntf;
diff --git a/src/types.hpp b/src/types.hpp
index badc977..f426f81 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -851,3 +851,18 @@
phosphor::network::detail::ToStrBuf<phosphor::network::IfAddr> tsb;
return os << tsb(v);
}
+
+namespace phosphor::network
+{
+
+/** @brief Contains all of the object information about the interface */
+struct AllIntfInfo
+{
+ InterfaceInfo intf;
+ std::optional<in_addr> defgw4 = std::nullopt;
+ std::optional<in6_addr> defgw6 = std::nullopt;
+ std::unordered_map<IfAddr, AddressInfo> addrs = {};
+ std::unordered_map<InAddrAny, NeighborInfo> staticNeighs = {};
+};
+
+} // namespace phosphor::network
diff --git a/test/test_ethernet_interface.cpp b/test/test_ethernet_interface.cpp
index dd1a10d..2b52e4c 100644
--- a/test/test_ethernet_interface.cpp
+++ b/test/test_ethernet_interface.cpp
@@ -39,7 +39,7 @@
static MockEthernetInterface makeInterface(sdbusplus::bus_t& bus,
MockManager& manager)
{
- InterfaceInfo info{.idx = 1, .flags = 0, .name = "test0"};
+ AllIntfInfo info{InterfaceInfo{.idx = 1, .flags = 0, .name = "test0"}};
return {bus, manager, info, "/xyz/openbmc_test/network"sv,
config::Parser()};
}
@@ -71,11 +71,11 @@
constexpr ether_addr mac{0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
constexpr unsigned mtu = 150;
- InterfaceInfo info{.idx = 2,
- .flags = IFF_RUNNING,
- .name = "test1",
- .mac = mac,
- .mtu = mtu};
+ AllIntfInfo info{InterfaceInfo{.idx = 2,
+ .flags = IFF_RUNNING,
+ .name = "test1",
+ .mac = mac,
+ .mtu = mtu}};
MockEthernetInterface intf(bus, manager, info,
"/xyz/openbmc_test/network"sv, config::Parser());