diff --git a/bpf_progs/netd.h b/bpf_progs/netd.h index 64ed633277b84548f3d59080c89567c212f53a7f..098147f8f4c8e7644cbaab76ce1f746661681a65 100644 --- a/bpf_progs/netd.h +++ b/bpf_progs/netd.h @@ -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, }; diff --git a/tests/native/utilities/firewall.cpp b/tests/native/utilities/firewall.cpp index 718ec9763d7f8ca2cf284e4a9fc5a6988b0ae152..34b4f0756b8cc521aaf726263ef7739055423d16 100644 --- a/tests/native/utilities/firewall.cpp +++ b/tests/native/utilities/firewall.cpp @@ -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);