rtnetlink_server: Add interfaces dynamically
We don't need to refresh all of the interfaces anymore and can handle
just those that come and go.
Change-Id: Id6b3852f52065ff4a1ef412528261c826eae7e63
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/rtnetlink_server.cpp b/src/rtnetlink_server.cpp
index 2f2a152..c5732e9 100644
--- a/src/rtnetlink_server.cpp
+++ b/src/rtnetlink_server.cpp
@@ -3,11 +3,9 @@
#include "netlink.hpp"
#include "network_manager.hpp"
#include "rtnetlink.hpp"
-#include "types.hpp"
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
-#include <netinet/in.h>
#include <memory>
#include <phosphor-logging/log.hpp>
@@ -29,17 +27,6 @@
using phosphor::logging::level;
using phosphor::logging::log;
-static bool shouldRefresh(const struct nlmsghdr& hdr, std::string_view) noexcept
-{
- switch (hdr.nlmsg_type)
- {
- case RTM_NEWLINK:
- case RTM_DELLINK:
- return true;
- }
- return false;
-}
-
inline void rthandler(std::string_view data, auto&& cb)
{
auto ret = gatewayFromRtm(data);
@@ -52,14 +39,16 @@
static void handler(Manager& m, const nlmsghdr& hdr, std::string_view data)
{
- if (shouldRefresh(hdr, data) && !refreshObjectTimer->isEnabled())
- {
- refreshObjectTimer->restartOnce(refreshTimeout);
- }
try
{
switch (hdr.nlmsg_type)
{
+ case RTM_NEWLINK:
+ m.addInterface(intfFromRtm(data));
+ break;
+ case RTM_DELLINK:
+ m.removeInterface(intfFromRtm(data));
+ break;
case RTM_NEWROUTE:
rthandler(data, [&](auto ifidx, auto addr) {
m.addDefGw(ifidx, addr);