Skip to content
Snippets Groups Projects
Commit 60a657f4 authored by Maciej Żenczykowski's avatar Maciej Żenczykowski Committed by Gerrit Code Review
Browse files

Merge "eliminate some casts" into main

parents 2e29f6dd d7ade39c
No related branches found
No related tags found
No related merge requests found
......@@ -178,7 +178,7 @@ ASSERT_STRING_EQUAL(XT_BPF_DENYLIST_PROG_PATH, BPF_NETD_PATH "prog_netd_skfilte
#endif // __cplusplus
// LINT.IfChange(match_type)
enum UidOwnerMatchType {
enum UidOwnerMatchType : uint32_t {
NO_MATCH = 0,
HAPPY_BOX_MATCH = (1 << 0),
PENALTY_BOX_MATCH = (1 << 1),
......@@ -196,14 +196,14 @@ enum UidOwnerMatchType {
};
// LINT.ThenChange(../framework/src/android/net/BpfNetMapsConstants.java)
enum BpfPermissionMatch {
enum BpfPermissionMatch : uint8_t {
BPF_PERMISSION_INTERNET = 1 << 2,
BPF_PERMISSION_UPDATE_DEVICE_STATS = 1 << 3,
};
// In production we use two identical stats maps to record per uid stats and
// do swap and clean based on the configuration specified here. The statsMapType
// value in configuration map specified which map is currently in use.
enum StatsMapType {
enum StatsMapType : uint32_t {
SELECT_MAP_A,
SELECT_MAP_B,
};
......
......@@ -60,10 +60,10 @@ Result<void> Firewall::addRule(uint32_t uid, UidOwnerMatchType match, uint32_t i
// iif should be non-zero if and only if match == MATCH_IIF
if (match == IIF_MATCH && iif == 0) {
return Errorf("Interface match {} must have nonzero interface index",
static_cast<int>(match));
static_cast<uint32_t>(match));
} else if (match != IIF_MATCH && iif != 0) {
return Errorf("Non-interface match {} must have zero interface index",
static_cast<int>(match));
static_cast<uint32_t>(match));
}
std::lock_guard guard(mMutex);
......@@ -71,14 +71,14 @@ Result<void> Firewall::addRule(uint32_t uid, UidOwnerMatchType match, uint32_t i
if (oldMatch.ok()) {
UidOwnerValue newMatch = {
.iif = iif ? iif : oldMatch.value().iif,
.rule = static_cast<uint32_t>(oldMatch.value().rule | match),
.rule = oldMatch.value().rule | match,
};
auto res = mUidOwnerMap.writeValue(uid, newMatch, BPF_ANY);
if (!res.ok()) return Errorf("Failed to update rule: {}", res.error().message());
} else {
UidOwnerValue newMatch = {
.iif = iif,
.rule = static_cast<uint32_t>(match),
.rule = match,
};
auto res = mUidOwnerMap.writeValue(uid, newMatch, BPF_ANY);
if (!res.ok()) return Errorf("Failed to add rule: {}", res.error().message());
......@@ -93,7 +93,7 @@ Result<void> Firewall::removeRule(uint32_t uid, UidOwnerMatchType match) {
UidOwnerValue newMatch = {
.iif = (match == IIF_MATCH) ? 0 : oldMatch.value().iif,
.rule = static_cast<uint32_t>(oldMatch.value().rule & ~match),
.rule = oldMatch.value().rule & ~match,
};
if (newMatch.rule == 0) {
auto res = mUidOwnerMap.deleteValue(uid);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment