• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SetLancfg(sptr<InterfaceConfiguration> &ifCfg);
46     void SetDhcpReqState(bool dhcpReqState);
47     void UpdateNetHttpProxy(const HttpProxy &httpProxy);
48     void UpdateLinkInfo(const sptr<StaticConfiguration> &config);
49     std::string GetDevName() const;
50     const std::set<NetCap> &GetNetCaps() const;
51     std::set<NetCap> GetNetCaps();
52     bool GetLinkUp() const;
53     sptr<NetLinkInfo> GetLinkInfo() const;
54     sptr<InterfaceConfiguration> GetIfcfg() const;
55     IPSetMode GetIPSetMode() const;
56     bool GetDhcpReqState() const;
57     bool IsLanIface();
58     void UpdateLanLinkInfo();
59     void UpdateLanLinkInfo(const sptr<StaticConfiguration> &config);
60 
61     void RemoteRegisterNetSupplier();
62     void RemoteUnregisterNetSupplier();
63     void RemoteUpdateNetLinkInfo();
64     void RemoteUpdateNetSupplierInfo();
65 
66     void GetDumpInfo(std::string &info);
67 
68 private:
69     enum ConnLinkState { REGISTERED, UNREGISTERED, LINK_AVAILABLE, LINK_UNAVAILABLE };
70     void UpdateLinkInfo();
71     void UpdateSupplierAvailable();
72     void CreateLocalRoute(const std::string &iface, const std::vector<INetAddr> &ipAddrList,
73                           const std::vector<INetAddr> &netMaskList);
74     std::string GetIpv4Prefix(const std::string &ipv4Addr, const std::vector<INetAddr> &netMaskList);
75     void GetTargetNetAddrWithSameFamily(const std::string &bySrcAddr, const std::vector<INetAddr> &fromAddrList,
76                                         INetAddr &targetNetAddr);
77     void GetRoutePrefixlen(const std::string &bySrcAddr, const std::vector<INetAddr> &fromAddrList,
78                            INetAddr &targetNetAddr);
79 
80 private:
81     ConnLinkState connLinkState_ = UNREGISTERED;
82     uint32_t netSupplier_ = 0;
83     std::string devName_;
84     bool linkUp_ = false;
85     bool dhcpReqState_ = false;
86     sptr<NetLinkInfo> linkInfo_ = nullptr;
87     sptr<NetSupplierInfo> netSupplierInfo_ = nullptr;
88     sptr<InterfaceConfiguration> ifCfg_ = nullptr;
89     std::set<NetCap> netCaps_;
90     NetBearType bearerType_ = BEARER_ETHERNET;
91 };
92 } // namespace NetManagerStandard
93 } // namespace OHOS
94 #endif // DEV_INTERFACE_STATE_H
95