diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2020-02-06 13:38:02 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-02-06 13:38:02 +0000 |
| commit | 8954095846e713af149236da2f86b7360c28321a (patch) | |
| tree | 49bd60cc9002002a2dfc0e3cb7a707b25e2e6f0e /server/TrafficController.cpp | |
| parent | b1ff3f1bc3589b27271fc463bafd3803a8bb7a50 (diff) | |
| parent | 615fd7410a1c1a459c45cb610fe359bedcfb3cc1 (diff) | |
| download | platform_system_netd-8954095846e713af149236da2f86b7360c28321a.tar.gz platform_system_netd-8954095846e713af149236da2f86b7360c28321a.tar.bz2 platform_system_netd-8954095846e713af149236da2f86b7360c28321a.zip | |
Merge "Convert system/netd to Result::ok()"
Diffstat (limited to 'server/TrafficController.cpp')
| -rw-r--r-- | server/TrafficController.cpp | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/server/TrafficController.cpp b/server/TrafficController.cpp index d6ec6c01e..55f8cd070 100644 --- a/server/TrafficController.cpp +++ b/server/TrafficController.cpp @@ -390,7 +390,7 @@ int TrafficController::tagSocket(int sockFd, uint32_t tag, uid_t uid, uid_t call return base::Result<void>(); }; auto configuration = mConfigurationMap.readValue(CURRENT_STATS_MAP_CONFIGURATION_KEY); - if (!configuration) { + if (!configuration.ok()) { ALOGE("Failed to get current configuration: %s, fd: %d", strerror(configuration.error().code()), mConfigurationMap.getMap().get()); return -configuration.error().code(); @@ -403,7 +403,7 @@ int TrafficController::tagSocket(int sockFd, uint32_t tag, uid_t uid, uid_t call BpfMap<StatsKey, StatsValue>& currentMap = (configuration.value() == SELECT_MAP_A) ? mStatsMapA : mStatsMapB; base::Result<void> res = currentMap.iterate(countUidStatsEntries); - if (!res) { + if (!res.ok()) { ALOGE("Failed to count the stats entry in map %d: %s", currentMap.getMap().get(), strerror(res.error().code())); return -res.error().code(); @@ -422,7 +422,7 @@ int TrafficController::tagSocket(int sockFd, uint32_t tag, uid_t uid, uid_t call // 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. res = mCookieTagMap.writeValue(sock_cookie, newKey, BPF_ANY); - if (!res) { + if (!res.ok()) { ALOGE("Failed to tag the socket: %s, fd: %d", strerror(res.error().code()), mCookieTagMap.getMap().get()); return -res.error().code(); @@ -440,7 +440,7 @@ int TrafficController::untagSocket(int sockFd) { if (sock_cookie == NONEXISTENT_COOKIE) return -errno; base::Result<void> res = mCookieTagMap.deleteValue(sock_cookie); - if (!res) { + if (!res.ok()) { ALOGE("Failed to untag socket: %s\n", strerror(res.error().code())); return -res.error().code(); } @@ -498,7 +498,7 @@ int TrafficController::deleteTagData(uint32_t tag, uid_t uid, uid_t callingUid) BpfMap<uint64_t, UidTagValue>& map) { if (value.uid == uid && (value.tag == tag || tag == 0)) { auto res = map.deleteValue(key); - if (res || (res.error().code() == ENOENT)) { + if (res.ok() || (res.error().code() == ENOENT)) { return base::Result<void>(); } ALOGE("Failed to delete data(cookie = %" PRIu64 "): %s\n", key, @@ -514,7 +514,7 @@ int TrafficController::deleteTagData(uint32_t tag, uid_t uid, uid_t callingUid) BpfMap<StatsKey, StatsValue>& map) { if (key.uid == uid && (key.tag == tag || tag == 0)) { auto res = map.deleteValue(key); - if (res || (res.error().code() == ENOENT)) { + if (res.ok() || (res.error().code() == ENOENT)) { //Entry is deleted, use the current key to get a new nextKey; return base::Result<void>(); } @@ -530,7 +530,7 @@ int TrafficController::deleteTagData(uint32_t tag, uid_t uid, uid_t callingUid) if (tag != 0) return 0; auto res = mUidCounterSetMap.deleteValue(uid); - if (!res && res.error().code() != ENOENT) { + if (!res.ok() && res.error().code() != ENOENT) { ALOGE("Failed to delete counterSet data(uid=%u, tag=%u): %s\n", uid, tag, strerror(res.error().code())); } @@ -539,7 +539,7 @@ int TrafficController::deleteTagData(uint32_t tag, uid_t uid, uid_t callingUid) BpfMap<uint32_t, StatsValue>& map) -> base::Result<void> { if (key == uid) { auto res = map.deleteValue(key); - if (res || (res.error().code() == ENOENT)) { + if (res.ok() || (res.error().code() == ENOENT)) { return {}; } ALOGE("Failed to delete data(uid=%u): %s", key, strerror(res.error().code())); @@ -596,7 +596,7 @@ UidOwnerMatchType TrafficController::jumpOpToMatch(BandwidthController::IptJumpO Status TrafficController::removeRule(BpfMap<uint32_t, UidOwnerValue>& map, uint32_t uid, UidOwnerMatchType match) { auto oldMatch = map.readValue(uid); - if (oldMatch) { + if (oldMatch.ok()) { UidOwnerValue newMatch = { .iif = (match == IIF_MATCH) ? 0 : oldMatch.value().iif, .rule = static_cast<uint8_t>(oldMatch.value().rule & ~match), @@ -621,7 +621,7 @@ Status TrafficController::addRule(BpfMap<uint32_t, UidOwnerValue>& map, uint32_t return statusFromErrno(EINVAL, "Non-interface match must have zero interface index"); } auto oldMatch = map.readValue(uid); - if (oldMatch) { + if (oldMatch.ok()) { UidOwnerValue newMatch = { .iif = iif ? iif : oldMatch.value().iif, .rule = static_cast<uint8_t>(oldMatch.value().rule | match), @@ -788,7 +788,7 @@ int TrafficController::toggleUidOwnerMap(ChildChain chain, bool enable) { std::lock_guard guard(mMutex); uint32_t key = UID_RULES_CONFIGURATION_KEY; auto oldConfiguration = mConfigurationMap.readValue(key); - if (!oldConfiguration) { + if (!oldConfiguration.ok()) { ALOGE("Cannot read the old configuration from map: %s", oldConfiguration.error().message().c_str()); return -oldConfiguration.error().code(); @@ -831,7 +831,7 @@ Status TrafficController::swapActiveStatsMap() { uint32_t key = CURRENT_STATS_MAP_CONFIGURATION_KEY; auto oldConfiguration = mConfigurationMap.readValue(key); - if (!oldConfiguration) { + if (!oldConfiguration.ok()) { ALOGE("Cannot read the old configuration from map: %s", oldConfiguration.error().message().c_str()); return Status(oldConfiguration.error().code(), oldConfiguration.error().message()); @@ -843,7 +843,7 @@ Status TrafficController::swapActiveStatsMap() { uint8_t newConfigure = (oldConfiguration.value() == SELECT_MAP_A) ? SELECT_MAP_B : SELECT_MAP_A; auto res = mConfigurationMap.writeValue(CURRENT_STATS_MAP_CONFIGURATION_KEY, newConfigure, BPF_EXIST); - if (!res) { + if (!res.ok()) { ALOGE("Failed to toggle the stats map: %s", strerror(res.error().code())); return res; } @@ -1006,7 +1006,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { return base::Result<void>(); }; base::Result<void> res = mCookieTagMap.iterateWithValue(printCookieTagInfo); - if (!res) { + if (!res.ok()) { dw.println("mCookieTagMap print end with error: %s", res.error().message().c_str()); } @@ -1018,7 +1018,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { return base::Result<void>(); }; res = mUidCounterSetMap.iterateWithValue(printUidInfo); - if (!res) { + if (!res.ok()) { dw.println("mUidCounterSetMap print end with error: %s", res.error().message().c_str()); } @@ -1032,7 +1032,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { return base::Result<void>(); }; res = mAppUidStatsMap.iterateWithValue(printAppUidStatsInfo); - if (!res) { + if (!res.ok()) { dw.println("mAppUidStatsMap print end with error: %s", res.error().message().c_str()); } @@ -1044,7 +1044,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { const BpfMap<StatsKey, StatsValue>&) { uint32_t ifIndex = key.ifaceIndex; auto ifname = mIfaceIndexNameMap.readValue(ifIndex); - if (!ifname) { + if (!ifname.ok()) { ifname = IfaceValue{"unknown"}; } dw.println("%u %s 0x%x %u %u %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, ifIndex, @@ -1053,14 +1053,14 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { return base::Result<void>(); }; res = mStatsMapA.iterateWithValue(printStatsInfo); - if (!res) { + if (!res.ok()) { dw.println("mStatsMapA print end with error: %s", res.error().message().c_str()); } // Print TagStatsMap content. dumpBpfMap("mStatsMapB", dw, statsHeader); res = mStatsMapB.iterateWithValue(printStatsInfo); - if (!res) { + if (!res.ok()) { dw.println("mStatsMapB print end with error: %s", res.error().message().c_str()); } @@ -1073,7 +1073,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { return base::Result<void>(); }; res = mIfaceIndexNameMap.iterateWithValue(printIfaceNameInfo); - if (!res) { + if (!res.ok()) { dw.println("mIfaceIndexNameMap print end with error: %s", res.error().message().c_str()); } @@ -1084,7 +1084,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { const auto printIfaceStatsInfo = [&dw, this](const uint32_t& key, const StatsValue& value, const BpfMap<uint32_t, StatsValue>&) { auto ifname = mIfaceIndexNameMap.readValue(key); - if (!ifname) { + if (!ifname.ok()) { ifname = IfaceValue{"unknown"}; } dw.println("%u %s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, key, ifname.value().name, @@ -1092,7 +1092,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { return base::Result<void>(); }; res = mIfaceStatsMap.iterateWithValue(printIfaceStatsInfo); - if (!res) { + if (!res.ok()) { dw.println("mIfaceStatsMap print end with error: %s", res.error().message().c_str()); } @@ -1100,7 +1100,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { uint32_t key = UID_RULES_CONFIGURATION_KEY; auto configuration = mConfigurationMap.readValue(key); - if (configuration) { + if (configuration.ok()) { dw.println("current ownerMatch configuration: %d%s", configuration.value(), uidMatchTypeToString(configuration.value()).c_str()); } else { @@ -1110,7 +1110,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { key = CURRENT_STATS_MAP_CONFIGURATION_KEY; configuration = mConfigurationMap.readValue(key); - if (configuration) { + if (configuration.ok()) { const char* statsMapDescription = "???"; switch (configuration.value()) { case SELECT_MAP_A: @@ -1132,7 +1132,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { const BpfMap<uint32_t, UidOwnerValue>&) { if (value.rule & IIF_MATCH) { auto ifname = mIfaceIndexNameMap.readValue(value.iif); - if (ifname) { + if (ifname.ok()) { dw.println("%u %s %s", key, uidMatchTypeToString(value.rule).c_str(), ifname.value().name); } else { @@ -1144,7 +1144,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { return base::Result<void>(); }; res = mUidOwnerMap.iterateWithValue(printUidMatchInfo); - if (!res) { + if (!res.ok()) { dw.println("mUidOwnerMap print end with error: %s", res.error().message().c_str()); } dumpBpfMap("mUidPermissionMap", dw, ""); @@ -1154,7 +1154,7 @@ void TrafficController::dump(DumpWriter& dw, bool verbose) { return base::Result<void>(); }; res = mUidPermissionMap.iterateWithValue(printUidPermissionInfo); - if (!res) { + if (!res.ok()) { dw.println("mUidPermissionMap print end with error: %s", res.error().message().c_str()); } |
