summaryrefslogtreecommitdiff
path: root/server/InterfaceController.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/InterfaceController.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/InterfaceController.cpp')
-rw-r--r--server/InterfaceController.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/server/InterfaceController.cpp b/server/InterfaceController.cpp
index 28b814f2..5a630255 100644
--- a/server/InterfaceController.cpp
+++ b/server/InterfaceController.cpp
@@ -17,6 +17,7 @@
#include <dirent.h>
#include <errno.h>
#include <malloc.h>
+#include <net/if.h>
#include <sys/socket.h>
#include <functional>
@@ -386,3 +387,22 @@ void InterfaceController::setIPv6OptimisticMode(const char *value) {
setOnAllInterfaces(ipv6_proc_path, "optimistic_dad", value);
setOnAllInterfaces(ipv6_proc_path, "use_optimistic", value);
}
+
+StatusOr<std::map<std::string, uint32_t>> InterfaceController::getIfaceList() {
+ std::map<std::string, uint32_t> ifacePairs;
+ DIR* d;
+ struct dirent* de;
+
+ if (!(d = opendir("/sys/class/net"))) {
+ return statusFromErrno(errno, "Cannot open iface directory");
+ }
+ while ((de = readdir(d))) {
+ if (de->d_name[0] == '.') continue;
+ uint32_t ifaceIndex = if_nametoindex(de->d_name);
+ if (ifaceIndex) {
+ ifacePairs.insert(std::pair<std::string, uint32_t>(de->d_name, ifaceIndex));
+ }
+ }
+ closedir(d);
+ return ifacePairs;
+}