network_manager: Allow direct access to interfaces
Change-Id: I3dc2bb944b8d3a7873e26ce2958a2cb1d9be95af
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/dhcp_configuration.cpp b/src/dhcp_configuration.cpp
index 6c96206..c14f547 100644
--- a/src/dhcp_configuration.cpp
+++ b/src/dhcp_configuration.cpp
@@ -26,7 +26,7 @@
{
config::Parser conf;
{
- auto interfaceStrList = getInterfaces();
+ auto interfaceStrList = getSystemInterfaces();
if (!interfaceStrList.empty())
{
conf.setFile(config::pathForIntfConf(manager.getConfDir(),
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index bba2ca2..eecbe68 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -55,7 +55,7 @@
auto isCreated = false;
try
{
- auto interfaceStrList = getInterfaces();
+ auto interfaceStrList = getSystemInterfaces();
for (const auto& interface : interfaceStrList)
{
// if the interface has '.' in the name, it means that this is a
@@ -106,7 +106,7 @@
// clear all the interfaces first
interfaces.clear();
- auto interfaceStrList = getInterfaces();
+ auto interfaceStrList = getSystemInterfaces();
for (auto& interface : interfaceStrList)
{
@@ -181,13 +181,6 @@
ObjectPath Manager::vlan(std::string interfaceName, uint32_t id)
{
- if (!hasInterface(interfaceName))
- {
- using ResourceErr =
- phosphor::logging::xyz::openbmc_project::Common::ResourceNotFound;
- elog<ResourceNotFound>(ResourceErr::RESOURCE(interfaceName.c_str()));
- }
-
if (id == 0 || id >= 4095)
{
log<level::ERR>("VLAN ID is not valid", entry("VLANID=%u", id));
@@ -196,7 +189,14 @@
Argument::ARGUMENT_VALUE(std::to_string(id).c_str()));
}
- return interfaces[interfaceName]->createVLAN(id);
+ auto it = interfaces.find(interfaceName);
+ if (it == interfaces.end())
+ {
+ using ResourceErr =
+ phosphor::logging::xyz::openbmc_project::Common::ResourceNotFound;
+ elog<ResourceNotFound>(ResourceErr::RESOURCE(interfaceName.c_str()));
+ }
+ return it->second->createVLAN(id);
}
void Manager::reset()
diff --git a/src/network_manager.hpp b/src/network_manager.hpp
index 89d909a..edd7125 100644
--- a/src/network_manager.hpp
+++ b/src/network_manager.hpp
@@ -129,23 +129,13 @@
*/
void doReloadConfigs();
- /** @brief Returns the number of interfaces under this manager.
+ /** @brief Get the interfaces owned by the manager
*
- * @return the number of interfaces managed by this manager.
+ * @return Interfaces reference.
*/
- inline size_t getInterfaceCount()
+ inline const auto& getInterfaces() const
{
- return interfaces.size();
- }
-
- /** @brief Does the requested interface exist under this manager?
- *
- * @param[in] intf - the interface name to check.
- * @return true if found, false otherwise.
- */
- inline bool hasInterface(std::string_view intf)
- {
- return interfaces.find(intf) != interfaces.end();
+ return interfaces;
}
/** @brief Get the routing table owned by the manager
diff --git a/src/types.hpp b/src/types.hpp
index 5465381..58ad04a 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -52,8 +52,6 @@
// Byte representations for common address types in network byte order
using InAddrAny = std::variant<struct in_addr, struct in6_addr>;
-using InterfaceList = std::unordered_set<std::string>;
-
using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
struct string_hash : public std::hash<std::string_view>
@@ -63,6 +61,8 @@
template <typename V>
using string_umap =
std::unordered_map<std::string, V, string_hash, std::equal_to<>>;
+using string_uset =
+ std::unordered_set<std::string, string_hash, std::equal_to<>>;
} // namespace network
} // namespace phosphor
diff --git a/src/util.cpp b/src/util.cpp
index b1f4d39..9d58bcb 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -200,9 +200,9 @@
[=]<int f>() noexcept { return isValidPrefix<f>(prefix); }, family);
}
-InterfaceList getInterfaces()
+string_uset getSystemInterfaces()
{
- InterfaceList interfaces{};
+ string_uset interfaces;
struct ifaddrs* ifaddr = nullptr;
// attempt to fill struct with ifaddrs
diff --git a/src/util.hpp b/src/util.hpp
index 16dca64..ddc5454 100644
--- a/src/util.hpp
+++ b/src/util.hpp
@@ -148,7 +148,7 @@
/** @brief Get all the interfaces from the system.
* @returns list of interface names.
*/
-InterfaceList getInterfaces();
+string_uset getSystemInterfaces();
/** @brief Delete the given interface.
* @param[in] intf - interface name.