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); 45 46 private: 47 void ExecuteUpdate(SysVpnStageCode stage); 48 49 private: 50 static constexpr const char *IPSEC_CMD_PATH = "/system/bin/ipsec"; 51 const std::string VPN_STAGE_RESTART = "restart"; 52 const std::string VPN_STAGE_SWANCTL_LOAD = "swanctl --load-all --file "; 53 const std::string VPN_STAGE_UP_HOME = "up home"; 54 const std::string VPN_STAGE_DOWN_HOME = "down home"; 55 const std::string VPN_STAGE_STOP = "stop"; 56 const std::string VPN_STAGE_L2TP_LOAD = "xl2tpd -c "; 57 const std::string VPN_STAGE_L2TP_CTL = "l2tpctl"; 58 const std::string IPSEC_L2TP_CTL = " -C " IPSEC_PIDDIR "/l2tp-control"; 59 const std::string SWAN_CTL_FILE = IPSEC_PIDDIR "/swanctl.conf"; 60 const std::string L2TP_CFG = IPSEC_PIDDIR "/xl2tpd.conf"; 61 bool isIpSecAccess_ = false; 62 std::shared_ptr<ffrt::queue> vpnFfrtQueue_ = nullptr; 63 const std::string OPENVPN_CONFIG_FILE = IPSEC_PIDDIR "/config.ovpn"; 64 const std::string VPN_STAGE_OPENVPN_RESTART = "restartopenvpn --config "; 65 const std::string VPN_STAGE_OPENVPN_STOP = "stopopenvpn"; 66 }; 67 } // namespace nmd 68 } // namespace OHOS 69 #endif /* SYSTEM_VPN_WRAPPER_H */ 70