rtnetlink: Migrate IP functions
Change-Id: I4c87b59306911df4c5a73e441b2b962fbaab072c
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/system_queries.cpp b/src/system_queries.cpp
index f0222ec..5aba1d2 100644
--- a/src/system_queries.cpp
+++ b/src/system_queries.cpp
@@ -1,6 +1,7 @@
#include "system_queries.hpp"
#include "netlink.hpp"
+#include "rtnetlink.hpp"
#include "util.hpp"
#include <fmt/format.h>
@@ -224,6 +225,16 @@
return true;
}
+bool detail::validateNewAddr(const AddressInfo& info,
+ const AddressFilter& filter) noexcept
+{
+ if (filter.ifidx != 0 && filter.ifidx != info.ifidx)
+ {
+ return false;
+ }
+ return true;
+}
+
std::vector<InterfaceInfo> getInterfaces()
{
std::vector<InterfaceInfo> ret;
@@ -239,4 +250,20 @@
return ret;
}
+std::vector<AddressInfo> getAddresses(const AddressFilter& filter)
+{
+ std::vector<AddressInfo> ret;
+ auto cb = [&](const nlmsghdr&, std::string_view msg) {
+ auto info = netlink::addrFromRtm(msg);
+ if (detail::validateNewAddr(info, filter))
+ {
+ ret.emplace_back(std::move(info));
+ }
+ };
+ ifaddrmsg msg{};
+ msg.ifa_index = filter.ifidx;
+ netlink::performRequest(NETLINK_ROUTE, RTM_GETADDR, NLM_F_DUMP, msg, cb);
+ return ret;
+}
+
} // namespace phosphor::network::system