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 NAT464_SERVICE_H 16 #define NAT464_SERVICE_H 17 18 #include <string> 19 20 #include "clat_constants.h" 21 #include "ffrt.h" 22 #include "inet_addr.h" 23 #include "net_all_capabilities.h" 24 25 namespace OHOS { 26 namespace NetManagerStandard { 27 28 class NetSupplier; 29 30 class Nat464Service { 31 public: 32 Nat464Service(int32_t netId, const std::string &v6Iface); 33 34 void UpdateService(Nat464UpdateFlag updateFlag); 35 36 void MaybeUpdateV6Iface(const std::string &v6Iface); 37 38 private: 39 void UpdateServiceState(Nat464UpdateFlag updateFlag); 40 41 void StartPrefixDiscovery(); 42 43 void DiscoverPrefix(); 44 45 bool GetPrefixFromDns64(); 46 47 void StopPrefixDiscovery(); 48 49 void StartService(); 50 51 void StopService(); 52 53 int32_t netId_; 54 std::string v6Iface_; 55 std::string v4TunIface_; 56 static inline ffrt::queue serviceUpdateQueue_{"Nat464ServiceUpdateState"}; 57 58 std::atomic<bool> tryStopDiscovery_; 59 uint32_t discoveryCycleMs_; 60 uint8_t discoveryIter_; 61 INetAddr nat64PrefixFromDns_; 62 63 volatile Nat464ServiceState serviceState_; 64 }; 65 } // namespace NetManagerStandard 66 } // namespace OHOS 67 #endif 68