• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "extended_vpn_ctl.h"
17 
18 #include <regex>
19 #include <string>
20 
21 #include <fcntl.h>
22 
23 #include "net_manager_constants.h"
24 #include "net_manager_ext_constants.h"
25 #include "netmgr_ext_log_wrapper.h"
26 #include "netsys_controller.h"
27 
28 namespace OHOS {
29 namespace NetManagerStandard {
30 
ExtendedVpnCtl(sptr<VpnConfig> config,const std::string & pkg,int32_t userId,std::vector<int32_t> & activeUserIds)31 ExtendedVpnCtl::ExtendedVpnCtl(sptr<VpnConfig> config, const std::string &pkg, int32_t userId, std::vector<int32_t> &activeUserIds)
32     : NetVpnImpl(config, pkg, userId, activeUserIds)
33 {
34 }
35 
IsInternalVpn()36 bool ExtendedVpnCtl::IsInternalVpn()
37 {
38     return false;
39 }
40 
SetUp()41 int32_t ExtendedVpnCtl::SetUp()
42 {
43     NETMGR_EXT_LOG_I("SetUp virtual network");
44 #ifdef SUPPORT_SYSVPN
45     if (vpnConfig_ != nullptr && !vpnConfig_->vpnId_.empty() && multiVpnInfo_ != nullptr) {
46         NetsysController::GetInstance().ProcessVpnStage(SysVpnStageCode::VPN_STAGE_SET_VPN_CALL_MODE,
47             multiVpnInfo_->isVpnExtCall ? "0" : "1");
48         std::string addr = vpnConfig_->addresses_.empty() ? "" : vpnConfig_->addresses_.back().address_;
49         if (MultiVpnHelper::GetInstance().CheckAndCompareMultiVpnLocalAddress(addr) != NETMANAGER_EXT_SUCCESS) {
50             NETMGR_EXT_LOG_E("forbit setup, multi tun check ip address is same");
51             return NETMANAGER_EXT_ERR_INTERNAL;
52         }
53         multiVpnInfo_->localAddress = addr;
54     }
55 #endif // SUPPORT_SYSVPN
56     return NetVpnImpl::SetUp();
57 }
58 
Destroy()59 int32_t ExtendedVpnCtl::Destroy()
60 {
61     NETMGR_EXT_LOG_I("Destroy virtual network");
62 #ifdef SUPPORT_SYSVPN
63     if (vpnConfig_ != nullptr && !vpnConfig_->vpnId_.empty() && multiVpnInfo_ != nullptr) {
64         NetsysController::GetInstance().ProcessVpnStage(SysVpnStageCode::VPN_STAGE_SET_VPN_CALL_MODE,
65             multiVpnInfo_->isVpnExtCall ? "0" : "1");
66     }
67 #endif // SUPPORT_SYSVPN
68     return NetVpnImpl::Destroy();
69 }
70 
71 } // namespace NetManagerStandard
72 } // namespace OHOS
73