• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef INCLUDE_INTERFACE_MANAGER_H
17 #define INCLUDE_INTERFACE_MANAGER_H
18 
19 #include "interface_type.h"
20 #include <ostream>
21 #include <string>
22 #include <vector>
23 
24 namespace OHOS {
25 namespace nmd {
26 static const uint32_t INTERFACE_ERR_MAX_LEN = 256;
27 
28 class InterfaceManager {
29 public:
30     InterfaceManager() = default;
31     ~InterfaceManager() = default;
32     /**
33      * Set network device mtu
34      *
35      * @param interfaceName Network device name
36      * @param mtuValue Value of mtu
37      * @return Returns 0, set network device mtu successfully, otherwise it will fail
38      */
39     static int SetMtu(const char *interfaceName, const char *mtuValue);
40 
41     /**
42      * Get network device mtu
43      *
44      * @param interfaceName Network device name
45      * @return Returns value of mtu
46      */
47     static int GetMtu(const char *interfaceName);
48 
49     /**
50      * Add local IP address to network
51      *
52      * @param interfaceName Network device name
53      * @param addr Network IP address
54      * @param prefixLen Length of the network number of the subnet mask
55      * @return Returns 0, add local IP address to network successfully, otherwise it will fail
56      */
57     static int AddAddress(const char *interfaceName, const char *addr, int prefixLen);
58 
59     /**
60      * Delete local IP address to network
61      *
62      * @param interfaceName Network device name
63      * @param addr Network IP address
64      * @param prefixLen Length of the network number of the subnet mask
65      * @return Returns 0, delete local IP address to network successfully, otherwise it will fail
66      */
67     static int DelAddress(const char *interfaceName, const char *addr, int prefixLen);
68 
69     /**
70      * Get the network interface names
71      *
72      * @return Network interface names
73      */
74     static std::vector<std::string> GetInterfaceNames();
75 
76     /**
77      * Get the network interface config
78      *
79      * @param ifName Network device name
80      * @return Interface configuration parcel
81      */
82     static InterfaceConfigurationParcel GetIfaceConfig(const std::string &ifName);
83 
84     /**
85      * Set network interface config
86      *
87      * @param ifaceConfig Interface configuration parcel
88      * @return Returns 1, set network interface config successfully, otherwise it will fail
89      */
90     static int SetIfaceConfig(const nmd::InterfaceConfigurationParcel &ifaceConfig);
91 
92     /**
93      * Set network interface ip address
94      *
95      * @param ifaceName Network port device name
96      * @param ipAddress Ip address
97      * @return Returns 0, set IP address to network successfully, otherwise it will fail
98      */
99     static int SetIpAddress(const std::string &ifaceName, const std::string &ipAddress);
100 
101     /**
102      * Set iface up
103      *
104      * @param ifaceName Network port device name
105      * @return Returns 0, set up to network successfully, otherwise it will fail
106      */
107     static int SetIffUp(const std::string &ifaceName);
108 
109 private:
110     static int ModifyAddress(uint32_t action, const char *interfaceName, const char *addr, int prefixLen);
111 };
112 } // namespace nmd
113 } // namespace OHOS
114 #endif // INCLUDE_INTERFACE_MANAGER_H
115