1 /*
2  * Copyright (C) 2021-2022 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 OHOS_WIFI_IF_CONFIG_H
16 #define OHOS_WIFI_IF_CONFIG_H
17 
18 #include <memory>
19 #include "wifi_log.h"
20 
21 #ifdef OHOS_ARCH_LITE
22 #include "dhcp_c_api.h"
23 #endif
24 
25 namespace OHOS {
26 namespace Wifi {
27 typedef enum IpType {
28     IPTYPE_IPV4,
29     IPTYPE_IPV6,
30     IPTYPE_MIX,
31     IPTYPE_BUTT,
32 } IpType;
33 
34 class IfConfig {
35 public:
36     IfConfig();
37     ~IfConfig();
38 
39     static IfConfig &GetInstance();
40 
41     void FlushIpAddr(const std::string &ifName, const int &ipType);
42 
43     void AddIpAddr(const std::string &ifName, const std::string &ipAddr, const std::string &mask, const int &ipType);
44 
45     void SetProxy(bool isAuto, const std::string &proxy, const std::string &port, const std::string &noProxys,
46         const std::string &pac);
47 
48     bool ExecCommand(const std::vector<std::string> &vecCommandArg);
49 
50     bool GetIpAddr(const std::string& ifName, std::string& ipAddr);
51 
52 #ifdef OHOS_ARCH_LITE
53     /**
54      * @Description : Set the If Addr object
55      *
56      * @param dhcpInfo - dhcp information[in]
57      * @param ipType - ip type[in]
58      * @return int
59      */
60     int SetIfDnsAndRoute(const DhcpResult *dhcpInfo, int ipType, int instId = 0);
61 
62     void SetNetDns(const std::string &ifName, const std::string &dns1, const std::string &dns2);
63 
64     void AddIfRoute(const std::string &ifName, const std::string &ipAddr, const std::string &mask,
65         const std::string &gateWay, const int &ipType);
66 
67     void AddIpv4Route(
68         const std::string &ifName, const std::string &ipAddr, const std::string &mask, const std::string &gateWay);
69 
70     void AddIpv6Route(
71         const std::string &ifName, const std::string &ipAddr, const std::string &mask, const std::string &gateWay);
72 #endif
73 
74 private:
75     /**
76      * @Description : Check if the interface name is valid
77      */
78     bool CheckIfaceValid(const std::string& ifname);
79 };
80 }  // namespace Wifi
81 }  // namespace OHOS
82 #endif
83