rtnetlink: Migrate neighbor functions
Change-Id: I697f3d70f327f5d1d5e104dc7e4a2af528bf2b6e
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/system_queries.cpp b/src/system_queries.cpp
index 5aba1d2..35dfa10 100644
--- a/src/system_queries.cpp
+++ b/src/system_queries.cpp
@@ -235,6 +235,16 @@
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;
@@ -266,4 +276,20 @@
return ret;
}
+std::vector<NeighborInfo> getNeighbors(const NeighborFilter& filter)
+{
+ std::vector<NeighborInfo> ret;
+ auto cb = [&](const nlmsghdr&, std::string_view msg) {
+ auto info = netlink::neighFromRtm(msg);
+ if (detail::validateNewNeigh(info, filter))
+ {
+ ret.push_back(std::move(info));
+ }
+ };
+ ndmsg msg{};
+ msg.ndm_ifindex = filter.ifidx;
+ netlink::performRequest(NETLINK_ROUTE, RTM_GETNEIGH, NLM_F_DUMP, msg, cb);
+ return ret;
+}
+
} // namespace phosphor::network::system