diff options
Diffstat (limited to 'server/PhysicalNetwork.cpp')
-rw-r--r-- | server/PhysicalNetwork.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/server/PhysicalNetwork.cpp b/server/PhysicalNetwork.cpp index 2808fbe7..7b9a19a1 100644 --- a/server/PhysicalNetwork.cpp +++ b/server/PhysicalNetwork.cpp @@ -158,8 +158,36 @@ int PhysicalNetwork::removeAsDefault() { return 0; } -Network::Type PhysicalNetwork::getType() const { - return PHYSICAL; +int PhysicalNetwork::addUsers(const UidRanges& uidRanges, uint32_t subPriority) { + if (!isValidSubPriority(subPriority) || !canAddUidRanges(uidRanges, subPriority)) { + return -EINVAL; + } + + for (const std::string& interface : mInterfaces) { + int ret = RouteController::addUsersToPhysicalNetwork(mNetId, interface.c_str(), + {{subPriority, uidRanges}}); + if (ret) { + ALOGE("failed to add users on interface %s of netId %u", interface.c_str(), mNetId); + return ret; + } + } + addToUidRangeMap(uidRanges, subPriority); + return 0; +} + +int PhysicalNetwork::removeUsers(const UidRanges& uidRanges, uint32_t subPriority) { + if (!isValidSubPriority(subPriority)) return -EINVAL; + + for (const std::string& interface : mInterfaces) { + int ret = RouteController::removeUsersFromPhysicalNetwork(mNetId, interface.c_str(), + {{subPriority, uidRanges}}); + if (ret) { + ALOGE("failed to remove users on interface %s of netId %u", interface.c_str(), mNetId); + return ret; + } + } + removeFromUidRangeMap(uidRanges, subPriority); + return 0; } int PhysicalNetwork::addInterface(const std::string& interface) { @@ -167,7 +195,7 @@ int PhysicalNetwork::addInterface(const std::string& interface) { return 0; } if (int ret = RouteController::addInterfaceToPhysicalNetwork(mNetId, interface.c_str(), - mPermission)) { + mPermission, mUidRangeMap)) { ALOGE("failed to add interface %s to netId %u", interface.c_str(), mNetId); return ret; } @@ -194,7 +222,7 @@ int PhysicalNetwork::removeInterface(const std::string& interface) { // to find the interface index in the cache in cases where the interface is already gone // (e.g. bt-pan). if (int ret = RouteController::removeInterfaceFromPhysicalNetwork(mNetId, interface.c_str(), - mPermission)) { + mPermission, mUidRangeMap)) { ALOGE("failed to remove interface %s from netId %u", interface.c_str(), mNetId); return ret; } @@ -202,4 +230,9 @@ int PhysicalNetwork::removeInterface(const std::string& interface) { return 0; } +bool PhysicalNetwork::isValidSubPriority(uint32_t priority) { + return priority >= UidRanges::DEFAULT_SUB_PRIORITY && + priority <= UidRanges::LOWEST_SUB_PRIORITY; +} + } // namespace android::net |