summaryrefslogtreecommitdiff
path: root/server/InterfaceControllerTest.cpp
diff options
context:
space:
mode:
authorChenbo Feng <fengc@google.com>2018-02-28 22:57:21 -0800
committerChenbo Feng <fengc@google.com>2018-03-13 20:27:27 -0700
commit7e97405ea17a9134bb1b63c41d1d32de003d6bbf (patch)
tree8f2ecf975144551c81578b1b49aab302c07d9a2c /server/InterfaceControllerTest.cpp
parentcf9e21191285c14fe4d5b873169c9a401a9721f4 (diff)
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
Diffstat (limited to 'server/InterfaceControllerTest.cpp')
-rw-r--r--server/InterfaceControllerTest.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/server/InterfaceControllerTest.cpp b/server/InterfaceControllerTest.cpp
index 014d05d1..0cf7cfc1 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 @@ TEST_F(StablePrivacyTest, ExistingPropertyWriteFail) {
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