1 /* 2 * Copyright (c) 2021-2023 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 DEV_INTERFACE_STATE_H 17 #define DEV_INTERFACE_STATE_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <iosfwd> 22 #include <set> 23 #include <string> 24 #include <vector> 25 26 #include "http_proxy.h" 27 #include "interface_configuration.h" 28 #include "net_all_capabilities.h" 29 #include "net_link_info.h" 30 #include "net_specifier.h" 31 #include "net_supplier_info.h" 32 #include "refbase.h" 33 34 namespace OHOS { 35 namespace NetManagerStandard { 36 class DevInterfaceState : public virtual RefBase { 37 public: 38 DevInterfaceState(); 39 ~DevInterfaceState() = default; 40 void SetDevName(const std::string &devName); 41 void SetNetCaps(const std::set<NetCap> &netCaps); 42 void SetLinkUp(bool up); 43 void SetlinkInfo(sptr<NetLinkInfo> &linkInfo); 44 void SetIfcfg(sptr<InterfaceConfiguration> &ifCfg); 45 void SetDhcpReqState(bool dhcpReqState); 46 void UpdateNetHttpProxy(const HttpProxy &httpProxy); 47 void UpdateLinkInfo(const sptr<StaticConfiguration> &config); 48 std::string GetDevName() const; 49 const std::set<NetCap> &GetNetCaps() const; 50 std::set<NetCap> GetNetCaps(); 51 bool GetLinkUp() const; 52 sptr<NetLinkInfo> GetLinkInfo() const; 53 sptr<InterfaceConfiguration> GetIfcfg() const; 54 IPSetMode GetIPSetMode() const; 55 bool GetDhcpReqState() const; 56 57 void RemoteRegisterNetSupplier(); 58 void RemoteUnregisterNetSupplier(); 59 void RemoteUpdateNetLinkInfo(); 60 void RemoteUpdateNetSupplierInfo(); 61 62 void GetDumpInfo(std::string &info); 63 64 private: 65 enum ConnLinkState { REGISTERED, UNREGISTERED, LINK_AVAILABLE, LINK_UNAVAILABLE }; 66 void UpdateLinkInfo(); 67 void UpdateSupplierAvailable(); 68 void CreateLocalRoute(const std::string &iface, const std::vector<INetAddr> &ipAddrList, 69 const std::vector<INetAddr> &netMaskList); 70 std::string GetIpv4Prefix(const std::string &ipv4Addr, const std::vector<INetAddr> &netMaskList); 71 void GetTargetNetAddrWithSameFamily(const std::string &bySrcAddr, const std::vector<INetAddr> &fromAddrList, 72 INetAddr &targetNetAddr); 73 74 private: 75 ConnLinkState connLinkState_ = UNREGISTERED; 76 uint32_t netSupplier_ = 0; 77 std::string devName_; 78 bool linkUp_ = false; 79 bool dhcpReqState_ = false; 80 sptr<NetLinkInfo> linkInfo_ = nullptr; 81 sptr<NetSupplierInfo> netSupplierInfo_ = nullptr; 82 sptr<InterfaceConfiguration> ifCfg_ = nullptr; 83 std::set<NetCap> netCaps_; 84 NetBearType bearerType_ = BEARER_ETHERNET; 85 }; 86 } // namespace NetManagerStandard 87 } // namespace OHOS 88 #endif // DEV_INTERFACE_STATE_H 89