#define LOG_TAG "Netd"
#include "log/log.h"
-VirtualNetwork::VirtualNetwork(unsigned netId, uid_t /*ownerUid*/) : Network(netId) {
+VirtualNetwork::VirtualNetwork(unsigned netId, bool hasDns, bool secure) :
+ Network(netId), mHasDns(hasDns), mSecure(secure) {
}
VirtualNetwork::~VirtualNetwork() {
}
+bool VirtualNetwork::getHasDns() const {
+ return mHasDns;
+}
+
+bool VirtualNetwork::isSecure() const {
+ return mSecure;
+}
+
+bool VirtualNetwork::appliesToUser(uid_t uid) const {
+ return mUidRanges.hasUid(uid);
+}
+
+int VirtualNetwork::addUsers(const UidRanges& uidRanges) {
+ for (const std::string& interface : mInterfaces) {
+ if (int ret = RouteController::addUsersToVirtualNetwork(mNetId, interface.c_str(), mSecure,
+ uidRanges)) {
+ 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) {
+ if (int ret = RouteController::removeUsersFromVirtualNetwork(mNetId, interface.c_str(),
+ mSecure, uidRanges)) {
+ ALOGE("failed to remove users on interface %s of netId %u", interface.c_str(), mNetId);
+ return ret;
+ }
+ }
+ mUidRanges.remove(uidRanges);
+ return 0;
+}
+
+Network::Type VirtualNetwork::getType() const {
+ return VIRTUAL;
+}
+
int VirtualNetwork::addInterface(const std::string& interface) {
if (hasInterface(interface)) {
return 0;
}
- if (int ret = RouteController::addInterfaceToVpn(mNetId, interface.c_str())) {
+ if (int ret = RouteController::addInterfaceToVirtualNetwork(mNetId, interface.c_str(), mSecure,
+ mUidRanges)) {
ALOGE("failed to add interface %s to VPN netId %u", interface.c_str(), mNetId);
return ret;
}
if (!hasInterface(interface)) {
return 0;
}
- if (int ret = RouteController::removeInterfaceFromVpn(mNetId, interface.c_str())) {
+ if (int ret = RouteController::removeInterfaceFromVirtualNetwork(mNetId, interface.c_str(),
+ mSecure, mUidRanges)) {
ALOGE("failed to remove interface %s from VPN netId %u", interface.c_str(), mNetId);
return ret;
}