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 L2TP_VPN_INTERFACE_H 17 #define L2TP_VPN_INTERFACE_H 18 19 #include <cstdint> 20 21 #include "ipsecvpn_config.h" 22 #include "ipsec_vpn_ctl.h" 23 #include "l2tpvpn_config.h" 24 #include "net_vpn_impl.h" 25 26 namespace OHOS { 27 namespace NetManagerStandard { 28 namespace { 29 constexpr const char *L2TP_IPSEC_CONFIGURED_TAG = "xl2tpdstart"; 30 constexpr const char *L2TP_IPSEC_CONNECTED_TAG = "pppdstart"; 31 constexpr const char *VPN_NAME_KEY = "l2tp"; 32 constexpr const char *VPN_CLIENT_CONFIG_NAME_KEY = "options.l2tpd.client.conf"; 33 constexpr const char *SINGLE_XL2TP_CONFIG_LNS = " lns = "; 34 constexpr const char *SINGLE_XL2TP_CONFIG_PPP = ";ppp debug = yes;pppoptfile = "; 35 constexpr const char *SINGLE_XL2TP_CONFIG_LENGTH = ";length bit = yes;"; 36 } // namespace 37 class L2tpVpnCtl : public IpsecVpnCtl { 38 public: 39 L2tpVpnCtl(sptr<VpnConfig> config, const std::string &pkg, int32_t userId, std::vector<int32_t> &activeUserIds); 40 ~L2tpVpnCtl() = default; 41 42 int32_t GetVpnCertData(const int32_t certType, std::vector<int8_t> &certData) override; 43 int32_t GetConnectedSysVpnConfig(sptr<SysVpnConfig> &sysVpnConfig) override; 44 int32_t NotifyConnectStage(const std::string &stage, const int32_t &result) override; 45 int32_t GetSysVpnCertUri(const int32_t certType, std::string &certUri) override; 46 47 private: 48 int32_t StartSysVpn() override; 49 int32_t StopSysVpn() override; 50 int32_t InitConfigFile() override; 51 std::string GetXl2tpdConfig(); 52 void AddConfigToL2tpdConf(); 53 void HandleIpdecStarted(); 54 void HandleSwanCtlLoaded(); 55 void HandleL2tpConfiged(); 56 void HandleL2tpdCtl(); 57 void HandleL2tpConnected(); 58 void HandleConnectFailed(const int32_t result); 59 int32_t ProcessUpdateConfig(const std::string &config); 60 }; 61 } // namespace NetManagerStandard 62 } // namespace OHOS 63 #endif // L2TP_VPN_INTERFACE_H 64