#include "rtnetlink.hpp" #include "netlink.hpp" #include namespace phosphor::network::netlink { template static std::optional> parse(std::string_view msg) { std::optional ifIdx; std::optional gw; while (!msg.empty()) { auto [hdr, data] = extractRtAttr(msg); switch (hdr.rta_type) { case RTA_OIF: ifIdx.emplace(stdplus::raw::copyFrom(data)); break; case RTA_GATEWAY: gw.emplace(stdplus::raw::copyFrom(data)); break; } } if (ifIdx && gw) { return std::make_tuple(*ifIdx, *gw); } return std::nullopt; } std::optional> gatewayFromRtm(std::string_view msg) { const auto& rtm = extractRtData(msg); if (rtm.rtm_table != RT_TABLE_MAIN || rtm.rtm_dst_len != 0) { return std::nullopt; } switch (rtm.rtm_family) { case AF_INET: return parse(msg); case AF_INET6: return parse(msg); } return std::nullopt; } } // namespace phosphor::network::netlink