diff options
| author | Ken Chen <cken@google.com> | 2021-05-23 14:56:43 +0800 |
|---|---|---|
| committer | Ken Chen <cken@google.com> | 2021-07-01 01:17:01 +0800 |
| commit | 4ea88460c9a94fb0dc0b8bdee8fb5498ebcb38df (patch) | |
| tree | 3acf3084ed632b1b2d2e450c17e2bca7bde72d22 /server/PhysicalNetwork.cpp | |
| parent | ba36d2784d5d20dc88624cc3116c9d96aa328e0e (diff) | |
| download | platform_system_netd-4ea88460c9a94fb0dc0b8bdee8fb5498ebcb38df.tar.gz platform_system_netd-4ea88460c9a94fb0dc0b8bdee8fb5498ebcb38df.tar.bz2 platform_system_netd-4ea88460c9a94fb0dc0b8bdee8fb5498ebcb38df.zip | |
Support subsidiary priority on UID ranges
Network preference per-profile and OEM network preferences can't be set
at the same time, because it is unclear what should happen if both
preferences are active for one given UID. Therefore, it needs a
parameter for ConnectivityService to specify which preference is prior
to others.
In this commit:
1. Adds a pair of methods with parcelable parameter, which currently
includes netId, UID range array and subsidiary priority.
2. The subsidiary priority will be used to adjust the original IP rule
priority. UID ranges can applies to different network with different
subsidiary priority. But a single UID should not apply to multiple
networks with the same subsidiary priority.
3. The possible value of subsidiary priority for physical and
unreachable networks is 0-999. 0 is the highest priority. 0 is also
the default value. Virtual network supports only the default value.
4. Netd and its tests reference to latest AIDL version (unstable).
Bug: 182460808
Test: m; flash; cd system/netd/; atest
Test: atest FrameworksNetTests
Test: atest HostsideVpnTests
Change-Id: I94e8830d0a21ffcca17757fe4783a4be9438c8b4
Diffstat (limited to 'server/PhysicalNetwork.cpp')
| -rw-r--r-- | server/PhysicalNetwork.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/server/PhysicalNetwork.cpp b/server/PhysicalNetwork.cpp index 894d56ab2..7b9a19a15 100644 --- a/server/PhysicalNetwork.cpp +++ b/server/PhysicalNetwork.cpp @@ -158,32 +158,35 @@ int PhysicalNetwork::removeAsDefault() { return 0; } -int PhysicalNetwork::addUsers(const UidRanges& uidRanges) { - if (hasInvalidUidRanges(uidRanges)) { +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(), uidRanges); + 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; } } - mUidRanges.add(uidRanges); + addToUidRangeMap(uidRanges, subPriority); return 0; } -int PhysicalNetwork::removeUsers(const UidRanges& uidRanges) { +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(), - uidRanges); + {{subPriority, uidRanges}}); if (ret) { ALOGE("failed to remove users on interface %s of netId %u", interface.c_str(), mNetId); return ret; } } - mUidRanges.remove(uidRanges); + removeFromUidRangeMap(uidRanges, subPriority); return 0; } @@ -192,7 +195,7 @@ int PhysicalNetwork::addInterface(const std::string& interface) { return 0; } if (int ret = RouteController::addInterfaceToPhysicalNetwork(mNetId, interface.c_str(), - mPermission, mUidRanges)) { + mPermission, mUidRangeMap)) { ALOGE("failed to add interface %s to netId %u", interface.c_str(), mNetId); return ret; } @@ -219,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, mUidRanges)) { + mPermission, mUidRangeMap)) { ALOGE("failed to remove interface %s from netId %u", interface.c_str(), mNetId); return ret; } @@ -227,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 |
