1 /* 2 * Copyright (c) 2024 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 SYSTEM_VPN_WRAPPER_H 17 #define SYSTEM_VPN_WRAPPER_H 18 19 #include <cstring> 20 #include "ffrt.h" 21 #include "i_netsys_service.h" 22 23 #define IPSEC_PIDDIR "/data/service/el1/public/vpn" 24 25 namespace OHOS { 26 namespace nmd { 27 using namespace NetsysNative; 28 class SystemVpnWrapper : public std::enable_shared_from_this<SystemVpnWrapper> { 29 public: 30 SystemVpnWrapper(); 31 ~SystemVpnWrapper(); GetInstance()32 static std::shared_ptr<SystemVpnWrapper> &GetInstance() 33 { 34 static std::shared_ptr<SystemVpnWrapper> instance = std::make_shared<SystemVpnWrapper>(); 35 return instance; 36 } 37 38 /** 39 * update system vpn next stage by SysVpnStageCode 40 * 41 * @param stage one of the SysVpnStageCode 42 * @return NETMANAGER_SUCCESS suceess or NETMANAGER_ERROR failed 43 */ 44 int32_t Update(SysVpnStageCode stage, const std::string &message = ""); 45 46 private: 47 void ExecuteUpdate(SysVpnStageCode stage, const std::string &message = ""); 48 bool PrepareUpdate(SysVpnStageCode stage, const std::string &message = ""); 49 50 private: 51 static constexpr const char *IPSEC_CMD_PATH = "/system/bin/ipsec"; 52 const std::string VPN_STAGE_RESTART = "restart"; 53 const std::string VPN_STAGE_SWANCTL_LOAD = "swanctl --load-all --file "; 54 const std::string VPN_STAGE_UP_HOME = "up "; 55 const std::string VPN_STAGE_DOWN_HOME = "down "; 56 const std::string VPN_STAGE_STOP = "stop"; 57 const std::string VPN_STAGE_L2TP_LOAD = "xl2tpd -c "; 58 const std::string VPN_STAGE_L2TP_CTL = "l2tpctl "; 59 const std::string IPSEC_L2TP_CTL = " -C " IPSEC_PIDDIR "/l2tp-control"; 60 const std::string SWAN_CTL_FILE = IPSEC_PIDDIR "/swanctl.conf"; 61 const std::string L2TP_CFG = IPSEC_PIDDIR "/xl2tpd.conf"; 62 bool isIpSecAccess_ = false; 63 std::shared_ptr<ffrt::queue> vpnFfrtQueue_ = nullptr; 64 const std::string OPENVPN_CONFIG_FILE = IPSEC_PIDDIR "/config.ovpn"; 65 const std::string VPN_STAGE_OPENVPN_RESTART = "restartopenvpn --config "; 66 const std::string VPN_STAGE_OPENVPN_STOP = "stopopenvpn"; 67 const std::string VPN_STAGE_L2TP_STOP = "stopl2tp "; 68 const std::string VPN_STAGE_SET_L2TP_CONF = "setl2tp "; 69 }; 70 } // namespace nmd 71 } // namespace OHOS 72 #endif /* SYSTEM_VPN_WRAPPER_H */ 73