#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() {
}
-int VirtualNetwork::addInterface(const std::string& interface) {
- if (hasInterface(interface)) {
- return 0;
- }
- if (int ret = RouteController::addInterfaceToVpn(mNetId, interface.c_str(), mUidRanges)) {
- ALOGE("failed to add interface %s to VPN netId %u", interface.c_str(), mNetId);
- return ret;
- }
- mInterfaces.insert(interface);
- return 0;
+bool VirtualNetwork::getHasDns() const {
+ return mHasDns;
}
-int VirtualNetwork::removeInterface(const std::string& interface) {
- if (!hasInterface(interface)) {
- return 0;
- }
- if (int ret = RouteController::removeInterfaceFromVpn(mNetId, interface.c_str(), mUidRanges)) {
- ALOGE("failed to remove interface %s from VPN netId %u", interface.c_str(), mNetId);
- return ret;
- }
- mInterfaces.erase(interface);
- return 0;
+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::addUsersToVpn(mNetId, interface.c_str(), uidRanges)) {
+ 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;
}
int VirtualNetwork::removeUsers(const UidRanges& uidRanges) {
for (const std::string& interface : mInterfaces) {
- if (int ret = RouteController::removeUsersFromVpn(mNetId, interface.c_str(), uidRanges)) {
+ 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::addInterfaceToVirtualNetwork(mNetId, interface.c_str(), mSecure,
+ mUidRanges)) {
+ ALOGE("failed to add interface %s to VPN netId %u", interface.c_str(), mNetId);
+ return ret;
+ }
+ mInterfaces.insert(interface);
+ return 0;
+}
+
+int VirtualNetwork::removeInterface(const std::string& interface) {
+ if (!hasInterface(interface)) {
+ return 0;
+ }
+ 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;
+ }
+ mInterfaces.erase(interface);
+ return 0;
+}