rtnetlink_server: Ignore errors on ignored interfaces
An example is MCTP device addresses that cannot be parsed by
phosphor-networkd. We don't need to parse them if they are ignored, so
we can just ignored the errors.
Tested: Verified that MCTP devices no longer cause error messages to
print to the journal.
Change-Id: I60b0a24f1e9a2e1866ac902833eb94c034ddfce0
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/rtnetlink_server.cpp b/src/rtnetlink_server.cpp
index 3fe997e..cfa0b2c 100644
--- a/src/rtnetlink_server.cpp
+++ b/src/rtnetlink_server.cpp
@@ -24,6 +24,23 @@
cb(std::get<unsigned>(*ret), std::get<InAddrAny>(*ret));
}
+static unsigned getIfIdx(const nlmsghdr& hdr, std::string_view data)
+{
+ switch (hdr.nlmsg_type)
+ {
+ case RTM_NEWLINK:
+ case RTM_DELLINK:
+ return extractRtData<ifinfomsg>(data).ifi_index;
+ case RTM_NEWADDR:
+ case RTM_DELADDR:
+ return extractRtData<ifaddrmsg>(data).ifa_index;
+ case RTM_NEWNEIGH:
+ case RTM_DELNEIGH:
+ return extractRtData<ndmsg>(data).ndm_ifindex;
+ }
+ throw std::runtime_error("Unknown nlmsg_type");
+}
+
static void handler(Manager& m, const nlmsghdr& hdr, std::string_view data)
{
try
@@ -62,6 +79,16 @@
}
catch (const std::exception& e)
{
+ try
+ {
+ if (m.ignoredIntf.contains(getIfIdx(hdr, data)))
+ {
+ // We don't want to log errors for ignored interfaces
+ return;
+ }
+ }
+ catch (...)
+ {}
lg2::error("Failed handling netlink event: {ERROR}", "ERROR", e);
}
}