treewide: Completely remove global refresh
We no longer need any of the global refresh code as we can dynamically
receive all of the updates to network configuration.
Change-Id: Ia8cb3af827c599c17d5df9fdddaf6cdc6546050d
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/dhcp_configuration.cpp b/src/dhcp_configuration.cpp
index 41c364b..d421111 100644
--- a/src/dhcp_configuration.cpp
+++ b/src/dhcp_configuration.cpp
@@ -66,7 +66,7 @@
auto name = ConfigIntf::sendHostNameEnabled(value);
manager.writeToConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
return name;
}
@@ -80,7 +80,7 @@
auto name = ConfigIntf::hostNameEnabled(value);
manager.writeToConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
return name;
}
@@ -94,7 +94,7 @@
auto ntp = ConfigIntf::ntpEnabled(value);
manager.writeToConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
return ntp;
}
@@ -108,7 +108,7 @@
auto dns = ConfigIntf::dnsEnabled(value);
manager.writeToConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
return dns;
}
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 67dd16b..e836268 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -95,22 +95,6 @@
EthernetInterfaceIntf::dhcp6(dhcpVal.v6);
EthernetInterfaceIntf::ipv6AcceptRA(getIPv6AcceptRA(config));
EthernetInterfaceIntf::nicEnabled(enabled);
- {
- const auto& gws = manager.getRouteTable().getDefaultGateway();
- auto it = gws.find(ifIdx);
- if (it != gws.end())
- {
- EthernetInterfaceIntf::defaultGateway(std::to_string(it->second));
- }
- }
- {
- const auto& gws = manager.getRouteTable().getDefaultGateway6();
- auto it = gws.find(ifIdx);
- if (it != gws.end())
- {
- EthernetInterfaceIntf::defaultGateway6(std::to_string(it->second));
- }
- }
EthernetInterfaceIntf::ntpServers(
config.map.getValueStrings("Network", "NTP"));
@@ -194,15 +178,6 @@
}
}
-void EthernetInterface::createIPAddressObjects()
-{
- addrs.clear();
- for (const auto& addr : system::getAddresses({.ifidx = ifIdx}))
- {
- manager.addAddress(addr);
- }
-}
-
void EthernetInterface::addStaticNeigh(const NeighborInfo& info)
{
if (!info.mac || !info.addr)
@@ -225,15 +200,6 @@
}
}
-void EthernetInterface::createStaticNeighborObjects()
-{
- staticNeighbors.clear();
- for (const auto& neighbor : system::getNeighbors({.ifidx = ifIdx}))
- {
- manager.addNeighbor(neighbor);
- }
-}
-
ObjectPath EthernetInterface::ip(IP::Protocol protType, std::string ipaddress,
uint8_t prefixLength, std::string)
{
@@ -281,7 +247,7 @@
ifaddr, IP::AddressOrigin::Static));
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
return it->second->getObjPath();
}
@@ -324,7 +290,7 @@
lladdr, Neighbor::State::Permanent));
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
return it->second->getObjPath();
}
@@ -334,7 +300,7 @@
if (ipv6AcceptRA() != EthernetInterfaceIntf::ipv6AcceptRA(value))
{
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
}
return value;
}
@@ -344,7 +310,7 @@
if (dhcp4() != EthernetInterfaceIntf::dhcp4(value))
{
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
}
return value;
}
@@ -354,7 +320,7 @@
if (dhcp6() != EthernetInterfaceIntf::dhcp6(value))
{
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
}
return value;
}
@@ -376,7 +342,7 @@
if (old4 != new4 || old6 != new6 || oldra != newra)
{
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
}
return value;
}
@@ -394,27 +360,6 @@
return ipv6AcceptRA() ? DHCPConf::v6stateless : DHCPConf::none;
}
-bool EthernetInterface::linkUp() const
-{
- if (ifIdx == 0)
- {
- return EthernetInterfaceIntf::linkUp();
- }
- return system::intfIsRunning(interfaceName());
-}
-
-size_t EthernetInterface::mtu() const
-{
- if (ifIdx == 0)
- {
- return EthernetInterfaceIntf::mtu();
- }
- const auto ifname = interfaceName();
- return ignoreError("GetMTU", ifname, std::nullopt,
- [&] { return system::getMTU(ifname); })
- .value_or(EthernetInterfaceIntf::mtu());
-}
-
size_t EthernetInterface::mtu(size_t value)
{
const size_t old = EthernetInterfaceIntf::mtu();
@@ -445,7 +390,7 @@
manager.addReloadPreHook(
[ifname = interfaceName()]() { system::setNICUp(ifname, false); });
}
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
return value;
}
@@ -472,7 +417,7 @@
EthernetInterfaceIntf::staticNameServers(value);
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
}
catch (const InternalFailure& e)
{
@@ -613,7 +558,7 @@
config.writeFile(config::pathForIntfDev(manager.getConfDir(), intfName));
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
return ret;
}
@@ -625,7 +570,7 @@
EthernetInterfaceIntf::staticNTPServers(value);
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
}
catch (InternalFailure& e)
{
@@ -742,18 +687,15 @@
{
auto& dhcp = config.map["DHCP"].emplace_back();
dhcp["ClientIdentifier"].emplace_back("mac");
- if (manager.getDHCPConf())
- {
- const auto& conf = *manager.getDHCPConf();
- auto dns_enabled = conf.dnsEnabled() ? "true" : "false";
- dhcp["UseDNS"].emplace_back(dns_enabled);
- dhcp["UseDomains"].emplace_back(dns_enabled);
- dhcp["UseNTP"].emplace_back(conf.ntpEnabled() ? "true" : "false");
- dhcp["UseHostname"].emplace_back(conf.hostNameEnabled() ? "true"
- : "false");
- dhcp["SendHostname"].emplace_back(
- conf.sendHostNameEnabled() ? "true" : "false");
- }
+ const auto& conf = manager.getDHCPConf();
+ auto dns_enabled = conf.dnsEnabled() ? "true" : "false";
+ dhcp["UseDNS"].emplace_back(dns_enabled);
+ dhcp["UseDomains"].emplace_back(dns_enabled);
+ dhcp["UseNTP"].emplace_back(conf.ntpEnabled() ? "true" : "false");
+ dhcp["UseHostname"].emplace_back(conf.hostNameEnabled() ? "true"
+ : "false");
+ dhcp["SendHostname"].emplace_back(conf.sendHostNameEnabled() ? "true"
+ : "false");
}
auto path = config::pathForIntfConf(manager.getConfDir(), interfaceName());
config.writeFile(path);
@@ -811,7 +753,7 @@
// The MAC and LLADDRs will only update if the NIC is already down
system::setNICUp(interface, false);
});
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
}
#ifdef HAVE_UBOOT_ENV
@@ -839,7 +781,7 @@
addrs.clear();
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
}
std::string EthernetInterface::defaultGateway(std::string gateway)
@@ -866,7 +808,7 @@
EthernetInterfaceIntf::defaultGateway(gateway);
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
return gateway;
}
@@ -895,7 +837,7 @@
EthernetInterfaceIntf::defaultGateway6(gateway);
writeConfigurationFile();
- manager.reloadConfigsNoRefresh();
+ manager.reloadConfigs();
return gateway;
}
diff --git a/src/ethernet_interface.hpp b/src/ethernet_interface.hpp
index a2fb409..f29efa2 100644
--- a/src/ethernet_interface.hpp
+++ b/src/ethernet_interface.hpp
@@ -124,16 +124,6 @@
*/
ObjectPath neighbor(std::string ipAddress, std::string macAddress) override;
- /* @brief creates the dbus object(IPaddres) given in the address list.
- * @param[in] addrs - address list for which dbus objects needs
- * to create.
- */
- void createIPAddressObjects();
-
- /* @brief creates the dbus object(Neighbor) given in the neighbor list.
- */
- void createStaticNeighborObjects();
-
/** Set value of DHCPEnabled */
DHCPConf dhcpEnabled() const override;
DHCPConf dhcpEnabled(DHCPConf value) override;
@@ -155,12 +145,6 @@
return std::visit([&](auto v) { return dhcpIsEnabled(v); }, addr);
}
- /** Retrieve Link State */
- bool linkUp() const override;
-
- /** Retrieve MTU Size */
- size_t mtu() const override;
-
/** Set size of MTU */
size_t mtu(size_t value) override;
diff --git a/src/ipaddress.cpp b/src/ipaddress.cpp
index b3ca3db..560129d 100644
--- a/src/ipaddress.cpp
+++ b/src/ipaddress.cpp
@@ -111,7 +111,7 @@
}
parent.writeConfigurationFile();
- parent.manager.reloadConfigsNoRefresh();
+ parent.manager.reloadConfigs();
}
} // namespace network
diff --git a/src/neighbor.cpp b/src/neighbor.cpp
index 58334b2..0f5140e 100644
--- a/src/neighbor.cpp
+++ b/src/neighbor.cpp
@@ -57,7 +57,7 @@
}
parent.writeConfigurationFile();
- parent.manager.reloadConfigsNoRefresh();
+ parent.manager.reloadConfigs();
}
using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index 2634e11..99bedaa 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -33,7 +33,6 @@
namespace network
{
-extern std::unique_ptr<Timer> refreshObjectTimer;
extern std::unique_ptr<Timer> reloadTimer;
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
@@ -46,10 +45,9 @@
"PropertiesChanged',arg0='org.freedesktop.network1.Link',";
Manager::Manager(sdbusplus::bus_t& bus, const char* objPath,
- const fs::path& confDir) :
- details::VLANCreateIface(bus, objPath,
- details::VLANCreateIface::action::defer_emit),
- bus(bus), objectPath(objPath),
+ const std::filesystem::path& confDir) :
+ ManagerIface(bus, objPath, ManagerIface::action::defer_emit),
+ bus(bus), objPath(std::string(objPath)), confDir(confDir),
systemdNetworkdEnabledMatch(
bus, enabledMatch, [&](sdbusplus::message_t& m) {
std::string intf;
@@ -82,7 +80,6 @@
}
})
{
- setConfDir(confDir);
std::vector<
std::tuple<int32_t, std::string, sdbusplus::message::object_path>>
links;
@@ -112,25 +109,29 @@
rsp.read(val);
handleAdminState(std::get<std::string>(val), ifidx);
}
-}
-void Manager::setConfDir(const fs::path& dir)
-{
- confDir = dir;
-
- if (!fs::exists(confDir))
- {
- if (!fs::create_directories(confDir))
- {
- log<level::ERR>("Unable to create the network conf dir",
- entry("DIR=%s", confDir.c_str()));
- elog<InternalFailure>();
- }
- }
+ std::filesystem::create_directories(confDir);
+ systemConf = std::make_unique<phosphor::network::SystemConfiguration>(
+ bus, (this->objPath / "config").str);
+ dhcpConf = std::make_unique<phosphor::network::dhcp::Configuration>(
+ bus, (this->objPath / "dhcp").str, *this);
}
void Manager::createInterface(const UndiscoveredInfo& info, bool enabled)
{
+ if (auto it = interfacesByIdx.find(info.intf.idx);
+ it != interfacesByIdx.end())
+ {
+ it->second->updateInfo(info.intf);
+ if (info.intf.name && *info.intf.name != it->second->interfaceName())
+ {
+ fmt::print(stderr, "Interface name change detected {} -> {}\n",
+ it->second->interfaceName(), *info.intf.name);
+ fflush(stderr);
+ std::abort();
+ }
+ return;
+ }
if (!info.intf.name)
{
auto msg = fmt::format("Can't create interface without name: {}",
@@ -138,12 +139,25 @@
log<level::ERR>(msg.c_str(), entry("IFIDX=%u", info.intf.idx));
return;
}
- removeInterface(info.intf);
config::Parser config(config::pathForIntfConf(confDir, *info.intf.name));
auto intf = std::make_unique<EthernetInterface>(
- bus, *this, info.intf, objectPath, config, true, enabled);
- intf->createIPAddressObjects();
- intf->createStaticNeighborObjects();
+ bus, *this, info.intf, objPath.str, config, true, 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);
+ }
intf->loadNameServers(config);
intf->loadNTPServers(config);
auto ptr = intf.get();
@@ -407,39 +421,6 @@
}
}
-void Manager::createInterfaces()
-{
- // clear all the interfaces first
- interfaces.clear();
- interfacesByIdx.clear();
- for (auto& info : system::getInterfaces())
- {
- addInterface(info);
- }
-}
-
-void Manager::createChildObjects()
-{
- routeTable.refresh();
-
- // creates the ethernet interface dbus object.
- createInterfaces();
-
- systemConf.reset(nullptr);
- dhcpConf.reset(nullptr);
-
- fs::path objPath = objectPath;
- objPath /= "config";
-
- // create the system conf object.
- systemConf = std::make_unique<phosphor::network::SystemConfiguration>(
- bus, objPath.string());
- // create the dhcp conf object.
- objPath /= "dhcp";
- dhcpConf = std::make_unique<phosphor::network::dhcp::Configuration>(
- bus, objPath.string(), *this);
-}
-
ObjectPath Manager::vlan(std::string interfaceName, uint32_t id)
{
if (id == 0 || id >= 4095)
@@ -462,14 +443,12 @@
void Manager::reset()
{
- if (fs::is_directory(confDir))
+ for (const auto& dirent : std::filesystem::directory_iterator(confDir))
{
- for (const auto& file : fs::directory_iterator(confDir))
- {
- fs::remove(file.path());
- }
+ std::error_code ec;
+ std::filesystem::remove(dirent.path(), ec);
}
- log<level::INFO>("Network Factory Reset queued.");
+ log<level::INFO>("Network data purged.");
}
// Need to merge the below function with the code which writes the
@@ -517,16 +496,9 @@
#endif
-void Manager::reloadConfigsNoRefresh()
-{
- reloadTimer->restartOnce(reloadTimeout);
-}
-
void Manager::reloadConfigs()
{
- reloadConfigsNoRefresh();
- // Ensure that the next refresh happens after reconfiguration
- refreshObjectTimer->setRemaining(reloadTimeout + refreshTimeout);
+ reloadTimer->restartOnce(reloadTimeout);
}
void Manager::doReloadConfigs()
@@ -556,11 +528,6 @@
entry("ERR=%s", ex.what()));
elog<InternalFailure>();
}
- // Ensure reconfiguration has enough time
- if (refreshObjectTimer->isEnabled())
- {
- refreshObjectTimer->setRemaining(refreshTimeout);
- }
}
void Manager::handleAdminState(std::string_view state, unsigned ifidx)
diff --git a/src/network_manager.hpp b/src/network_manager.hpp
index 74e4fb1..3f7a050 100644
--- a/src/network_manager.hpp
+++ b/src/network_manager.hpp
@@ -11,6 +11,7 @@
#include <memory>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/bus/match.hpp>
+#include <sdbusplus/message/native_types.hpp>
#include <string>
#include <string_view>
#include <vector>
@@ -21,26 +22,14 @@
namespace network
{
-using SystemConfPtr = std::unique_ptr<SystemConfiguration>;
-using DHCPConfPtr = std::unique_ptr<dhcp::Configuration>;
-
-namespace fs = std::filesystem;
-namespace details
-{
-
-template <typename T, typename U>
-using ServerObject = typename sdbusplus::server::object_t<T, U>;
-
-using VLANCreateIface = details::ServerObject<
+using ManagerIface = sdbusplus::server::object_t<
sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
-} // namespace details
-
/** @class Manager
* @brief OpenBMC network manager implementation.
*/
-class Manager : public details::VLANCreateIface
+class Manager : public ManagerIface
{
public:
Manager(const Manager&) = delete;
@@ -55,7 +44,7 @@
* @param[in] confDir - Network Configuration directory path.
*/
Manager(sdbusplus::bus_t& bus, const char* objPath,
- const fs::path& confDir);
+ const std::filesystem::path& confDir);
ObjectPath vlan(std::string interfaceName, uint32_t id) override;
@@ -79,24 +68,9 @@
void addDefGw(unsigned ifidx, InAddrAny addr);
void removeDefGw(unsigned ifidx, InAddrAny addr);
- /** @brief Fetch the interface and the ipaddress details
- * from the system and create the ethernet interraces
- * dbus object.
- */
- virtual void createInterfaces();
-
- /** @brief create child interface object and the system conf object.
- */
- void createChildObjects();
-
- /** @brief sets the network conf directory.
- * @param[in] dirName - Absolute path of the directory.
- */
- void setConfDir(const fs::path& dir);
-
/** @brief gets the network conf directory.
*/
- inline const fs::path& getConfDir() const
+ inline const auto& getConfDir() const
{
return confDir;
}
@@ -104,17 +78,17 @@
/** @brief gets the system conf object.
*
*/
- inline const SystemConfPtr& getSystemConf()
+ inline auto& getSystemConf()
{
- return systemConf;
+ return *systemConf;
}
/** @brief gets the dhcp conf object.
*
*/
- inline const DHCPConfPtr& getDHCPConf()
+ inline auto& getDHCPConf()
{
- return dhcpConf;
+ return *dhcpConf;
}
/** @brief This function gets the MAC address from the VPD and
@@ -134,7 +108,6 @@
/** @brief Arms a timer to tell systemd-network to reload all of the network
* configurations
*/
- virtual void reloadConfigsNoRefresh();
virtual void reloadConfigs();
/** @brief Tell systemd-network to reload all of the network configurations
@@ -146,15 +119,6 @@
string_umap<std::unique_ptr<EthernetInterface>> interfaces;
std::unordered_map<unsigned, EthernetInterface*> interfacesByIdx;
- /** @brief Get the routing table owned by the manager
- *
- * @return Routing table reference.
- */
- inline const auto& getRouteTable() const
- {
- return routeTable;
- }
-
/** @brief Adds a hook that runs immediately prior to reloading
*
* @param[in] hook - The hook to execute before reloading
@@ -172,19 +136,16 @@
void reset() override;
/** @brief Path of Object. */
- std::string objectPath;
+ sdbusplus::message::object_path objPath;
/** @brief pointer to system conf object. */
- SystemConfPtr systemConf = nullptr;
+ std::unique_ptr<SystemConfiguration> systemConf = nullptr;
/** @brief pointer to dhcp conf object. */
- DHCPConfPtr dhcpConf = nullptr;
+ std::unique_ptr<dhcp::Configuration> dhcpConf = nullptr;
/** @brief Network Configuration directory. */
- fs::path confDir;
-
- /** @brief The routing table */
- route::Table routeTable;
+ std::filesystem::path confDir;
/** @brief Map of interface info for undiscovered interfaces */
struct UndiscoveredInfo
diff --git a/src/network_manager_main.cpp b/src/network_manager_main.cpp
index ffd97df..15bc59f 100644
--- a/src/network_manager_main.cpp
+++ b/src/network_manager_main.cpp
@@ -52,7 +52,6 @@
{
std::unique_ptr<Manager> manager = nullptr;
-std::unique_ptr<Timer> refreshObjectTimer = nullptr;
std::unique_ptr<Timer> reloadTimer = nullptr;
#ifdef SYNC_MAC_FROM_INVENTORY
@@ -239,17 +238,6 @@
#endif
-/** @brief refresh the network objects. */
-void refreshObjects()
-{
- if (manager)
- {
- log<level::INFO>("Refreshing the objects.");
- manager->createChildObjects();
- log<level::INFO>("Refreshing complete.");
- }
-}
-
void reloadNetworkd()
{
if (manager)
@@ -262,8 +250,6 @@
void initializeTimers(sdeventplus::Event& event)
{
- refreshObjectTimer =
- std::make_unique<Timer>(event, std::bind(refreshObjects));
reloadTimer = std::make_unique<Timer>(event, std::bind(reloadNetworkd));
}
@@ -301,11 +287,6 @@
watchEthernetInterface(bus, configJson);
#endif
- // Trigger the initial object scan
- // This is intentionally deferred, to ensure that systemd-networkd is
- // fully configured.
- refreshObjectTimer->restartOnce(refreshTimeout);
-
return event.loop();
}
diff --git a/src/rtnetlink_server.cpp b/src/rtnetlink_server.cpp
index ffa123e..a4266b7 100644
--- a/src/rtnetlink_server.cpp
+++ b/src/rtnetlink_server.cpp
@@ -7,20 +7,11 @@
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
-#include <memory>
#include <phosphor-logging/log.hpp>
#include <stdplus/fd/create.hpp>
#include <stdplus/fd/ops.hpp>
-#include <string_view>
-namespace phosphor
-{
-namespace network
-{
-
-extern std::unique_ptr<Timer> refreshObjectTimer;
-
-namespace netlink
+namespace phosphor::network::netlink
{
using phosphor::logging::entry;
@@ -122,6 +113,4 @@
performRequest(NETLINK_ROUTE, RTM_GETNEIGH, NLM_F_DUMP, ndmsg{}, cb);
}
-} // namespace netlink
-} // namespace network
-} // namespace phosphor
+} // namespace phosphor::network::netlink
diff --git a/src/system_queries.cpp b/src/system_queries.cpp
index 894fc09..9a360bd 100644
--- a/src/system_queries.cpp
+++ b/src/system_queries.cpp
@@ -1,8 +1,5 @@
#include "system_queries.hpp"
-#include "netlink.hpp"
-#include "rtnetlink.hpp"
-
#include <fmt/format.h>
#include <linux/ethtool.h>
#include <linux/sockios.h>
@@ -13,10 +10,8 @@
#include <phosphor-logging/log.hpp>
#include <stdexcept>
#include <stdplus/fd/create.hpp>
-#include <stdplus/raw.hpp>
#include <stdplus/util/cexec.hpp>
#include <string_view>
-#include <system_error>
namespace phosphor::network::system
{
@@ -99,17 +94,6 @@
.value_or(EthInfo{});
}
-bool intfIsRunning(std::string_view ifname)
-{
- return executeIFReq(ifname, SIOCGIFFLAGS).ifr_flags & IFF_RUNNING;
-}
-
-std::optional<unsigned> getMTU(stdplus::zstring_view ifname)
-{
- return optionalIFReq(ifname, SIOCGIFMTU, "GMTU",
- [](const ifreq& ifr) { return ifr.ifr_mtu; });
-}
-
void setMTU(std::string_view ifname, unsigned mtu)
{
auto ifr = makeIFReq(ifname);
@@ -125,93 +109,4 @@
getIFSock().ioctl(SIOCSIFFLAGS, &ifr);
}
-bool detail::validateNewAddr(const AddressInfo& info,
- const AddressFilter& filter) noexcept
-{
- if (filter.ifidx != 0 && filter.ifidx != info.ifidx)
- {
- return false;
- }
- return true;
-}
-
-bool detail::validateNewNeigh(const NeighborInfo& info,
- const NeighborFilter& filter) noexcept
-{
- if (filter.ifidx != 0 && filter.ifidx != info.ifidx)
- {
- return false;
- }
- return true;
-}
-
-std::vector<InterfaceInfo> getInterfaces()
-{
- std::vector<InterfaceInfo> ret;
- auto cb = [&](const nlmsghdr&, std::string_view msg) {
- try
- {
- ret.emplace_back(netlink::intfFromRtm(msg));
- }
- catch (const std::exception& e)
- {
- auto msg = fmt::format("Failed parsing interface: {}", e.what());
- log<level::ERR>(msg.c_str());
- }
- };
- ifinfomsg msg{};
- netlink::performRequest(NETLINK_ROUTE, RTM_GETLINK, NLM_F_DUMP, msg, cb);
- return ret;
-}
-
-std::vector<AddressInfo> getAddresses(const AddressFilter& filter)
-{
- std::vector<AddressInfo> ret;
- auto cb = [&](const nlmsghdr&, std::string_view msg) {
- try
- {
- auto info = netlink::addrFromRtm(msg);
- if (detail::validateNewAddr(info, filter))
- {
- ret.emplace_back(std::move(info));
- }
- }
- catch (const std::exception& e)
- {
- auto msg = fmt::format("Failed parsing address for ifidx {}: {}",
- filter.ifidx, e.what());
- log<level::ERR>(msg.c_str());
- }
- };
- ifaddrmsg msg{};
- msg.ifa_index = filter.ifidx;
- netlink::performRequest(NETLINK_ROUTE, RTM_GETADDR, NLM_F_DUMP, msg, cb);
- return ret;
-}
-
-std::vector<NeighborInfo> getNeighbors(const NeighborFilter& filter)
-{
- std::vector<NeighborInfo> ret;
- auto cb = [&](const nlmsghdr&, std::string_view msg) {
- try
- {
- auto info = netlink::neighFromRtm(msg);
- if (detail::validateNewNeigh(info, filter))
- {
- ret.push_back(std::move(info));
- }
- }
- catch (const std::exception& e)
- {
- auto msg = fmt::format("Failed parsing neighbor for ifidx {}: {}",
- filter.ifidx, e.what());
- log<level::ERR>(msg.c_str());
- }
- };
- ndmsg msg{};
- msg.ndm_ifindex = filter.ifidx;
- netlink::performRequest(NETLINK_ROUTE, RTM_GETNEIGH, NLM_F_DUMP, msg, cb);
- return ret;
-}
-
} // namespace phosphor::network::system
diff --git a/src/system_queries.hpp b/src/system_queries.hpp
index 7785c39..4c187c7 100644
--- a/src/system_queries.hpp
+++ b/src/system_queries.hpp
@@ -1,17 +1,9 @@
#pragma once
#include "types.hpp"
-#include <net/ethernet.h>
-
#include <cstdint>
-#include <optional>
-#include <stdplus/zstring.hpp>
#include <stdplus/zstring_view.hpp>
-#include <string>
#include <string_view>
-#include <vector>
-
-struct nlmsghdr;
namespace phosphor::network::system
{
@@ -22,44 +14,8 @@
};
EthInfo getEthInfo(stdplus::zstring_view ifname);
-bool intfIsRunning(std::string_view ifname);
-
-std::optional<unsigned> getMTU(stdplus::zstring_view ifname);
-
void setMTU(std::string_view ifname, unsigned mtu);
void setNICUp(std::string_view ifname, bool up);
-struct AddressFilter
-{
- unsigned ifidx = 0;
-};
-
-struct NeighborFilter
-{
- unsigned ifidx = 0;
-};
-
-namespace detail
-{
-bool validateNewAddr(const AddressInfo& info,
- const AddressFilter& filter) noexcept;
-bool validateNewNeigh(const NeighborInfo& info,
- const NeighborFilter& filter) noexcept;
-} // namespace detail
-
-/** @brief Get all the interfaces from the system.
- * @returns list of interface names.
- */
-std::vector<InterfaceInfo> getInterfaces();
-
-/** @brief Get all the addreses from the system.
- * @returns list of addresses
- */
-std::vector<AddressInfo> getAddresses(const AddressFilter& filter);
-
-/** @brief Returns a list of system neighbor table
- */
-std::vector<NeighborInfo> getNeighbors(const NeighborFilter& filter);
-
} // namespace phosphor::network::system
diff --git a/src/types.hpp b/src/types.hpp
index 709874c..badc977 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -42,10 +42,6 @@
// wait for three seconds before reloading systemd-networkd
constexpr auto reloadTimeout = 3s;
-// refresh the objets after four seconds as network
-// configuration takes 3-4 sec to reconfigure at most.
-constexpr auto refreshTimeout = 4s;
-
// Byte representations for common address types in network byte order
using InAddrAny = std::variant<in_addr, in6_addr>;
class IfAddr
diff --git a/test/global_network_objects.cpp b/test/global_network_objects.cpp
index 0f6550f..9442546 100644
--- a/test/global_network_objects.cpp
+++ b/test/global_network_objects.cpp
@@ -1,8 +1,6 @@
#include "mock_network_manager.hpp"
#include "types.hpp"
-#include <sdeventplus/event.hpp>
-
namespace phosphor
{
@@ -10,23 +8,7 @@
{
std::unique_ptr<MockManager> manager = nullptr;
-std::unique_ptr<Timer> refreshObjectTimer = nullptr;
std::unique_ptr<Timer> reloadTimer = nullptr;
-/** @brief refresh the network objects. */
-void refreshObjects()
-{
- if (manager)
- {
- manager->createChildObjects();
- }
-}
-
-void initializeTimers()
-{
- refreshObjectTimer = std::make_unique<Timer>(
- sdeventplus::Event::get_default(), std::bind(refreshObjects));
-}
-
} // namespace network
} // namespace phosphor
diff --git a/test/meson.build b/test/meson.build
index 1b96586..0e580fd 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -49,7 +49,6 @@
'netlink',
'network_manager',
'rtnetlink',
- 'system_queries',
'types',
'util',
]
diff --git a/test/mock_ethernet_interface.hpp b/test/mock_ethernet_interface.hpp
index 1f72486..ff1b324 100644
--- a/test/mock_ethernet_interface.hpp
+++ b/test/mock_ethernet_interface.hpp
@@ -17,8 +17,8 @@
{
}
+ MOCK_METHOD((ServerList), getNTPServerFromTimeSyncd, (), (override));
MOCK_METHOD((ServerList), getNameServerFromResolvd, (), (override));
- friend class TestEthernetInterface;
};
} // namespace network
} // namespace phosphor
diff --git a/test/mock_network_manager.hpp b/test/mock_network_manager.hpp
index fd344bf..87214d4 100644
--- a/test/mock_network_manager.hpp
+++ b/test/mock_network_manager.hpp
@@ -1,8 +1,5 @@
#pragma once
-#include "config_parser.hpp"
-#include "mock_ethernet_interface.hpp"
#include "network_manager.hpp"
-#include "system_queries.hpp"
#include <gmock/gmock.h>
@@ -11,9 +8,6 @@
namespace network
{
-void initializeTimers();
-void refreshObjects();
-
class MockManager : public Manager
{
public:
@@ -23,25 +17,9 @@
{
}
- void createInterfaces() override
- {
- interfaces.clear();
- for (auto& interface : system::getInterfaces())
- {
- config::Parser config(
- config::pathForIntfConf(confDir, *interface.name));
- auto intf = std::make_unique<MockEthernetInterface>(
- bus, *this, interface, objectPath, config);
- intf->createIPAddressObjects();
- intf->createStaticNeighborObjects();
- intf->loadNameServers(config);
- this->interfaces.emplace(
- std::make_pair(std::move(*interface.name), std::move(intf)));
- }
- }
-
MOCK_METHOD(void, reloadConfigs, (), (override));
- MOCK_METHOD(void, reloadConfigsNoRefresh, (), (override));
+
+ using Manager::handleAdminState;
};
} // namespace network
diff --git a/test/test_ethernet_interface.cpp b/test/test_ethernet_interface.cpp
index a7b3c69..dd1a10d 100644
--- a/test/test_ethernet_interface.cpp
+++ b/test/test_ethernet_interface.cpp
@@ -1,23 +1,15 @@
#include "config_parser.hpp"
#include "ipaddress.hpp"
+#include "mock_ethernet_interface.hpp"
#include "mock_network_manager.hpp"
-#include "mock_syscall.hpp"
-#include "system_queries.hpp"
-#include "util.hpp"
-#include <arpa/inet.h>
#include <net/if.h>
-#include <netinet/in.h>
-#include <stdlib.h>
-#include <charconv>
-#include <exception>
#include <sdbusplus/bus.hpp>
#include <stdplus/gtest/tmp.hpp>
#include <string_view>
#include <xyz/openbmc_project/Common/error.hpp>
-#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace phosphor
@@ -33,7 +25,7 @@
{
public:
sdbusplus::bus_t bus;
- std::string confDir;
+ std::filesystem::path confDir;
MockManager manager;
MockEthernetInterface interface;
TestEthernetInterface() :
@@ -47,9 +39,7 @@
static MockEthernetInterface makeInterface(sdbusplus::bus_t& bus,
MockManager& manager)
{
- system::mock_clear();
InterfaceInfo info{.idx = 1, .flags = 0, .name = "test0"};
- system::mock_addIF(info);
return {bus, manager, info, "/xyz/openbmc_test/network"sv,
config::Parser()};
}
@@ -86,7 +76,6 @@
.name = "test1",
.mac = mac,
.mtu = mtu};
- system::mock_addIF(info);
MockEthernetInterface intf(bus, manager, info,
"/xyz/openbmc_test/network"sv, config::Parser());
@@ -136,11 +125,9 @@
TEST_F(TestEthernetInterface, addStaticNameServers)
{
ServerList servers = {"9.1.1.1", "9.2.2.2", "9.3.3.3"};
- EXPECT_CALL(manager, reloadConfigsNoRefresh());
+ EXPECT_CALL(manager, reloadConfigs());
interface.staticNameServers(servers);
- fs::path filePath = confDir;
- filePath /= "00-bmc-test0.network";
- config::Parser parser(filePath.string());
+ config::Parser parser((confDir / "00-bmc-test0.network").native());
EXPECT_EQ(servers, parser.map.getValueStrings("Network", "DNS"));
}
@@ -155,11 +142,9 @@
TEST_F(TestEthernetInterface, addStaticNTPServers)
{
ServerList servers = {"10.1.1.1", "10.2.2.2", "10.3.3.3"};
- EXPECT_CALL(manager, reloadConfigsNoRefresh());
+ EXPECT_CALL(manager, reloadConfigs());
interface.staticNTPServers(servers);
- fs::path filePath = confDir;
- filePath /= "00-bmc-test0.network";
- config::Parser parser(filePath.string());
+ config::Parser parser((confDir / "00-bmc-test0.network").native());
EXPECT_EQ(servers, parser.map.getValueStrings("Network", "NTP"));
}
diff --git a/test/test_network_manager.cpp b/test/test_network_manager.cpp
index 7e3e211..ffffb44 100644
--- a/test/test_network_manager.cpp
+++ b/test/test_network_manager.cpp
@@ -1,11 +1,5 @@
#include "config_parser.hpp"
#include "mock_network_manager.hpp"
-#include "mock_syscall.hpp"
-
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <stdlib.h>
#include <filesystem>
#include <sdbusplus/bus.hpp>
@@ -30,12 +24,6 @@
bus(sdbusplus::bus::new_default()),
manager(bus, "/xyz/openbmc_test/abc", CaseTmpDir())
{
- system::mock_clear();
- }
-
- void createInterfaces()
- {
- manager.createInterfaces();
}
void deleteVLAN(std::string_view ifname)
@@ -44,31 +32,29 @@
}
};
-// getifaddrs will not return any interface
TEST_F(TestNetworkManager, NoInterface)
{
- createInterfaces();
EXPECT_TRUE(manager.interfaces.empty());
}
-// getifaddrs returns single interface.
+
TEST_F(TestNetworkManager, WithSingleInterface)
{
- // Adds the following ip in the getifaddrs list.
- system::mock_addIF({.idx = 2, .flags = 0, .name = "igb1"});
+ manager.addInterface({.idx = 2, .flags = 0, .name = "igb1"});
+ manager.handleAdminState("managed", 2);
// Now create the interfaces which will call the mocked getifaddrs
// which returns the above interface detail.
- createInterfaces();
EXPECT_THAT(manager.interfaces, UnorderedElementsAre(Key("igb1")));
}
// getifaddrs returns two interfaces.
TEST_F(TestNetworkManager, WithMultipleInterfaces)
{
- system::mock_addIF({.idx = 1, .flags = 0, .name = "igb0"});
- system::mock_addIF({.idx = 2, .flags = 0, .name = "igb1"});
+ manager.addInterface({.idx = 1, .flags = 0, .name = "igb0"});
+ manager.handleAdminState("managed", 1);
+ manager.handleAdminState("unmanaged", 2);
+ manager.addInterface({.idx = 2, .flags = 0, .name = "igb1"});
- createInterfaces();
EXPECT_THAT(manager.interfaces,
UnorderedElementsAre(Key("igb0"), Key("igb1")));
}
@@ -79,8 +65,8 @@
EXPECT_THROW(manager.vlan("", 0), std::exception);
EXPECT_THROW(manager.vlan("eth0", 2), std::exception);
- system::mock_addIF({.idx = 1, .flags = 0, .name = "eth0"});
- manager.createInterfaces();
+ manager.addInterface({.idx = 1, .flags = 0, .name = "eth0"});
+ manager.handleAdminState("managed", 1);
EXPECT_NO_THROW(manager.vlan("eth0", 2));
EXPECT_NO_THROW(manager.vlan("eth0", 4094));
EXPECT_THAT(
diff --git a/test/test_system_queries.cpp b/test/test_system_queries.cpp
deleted file mode 100644
index e88c64b..0000000
--- a/test/test_system_queries.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "system_queries.hpp"
-
-#include <gtest/gtest.h>
-
-namespace phosphor::network::system
-{
-namespace detail
-{
-
-TEST(ValidateNewAddr, Filtering)
-{
- AddressInfo info = {};
- EXPECT_TRUE(validateNewAddr(info, {}));
-
- info.ifidx = 2;
- EXPECT_TRUE(validateNewAddr(info, {}));
- EXPECT_TRUE(validateNewAddr(info, {.ifidx = 2}));
- EXPECT_FALSE(validateNewAddr(info, {.ifidx = 3}));
-}
-
-TEST(ValidateNewNeigh, Filtering)
-{
- NeighborInfo info = {};
- EXPECT_TRUE(validateNewNeigh(info, {}));
-
- info.ifidx = 2;
- EXPECT_TRUE(validateNewNeigh(info, {}));
- EXPECT_TRUE(validateNewNeigh(info, {.ifidx = 2}));
- EXPECT_FALSE(validateNewNeigh(info, {.ifidx = 3}));
-}
-
-} // namespace detail
-} // namespace phosphor::network::system