Use netlink listener to track destroyed socket
Add a netlink SkDestroyListener in TrafficController to listen to the
broadcast from kernel when a inet socket get destroyed. The broadcast
message contains the socket cookie of the destroyed socket and
TrafficController uses it to remove the tag/uid information stored
inside cookieTagMap if the process that create and tag the socket forget
to untag it before closing the socket.
Bug: 30950746
Test: Rewrite NativeQtaguidTest.cpp to support eBPF module.
Change-Id: I46d5067c38bc3ecd6cd96db364c3897db25b4e10
diff --git a/server/TrafficController.h b/server/TrafficController.h
index 0691aa5..be2f6e6 100644
--- a/server/TrafficController.h
+++ b/server/TrafficController.h
@@ -20,6 +20,7 @@
#include <linux/bpf.h>
#include <netdutils/StatusOr.h>
+#include "NetlinkListener.h"
#include "Network.h"
#include "android-base/unique_fd.h"
@@ -168,6 +169,8 @@
*/
base::unique_fd mTagStatsMap;
+ std::unique_ptr<NetlinkListenerInterface> mSkDestroyListener;
+
bool ebpfSupported;
netdutils::Status loadAndAttachProgram(bpf_attach_type type, const char* path, const char* name,