eliminate some casts
follow up to http://aosp/2965923 to hopefully eliminate that class of bug in the future... Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: Ie09db001ff15a6b2b15bb1bb0c1ce8228e162337
This commit is contained in:
parent
17dd9e9fa8
commit
d7ade39c0c
2 changed files with 8 additions and 8 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue