Convert system/netd to Result::ok()
No functionality changes, this is a mechanical cleanup.
Change-Id: I3181d34b52a05ed26296e2e0e72a5cdb8e955712
diff --git a/server/TrafficController.cpp b/server/TrafficController.cpp
index 7e3b005..c18ac08 100644
--- a/server/TrafficController.cpp
+++ b/server/TrafficController.cpp
@@ -387,7 +387,7 @@
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();
@@ -400,7 +400,7 @@
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();
@@ -419,7 +419,7 @@
// 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();
@@ -437,7 +437,7 @@
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();
}
@@ -495,7 +495,7 @@
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,
@@ -511,7 +511,7 @@
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>();
}
@@ -527,7 +527,7 @@
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()));
}
@@ -536,7 +536,7 @@
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()));
@@ -593,7 +593,7 @@
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),
@@ -618,7 +618,7 @@
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),
@@ -785,7 +785,7 @@
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();
@@ -828,7 +828,7 @@
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());
@@ -840,7 +840,7 @@
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;
}
@@ -1003,7 +1003,7 @@
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());
}
@@ -1015,7 +1015,7 @@
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());
}
@@ -1029,7 +1029,7 @@
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());
}
@@ -1041,7 +1041,7 @@
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,
@@ -1050,14 +1050,14 @@
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());
}
@@ -1070,7 +1070,7 @@
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());
}
@@ -1081,7 +1081,7 @@
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,
@@ -1089,7 +1089,7 @@
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());
}
@@ -1097,7 +1097,7 @@
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 {
@@ -1107,7 +1107,7 @@
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:
@@ -1129,7 +1129,7 @@
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 {
@@ -1141,7 +1141,7 @@
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, "");
@@ -1151,7 +1151,7 @@
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());
}