1*8542734aSAndroid Build Coastguard Worker /* 2*8542734aSAndroid Build Coastguard Worker * Copyright (C) 2014 The Android Open Source Project 3*8542734aSAndroid Build Coastguard Worker * 4*8542734aSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*8542734aSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*8542734aSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*8542734aSAndroid Build Coastguard Worker * 8*8542734aSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*8542734aSAndroid Build Coastguard Worker * 10*8542734aSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*8542734aSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*8542734aSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*8542734aSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*8542734aSAndroid Build Coastguard Worker * limitations under the License. 15*8542734aSAndroid Build Coastguard Worker */ 16*8542734aSAndroid Build Coastguard Worker 17*8542734aSAndroid Build Coastguard Worker #pragma once 18*8542734aSAndroid Build Coastguard Worker 19*8542734aSAndroid Build Coastguard Worker #include <set> 20*8542734aSAndroid Build Coastguard Worker 21*8542734aSAndroid Build Coastguard Worker #include "Network.h" 22*8542734aSAndroid Build Coastguard Worker 23*8542734aSAndroid Build Coastguard Worker namespace android::net { 24*8542734aSAndroid Build Coastguard Worker 25*8542734aSAndroid Build Coastguard Worker // A VirtualNetwork may be "secure" or not. 26*8542734aSAndroid Build Coastguard Worker // 27*8542734aSAndroid Build Coastguard Worker // A secure VPN is the usual type of VPN that grabs the default route (and thus all user traffic). 28*8542734aSAndroid Build Coastguard Worker // Only a few privileged UIDs may skip the VPN and go directly to the underlying physical network. 29*8542734aSAndroid Build Coastguard Worker // 30*8542734aSAndroid Build Coastguard Worker // A non-secure VPN ("bypassable" VPN) also grabs all user traffic by default. But all apps are 31*8542734aSAndroid Build Coastguard Worker // permitted to skip it and pick any other network for their connections. A bypassable VPN may 32*8542734aSAndroid Build Coastguard Worker // optionally exclude local routes, which means it will not grab traffic that is destined to IP 33*8542734aSAndroid Build Coastguard Worker // addresses considered to be on the local link. 34*8542734aSAndroid Build Coastguard Worker class VirtualNetwork : public Network { 35*8542734aSAndroid Build Coastguard Worker public: 36*8542734aSAndroid Build Coastguard Worker explicit VirtualNetwork(unsigned netId, bool secure, bool excludeLocalRoutes = false); 37*8542734aSAndroid Build Coastguard Worker virtual ~VirtualNetwork(); getPermission()38*8542734aSAndroid Build Coastguard Worker Permission getPermission() const { return PERMISSION_SYSTEM; }; 39*8542734aSAndroid Build Coastguard Worker [[nodiscard]] int addUsers(const UidRanges& uidRanges, int32_t subPriority) override; 40*8542734aSAndroid Build Coastguard Worker [[nodiscard]] int removeUsers(const UidRanges& uidRanges, int32_t subPriority) override; isVirtual()41*8542734aSAndroid Build Coastguard Worker bool isVirtual() override { return true; } canAddUsers()42*8542734aSAndroid Build Coastguard Worker bool canAddUsers() override { return true; } 43*8542734aSAndroid Build Coastguard Worker 44*8542734aSAndroid Build Coastguard Worker private: getTypeString()45*8542734aSAndroid Build Coastguard Worker std::string getTypeString() const override { return "VIRTUAL"; }; 46*8542734aSAndroid Build Coastguard Worker [[nodiscard]] int addInterface(const std::string& interface) override; 47*8542734aSAndroid Build Coastguard Worker [[nodiscard]] int removeInterface(const std::string& interface) override; 48*8542734aSAndroid Build Coastguard Worker bool isValidSubPriority(int32_t priority) override; 49*8542734aSAndroid Build Coastguard Worker // Whether the local traffic will be excluded from the VPN network. 50*8542734aSAndroid Build Coastguard Worker [[maybe_unused]] const bool mExcludeLocalRoutes; 51*8542734aSAndroid Build Coastguard Worker }; 52*8542734aSAndroid Build Coastguard Worker 53*8542734aSAndroid Build Coastguard Worker } // namespace android::net 54