Use bpf map to read the interface stats
With the support of xt_bpf module, the more accurate per interface
network traffic stats can be obtained from ifaceStatsMap under
sys/fs/bpf/. Change the framework NetworkStatsService native
implementation to read from map instead of /proc/net/dev. The
corresponding test is added and refactor the old test to be compatible.
Test: ./libbpf_test
atest android.net.cts.TrafficStatsTest
Bug: 72111305
Change-Id: I2a6c6f82317bd9667c1b15e6b082fc9f153f6bf3
diff --git a/server/BandwidthController.cpp b/server/BandwidthController.cpp
index ffedaf6..28dcbc1 100644
--- a/server/BandwidthController.cpp
+++ b/server/BandwidthController.cpp
@@ -267,11 +267,8 @@
} // namespace
bool BandwidthController::getBpfStatsStatus() {
- bool useBpf = (access(XT_BPF_INGRESS_PROG_PATH, F_OK) != -1) &&
- (access(XT_BPF_EGRESS_PROG_PATH, F_OK) != -1);
- // TODO: remove this when xt_bpf kernel support is ready
- useBpf = false;
- return useBpf;
+ return (access(XT_BPF_INGRESS_PROG_PATH, F_OK) != -1) &&
+ (access(XT_BPF_EGRESS_PROG_PATH, F_OK) != -1);
}
BandwidthController::BandwidthController() {