From 42edc60627899989335dafa568f6bf724ea1a104 Mon Sep 17 00:00:00 2001 From: Motomu Utsumi Date: Thu, 12 May 2022 13:57:42 +0000 Subject: [PATCH] Support 32 match types in UidOwnerValue rule Match type is also used in configuration_map at index UID_RULES_CONFIGURATION_KEY. However, this commit does not extend configuration_map and we can not still use more than 8 match type in configuration_map. Test: m Change-Id: I0f20cc8034551806b5cb3da322a0ea7861983095 --- bpf_progs/netd.c | 2 +- service/native/TrafficController.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bpf_progs/netd.c b/bpf_progs/netd.c index fe9a871535..f3f675fb87 100644 --- a/bpf_progs/netd.c +++ b/bpf_progs/netd.c @@ -194,7 +194,7 @@ static inline int bpf_owner_match(struct __sk_buff* skb, uint32_t uid, int direc BpfConfig enabledRules = getConfig(UID_RULES_CONFIGURATION_KEY); UidOwnerValue* uidEntry = bpf_uid_owner_map_lookup_elem(&uid); - uint8_t uidRules = uidEntry ? uidEntry->rule : 0; + uint32_t uidRules = uidEntry ? uidEntry->rule : 0; uint32_t allowed_iif = uidEntry ? uidEntry->iif : 0; if (enabledRules) { diff --git a/service/native/TrafficController.cpp b/service/native/TrafficController.cpp index 3e98edb7b5..473c9e38e6 100644 --- a/service/native/TrafficController.cpp +++ b/service/native/TrafficController.cpp @@ -88,7 +88,7 @@ static_assert(BPF_PERMISSION_UPDATE_DEVICE_STATS == INetd::PERMISSION_UPDATE_DEV } \ } while (0) -const std::string uidMatchTypeToString(uint8_t match) { +const std::string uidMatchTypeToString(uint32_t match) { std::string matchType; FLAG_MSG_TRANS(matchType, HAPPY_BOX_MATCH, match); FLAG_MSG_TRANS(matchType, PENALTY_BOX_MATCH, match); @@ -272,7 +272,7 @@ Status TrafficController::removeRule(uint32_t uid, UidOwnerMatchType match) { if (oldMatch.ok()) { UidOwnerValue newMatch = { .iif = (match == IIF_MATCH) ? 0 : oldMatch.value().iif, - .rule = static_cast(oldMatch.value().rule & ~match), + .rule = oldMatch.value().rule & ~match, }; if (newMatch.rule == 0) { RETURN_IF_NOT_OK(mUidOwnerMap.deleteValue(uid)); @@ -296,13 +296,13 @@ Status TrafficController::addRule(uint32_t uid, UidOwnerMatchType match, uint32_ if (oldMatch.ok()) { UidOwnerValue newMatch = { .iif = iif ? iif : oldMatch.value().iif, - .rule = static_cast(oldMatch.value().rule | match), + .rule = oldMatch.value().rule | match, }; RETURN_IF_NOT_OK(mUidOwnerMap.writeValue(uid, newMatch, BPF_ANY)); } else { UidOwnerValue newMatch = { .iif = iif, - .rule = static_cast(match), + .rule = match, }; RETURN_IF_NOT_OK(mUidOwnerMap.writeValue(uid, newMatch, BPF_ANY)); }