Factor getIfaceNames() from getIfaceList()

getIfaceList first walks the list of interfaces
from the sysfs, then it calls individually for
each of those interfaces to get the ifindex for
them. Because each of the calls to retrieve the
ifindex means a netlink call, this could possibly
cause performance problems (unconfirmed) on the
netlink interface. Since the names are independently
useful and are quick to fetch, this function is
now factored in to 2 parts: one which fetches the
names and a separate function which performs the
original operation of fetching the names and mapping
them to if_indices.

Bug: 74560705
Test: netd_integration_test - GetIfaceListTest
Merged-In: I1f888c31e992c8f7d51f3c67434ffef6d75b065d
Change-Id: I1f888c31e992c8f7d51f3c67434ffef6d75b065d
(cherry picked from commit dfe2a6f43de4aba2780c861c750db8e4f1fb22e3)
diff --git a/server/InterfaceControllerTest.cpp b/server/InterfaceControllerTest.cpp
index 0cf7cfc..fc5dce1 100644
--- a/server/InterfaceControllerTest.cpp
+++ b/server/InterfaceControllerTest.cpp
@@ -178,6 +178,19 @@
 
 class GetIfaceListTest : public testing::Test {};
 
+TEST_F(GetIfaceListTest, IfaceNames) {
+    StatusOr<std::vector<std::string>> ifaceNames = InterfaceController::getIfaceNames();
+    EXPECT_EQ(ok, ifaceNames.status());
+    struct ifaddrs *ifaddr, *ifa;
+    EXPECT_EQ(0, getifaddrs(&ifaddr));
+    for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+        const auto val = std::find(
+                ifaceNames.value().begin(), ifaceNames.value().end(), ifa->ifa_name);
+        EXPECT_NE(ifaceNames.value().end(), val);
+    }
+    freeifaddrs(ifaddr);
+}
+
 TEST_F(GetIfaceListTest, IfaceExist) {
     StatusOr<std::map<std::string, uint32_t>> ifaceMap = InterfaceController::getIfaceList();
     EXPECT_EQ(ok, ifaceMap.status());