Check errors when iterate the stats maps
Don't ignore the error happened when iterating through the statsMap
before tagging a socket. Also simplify the logic a little bit.
Bug: 126620214
Test: netd_unit_test netd_integration_test
Change-Id: Ib41805028798e39fb3a2b503bc3fbe9be32a6c75
diff --git a/server/TrafficController.cpp b/server/TrafficController.cpp
index cbf6b04..f065e5e 100644
--- a/server/TrafficController.cpp
+++ b/server/TrafficController.cpp
@@ -374,14 +374,20 @@
strerror(configuration.status().code()), mConfigurationMap.getMap().get());
return -configuration.status().code();
}
- if (configuration.value() == SELECT_MAP_A) {
- mStatsMapA.iterate(countUidStatsEntries).ignoreError();
- } else if (configuration.value() == SELECT_MAP_B) {
- mStatsMapB.iterate(countUidStatsEntries).ignoreError();
- } else {
+ if (configuration.value() != SELECT_MAP_A && configuration.value() != SELECT_MAP_B) {
ALOGE("unknown configuration value: %d", configuration.value());
return -EINVAL;
}
+
+ BpfMap<StatsKey, StatsValue>& currentMap =
+ (configuration.value() == SELECT_MAP_A) ? mStatsMapA : mStatsMapB;
+ Status res = currentMap.iterate(countUidStatsEntries);
+ if (!isOk(res)) {
+ ALOGE("Failed to count the stats entry in map %d: %s", currentMap.getMap().get(),
+ strerror(res.code()));
+ return -res.code();
+ }
+
if (totalEntryCount > mTotalUidStatsEntriesLimit ||
perUidEntryCount > mPerUidStatsEntriesLimit) {
ALOGE("Too many stats entries in the map, total count: %u, uid(%u) count: %u, blocking tag"
@@ -394,7 +400,7 @@
// yet. And update the tag if there is already a tag stored. Since the eBPF
// program in kernel only read this map, and is protected by rcu read lock. It
// should be fine to cocurrently update the map while eBPF program is running.
- Status res = mCookieTagMap.writeValue(sock_cookie, newKey, BPF_ANY);
+ res = mCookieTagMap.writeValue(sock_cookie, newKey, BPF_ANY);
if (!isOk(res)) {
ALOGE("Failed to tag the socket: %s, fd: %d", strerror(res.code()),
mCookieTagMap.getMap().get());