diff options
| author | Ken Chen <cken@google.com> | 2021-03-22 11:37:17 +0800 |
|---|---|---|
| committer | Ken Chen <cken@google.com> | 2021-03-23 11:41:59 +0800 |
| commit | c929e8aca3eb6a8fd05c9630c9776e751430648a (patch) | |
| tree | 0c4628c82360dec48e9e86d50df1fedc7f53c3b6 /server/VirtualNetwork.cpp | |
| parent | 3824ac96477f7432767f683b0d44c0356e6c7d5a (diff) | |
| download | platform_system_netd-c929e8aca3eb6a8fd05c9630c9776e751430648a.tar.gz platform_system_netd-c929e8aca3eb6a8fd05c9630c9776e751430648a.tar.bz2 platform_system_netd-c929e8aca3eb6a8fd05c9630c9776e751430648a.zip | |
Implement addUsers()/removeUsers() in derived classes
The implementation of addUsers() and removeUsers() are different between
virtual network, physical network, and others. Virtualize both functions
in base class and override them in derived classes for specialization.
Test: atest
Change-Id: Ie3baeb404d2cd9513efb95857de53b4b3079be0b
Diffstat (limited to 'server/VirtualNetwork.cpp')
| -rw-r--r-- | server/VirtualNetwork.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/server/VirtualNetwork.cpp b/server/VirtualNetwork.cpp index 0b425595a..9ae6c16f4 100644 --- a/server/VirtualNetwork.cpp +++ b/server/VirtualNetwork.cpp @@ -35,6 +35,36 @@ Network::Type VirtualNetwork::getType() const { return VIRTUAL; } +int VirtualNetwork::addUsers(const UidRanges& uidRanges) { + if (hasInvalidUidRanges(uidRanges)) { + return -EINVAL; + } + + for (const std::string& interface : mInterfaces) { + int ret = RouteController::addUsersToVirtualNetwork(mNetId, interface.c_str(), mSecure, + uidRanges); + if (ret) { + ALOGE("failed to add users on interface %s of netId %u", interface.c_str(), mNetId); + return ret; + } + } + mUidRanges.add(uidRanges); + return 0; +} + +int VirtualNetwork::removeUsers(const UidRanges& uidRanges) { + for (const std::string& interface : mInterfaces) { + int ret = RouteController::removeUsersFromVirtualNetwork(mNetId, interface.c_str(), mSecure, + uidRanges); + if (ret) { + ALOGE("failed to remove users on interface %s of netId %u", interface.c_str(), mNetId); + return ret; + } + } + mUidRanges.remove(uidRanges); + return 0; +} + int VirtualNetwork::addInterface(const std::string& interface) { if (hasInterface(interface)) { return 0; |
