1 /* 2 * Copyright (C) 2025 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 #ifndef OHOS_MULTI_VPN_HELPER_H 16 #define OHOS_MULTI_VPN_HELPER_H 17 #include <string> 18 #include <vector> 19 20 #include "sysvpn_config.h" 21 #include "refbase.h" 22 #include "net_manager_ext_constants.h" 23 #include "netsys_controller.h" 24 25 namespace OHOS { 26 namespace NetManagerStandard { 27 using namespace NetsysNative; 28 struct MultiVpnInfo : RefBase { 29 std::string vpnId; 30 std::string ifName; 31 std::string bundleName; 32 std::string localAddress; 33 int32_t ifNameId; 34 int32_t callingUid; 35 int32_t userId; 36 VpnConnectState vpnConnectState = VpnConnectState::VPN_DISCONNECTED; 37 bool isVpnExtCall = true; 38 }; 39 constexpr int32_t VPN_LOCAL_IP_INDEX = 1; 40 constexpr const char *DISCONNECT_TAG = "disconnect"; 41 42 class MultiVpnHelper { 43 public: 44 static MultiVpnHelper &GetInstance(); 45 int32_t GetNewIfNameId(); 46 int32_t CreateMultiVpnInfo(const std::string &vpnId, int32_t vpnType, sptr<MultiVpnInfo> &info); 47 int32_t AddMultiVpnInfo(const sptr<MultiVpnInfo> &info); 48 int32_t DelMultiVpnInfo(const sptr<MultiVpnInfo> &info); 49 bool StartIpsec(); 50 void StopIpsec(); 51 bool StartL2tp(); 52 void StopL2tp(); 53 bool IsConnectedStage(const std::string &stage); 54 int32_t CheckAndCompareMultiVpnLocalAddress(const std::string &localAddress); 55 int32_t GetDisconnectAddr(const std::string &stage, std::string &addr); 56 private: 57 MultiVpnHelper(); 58 bool IsOpenvpnConnectedStage(const std::string &stage); 59 std::vector<sptr<MultiVpnInfo>> multiVpnInfos_; 60 int32_t ipsecStartedCount_ = 0; 61 int32_t l2tpStartedCount_ = 0; 62 }; 63 } // namespace MultiVpnHelper 64 } // namespace OHOS 65 #endif // OHOS_MULTI_VPN_HELPER_H