Add a eBPF map to store iface name and index

Since the kernel bpf program can only get the iface index instead of
iface name, we need a seperate map to store the iface index and name
pair in userspace so the kernel program can know what iface each
received packet is and account against the correct name.

Test: run cts -m TrafficStatsTest
Bug: 30950746
Bug: 73137611
Change-Id: I6638dc4b03db6fd18b6b38b4524ec89e25a55bc0
diff --git a/server/InterfaceControllerTest.cpp b/server/InterfaceControllerTest.cpp
index 014d05d..0cf7cfc 100644
--- a/server/InterfaceControllerTest.cpp
+++ b/server/InterfaceControllerTest.cpp
@@ -14,6 +14,10 @@
  * limitations under the License.
  */
 
+#include <ifaddrs.h>
+#include <net/if.h>
+#include <sys/types.h>
+
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
@@ -172,5 +176,21 @@
     EXPECT_NE(ok, enableStablePrivacyAddresses(kTestIface));
 }
 
+class GetIfaceListTest : public testing::Test {};
+
+TEST_F(GetIfaceListTest, IfaceExist) {
+    StatusOr<std::map<std::string, uint32_t>> ifaceMap = InterfaceController::getIfaceList();
+    EXPECT_EQ(ok, ifaceMap.status());
+    struct ifaddrs *ifaddr, *ifa;
+    EXPECT_EQ(0, getifaddrs(&ifaddr));
+    for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+        uint32_t ifaceIndex = if_nametoindex(ifa->ifa_name);
+        const auto ifacePair = ifaceMap.value().find(ifa->ifa_name);
+        EXPECT_NE(ifaceMap.value().end(), ifacePair);
+        EXPECT_EQ(ifaceIndex, ifacePair->second);
+    }
+    freeifaddrs(ifaddr);
+}
+
 }  // namespace net
 }  // namespace android