1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef INCLUDE_VIRTUAL_NETWORK_H 17 #define INCLUDE_VIRTUAL_NETWORK_H 18 19 #include <cstdint> 20 #include <memory> 21 #include <set> 22 #include <string> 23 #include <vector> 24 25 #include <sys/types.h> 26 27 #include "netsys_network.h" 28 #include "network_permission.h" 29 #include "uid_range.h" 30 31 namespace OHOS { 32 namespace nmd { 33 using namespace NetManagerStandard; 34 class VirtualNetwork : public NetsysNetwork { 35 public: 36 VirtualNetwork(uint16_t netId, bool hasDns); 37 virtual ~VirtualNetwork() = default; 38 39 /** 40 * Judge network type whether or not physical 41 * 42 * @return Returns true physical 43 */ IsPhysical()44 bool IsPhysical() override 45 { 46 return false; 47 } 48 49 bool GetHasDns() const; 50 51 int32_t AddUids(const std::vector<UidRange> &uidRanges); 52 int32_t RemoveUids(const std::vector<UidRange> &uidRanges); 53 #ifdef SUPPORT_SYSVPN 54 int32_t UpdateVpnRules(const std::vector<std::string> &extMessages, bool add); 55 #endif // SUPPORT_SYSVPN 56 57 private: GetNetworkType()58 std::string GetNetworkType() const override 59 { 60 return "VIRTUAL"; 61 }; 62 63 int32_t AddInterface(std::string &interfaceName) override; 64 int32_t RemoveInterface(std::string &interfaceName) override; 65 66 private: 67 const bool hasDns_ = false; 68 std::vector<UidRange> uidRanges_; 69 }; 70 } // namespace nmd 71 } // namespace OHOS 72 #endif // INCLUDE_VIRTUAL_NETWORK_H 73