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 #ifndef CLAT_MANAGER_H 16 #define CLAT_MANAGER_H 17 18 #include <linux/bpf.h> 19 #include <map> 20 #include <string> 21 22 #include "clat_constants.h" 23 #include "clat_utils.h" 24 #include "clatd.h" 25 #include "inet_addr.h" 26 #include "net_manager_native.h" 27 28 namespace OHOS { 29 namespace nmd { 30 using namespace OHOS::NetManagerStandard; 31 class ClatManager { 32 public: 33 ClatManager(); 34 35 int32_t ClatStart(const std::string &v6Iface, int32_t netId, const std::string &nat64PrefixStr, 36 NetManagerNative *netsysService); 37 38 int32_t ClatStop(const std::string &v6Iface); 39 40 private: 41 uint32_t GetFwmark(int32_t netId); 42 43 int32_t GenerateClatSrcAddr(const std::string &v6Iface, uint32_t fwmark, const std::string &nat64PrefixStr, 44 INetAddr &v4Addr, INetAddr &v6Addr); 45 46 int32_t CreateAndConfigureTunIface(const std::string &v6Iface, const std::string &tunIface, const INetAddr &v4Addr, 47 NetManagerNative *netsysService, int &tunFd); 48 49 int32_t CreateAndConfigureClatSocket(const std::string &v6Iface, const INetAddr &v6Addr, uint32_t fwmark, 50 int &readSock6, int &writeSock6); 51 52 std::map<std::string, Clatd> clatds_; 53 54 std::map<std::string, ClatdTracker> clatdTrackers_; 55 }; 56 } // namespace nmd 57 } // namespace OHOS 58 #endif