Add unit test cases for TrafficController
The unit test cases use fake eBPF map to verify the behavior of
TrafficController API such as tag/untag socket and set counter set.
It use four temperary bpf maps to store the result of
TrafficController.
Bug: 30950746
Test: run netd_unit_test
Change-Id: I71ad301475034986ca403a87b81b0cbfc354ae18
diff --git a/server/TrafficController.cpp b/server/TrafficController.cpp
index 2db7d42..3398c0a 100644
--- a/server/TrafficController.cpp
+++ b/server/TrafficController.cpp
@@ -253,20 +253,6 @@
return loadAndAttachProgram(BPF_CGROUP_INET_EGRESS, BPF_EGRESS_PROG_PATH, "egress_prog", cg_fd);
}
-uint64_t getSocketCookie(int sockFd) {
- uint64_t sock_cookie;
- socklen_t cookie_len = sizeof(sock_cookie);
- int res = getsockopt(sockFd, SOL_SOCKET, SO_COOKIE, &sock_cookie, &cookie_len);
- if (res < 0) {
- res = -errno;
- ALOGE("Failed to get socket cookie: %s\n", strerror(errno));
- errno = -res;
- // 0 is an invalid cookie. See INET_DIAG_NOCOOKIE.
- return 0;
- }
- return sock_cookie;
-}
-
int TrafficController::tagSocket(int sockFd, uint32_t tag, uid_t uid) {
if (legacy_tagSocket(sockFd, tag, uid)) return -errno;
if (!ebpfSupported) return 0;
@@ -388,7 +374,7 @@
}
// If the tag is not zero, we already deleted all the data entry required. If tag is 0, we also
- // need to delete the stats stored in uidStatsMap
+ // need to delete the stats stored in uidStatsMap and counterSet map.
if (tag != 0) return 0;
res = deleteMapEntry(mUidCounterSetMap, &uid);