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 #include "netsys_controller.h"
16
17 #include "net_conn_constants.h"
18 #include "net_conn_types.h"
19 #include "net_mgr_log_wrapper.h"
20 #include "netmanager_base_common_utils.h"
21 #include "netsys_controller_service_impl.h"
22 #include "i_net_dns_result_callback.h"
23 #include "i_net_dns_health_callback.h"
24
25 using namespace OHOS::NetManagerStandard::CommonUtils;
26 namespace OHOS {
27 namespace NetManagerStandard {
Init()28 void NetsysController::Init()
29 {
30 NETMGR_LOG_I("netsys Init");
31 if (initFlag_) {
32 NETMGR_LOG_I("netsys initialization is complete");
33 return;
34 }
35 netsysService_ = std::make_unique<NetsysControllerServiceImpl>().release();
36 netsysService_->Init();
37 initFlag_ = true;
38 }
39
GetInstance()40 NetsysController &NetsysController::GetInstance()
41 {
42 static NetsysController singleInstance_;
43 static std::mutex mutex_;
44 if (!singleInstance_.initFlag_) {
45 std::unique_lock<std::mutex> lock(mutex_);
46 if (!singleInstance_.initFlag_) {
47 singleInstance_.Init();
48 }
49 }
50 return singleInstance_;
51 }
52
SetInternetPermission(uint32_t uid,uint8_t allow)53 int32_t NetsysController::SetInternetPermission(uint32_t uid, uint8_t allow)
54 {
55 if (netsysService_ == nullptr) {
56 NETMGR_LOG_E("netsysService_ is null");
57 return NETSYS_NETSYSSERVICE_NULL;
58 }
59 return netsysService_->SetInternetPermission(uid, allow);
60 }
61
NetworkCreatePhysical(int32_t netId,int32_t permission)62 int32_t NetsysController::NetworkCreatePhysical(int32_t netId, int32_t permission)
63 {
64 NETMGR_LOG_D("Create Physical network: netId[%{public}d], permission[%{public}d]", netId, permission);
65 if (netsysService_ == nullptr) {
66 NETMGR_LOG_E("netsysService_ is null");
67 return NETSYS_NETSYSSERVICE_NULL;
68 }
69 return netsysService_->NetworkCreatePhysical(netId, permission);
70 }
71
NetworkCreateVirtual(int32_t netId,bool hasDns)72 int32_t NetsysController::NetworkCreateVirtual(int32_t netId, bool hasDns)
73 {
74 NETMGR_LOG_D("Create Virtual network: netId[%{public}d], hasDns[%{public}d]", netId, hasDns);
75 if (netsysService_ == nullptr) {
76 NETMGR_LOG_E("netsysService_ is null");
77 return NETSYS_NETSYSSERVICE_NULL;
78 }
79 return netsysService_->NetworkCreateVirtual(netId, hasDns);
80 }
81
NetworkDestroy(int32_t netId)82 int32_t NetsysController::NetworkDestroy(int32_t netId)
83 {
84 NETMGR_LOG_D("Destroy network: netId[%{public}d]", netId);
85 if (netsysService_ == nullptr) {
86 NETMGR_LOG_E("netsysService_ is null");
87 return NETSYS_NETSYSSERVICE_NULL;
88 }
89 return netsysService_->NetworkDestroy(netId);
90 }
91
NetworkAddUids(int32_t netId,const std::vector<int32_t> & beginUids,const std::vector<int32_t> & endUids)92 int32_t NetsysController::NetworkAddUids(int32_t netId, const std::vector<int32_t> &beginUids,
93 const std::vector<int32_t> &endUids)
94 {
95 NETMGR_LOG_D("Destroy network: netId[%{public}d]", netId);
96 if (netsysService_ == nullptr) {
97 NETMGR_LOG_E("netsysService_ is null");
98 return NETSYS_NETSYSSERVICE_NULL;
99 }
100 if (beginUids.size() != endUids.size()) {
101 NETMGR_LOG_E("beginUids and endUids size is mismatch");
102 return NETMANAGER_ERR_INTERNAL;
103 }
104 std::vector<UidRange> uidRanges;
105 for (size_t i = 0; i < beginUids.size(); i++) {
106 uidRanges.emplace_back(UidRange(beginUids[i], endUids[i]));
107 }
108 return netsysService_->NetworkAddUids(netId, uidRanges);
109 }
110
NetworkDelUids(int32_t netId,const std::vector<int32_t> & beginUids,const std::vector<int32_t> & endUids)111 int32_t NetsysController::NetworkDelUids(int32_t netId, const std::vector<int32_t> &beginUids,
112 const std::vector<int32_t> &endUids)
113 {
114 NETMGR_LOG_D("Destroy network: netId[%{public}d]", netId);
115 if (netsysService_ == nullptr) {
116 NETMGR_LOG_E("netsysService_ is null");
117 return NETSYS_NETSYSSERVICE_NULL;
118 }
119 if (beginUids.size() != endUids.size()) {
120 NETMGR_LOG_E("beginUids and endUids size is mismatch");
121 return NETMANAGER_ERR_INTERNAL;
122 }
123 std::vector<UidRange> uidRanges;
124 for (size_t i = 0; i < beginUids.size(); i++) {
125 uidRanges.emplace_back(UidRange(beginUids[i], endUids[i]));
126 }
127 return netsysService_->NetworkDelUids(netId, uidRanges);
128 }
129
NetworkAddInterface(int32_t netId,const std::string & iface)130 int32_t NetsysController::NetworkAddInterface(int32_t netId, const std::string &iface)
131 {
132 NETMGR_LOG_D("Add network interface: netId[%{public}d], iface[%{public}s]", netId, iface.c_str());
133 if (netsysService_ == nullptr) {
134 NETMGR_LOG_E("netsysService_ is null");
135 return NETSYS_NETSYSSERVICE_NULL;
136 }
137 return netsysService_->NetworkAddInterface(netId, iface);
138 }
139
NetworkRemoveInterface(int32_t netId,const std::string & iface)140 int32_t NetsysController::NetworkRemoveInterface(int32_t netId, const std::string &iface)
141 {
142 NETMGR_LOG_D("Remove network interface: netId[%{public}d], iface[%{public}s]", netId, iface.c_str());
143 if (netsysService_ == nullptr) {
144 NETMGR_LOG_E("netsysService_ is null");
145 return NETSYS_NETSYSSERVICE_NULL;
146 }
147 return netsysService_->NetworkRemoveInterface(netId, iface);
148 }
149
NetworkAddRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)150 int32_t NetsysController::NetworkAddRoute(int32_t netId, const std::string &ifName, const std::string &destination,
151 const std::string &nextHop)
152 {
153 NETMGR_LOG_D("Add Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]",
154 netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
155 if (netsysService_ == nullptr) {
156 NETMGR_LOG_E("netsysService_ is null");
157 return NETSYS_NETSYSSERVICE_NULL;
158 }
159 return netsysService_->NetworkAddRoute(netId, ifName, destination, nextHop);
160 }
161
NetworkRemoveRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)162 int32_t NetsysController::NetworkRemoveRoute(int32_t netId, const std::string &ifName, const std::string &destination,
163 const std::string &nextHop)
164 {
165 NETMGR_LOG_D("Remove Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]",
166 netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
167 if (netsysService_ == nullptr) {
168 NETMGR_LOG_E("netsysService_ is null");
169 return NETSYS_NETSYSSERVICE_NULL;
170 }
171 return netsysService_->NetworkRemoveRoute(netId, ifName, destination, nextHop);
172 }
173
GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel & cfg)174 int32_t NetsysController::GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel &cfg)
175 {
176 NETMGR_LOG_D("get interface config");
177 if (netsysService_ == nullptr) {
178 NETMGR_LOG_E("netsysService_ is null");
179 return NETSYS_NETSYSSERVICE_NULL;
180 }
181 return netsysService_->GetInterfaceConfig(cfg);
182 }
183
SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel & cfg)184 int32_t NetsysController::SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel &cfg)
185 {
186 NETMGR_LOG_D("set interface config");
187 if (netsysService_ == nullptr) {
188 NETMGR_LOG_E("netsysService_ is null");
189 return NETSYS_NETSYSSERVICE_NULL;
190 }
191 return netsysService_->SetInterfaceConfig(cfg);
192 }
193
SetInterfaceDown(const std::string & iface)194 int32_t NetsysController::SetInterfaceDown(const std::string &iface)
195 {
196 NETMGR_LOG_D("Set interface down: iface[%{public}s]", iface.c_str());
197 if (netsysService_ == nullptr) {
198 NETMGR_LOG_E("netsysService_ is null");
199 return NETSYS_NETSYSSERVICE_NULL;
200 }
201 return netsysService_->SetInterfaceDown(iface);
202 }
203
SetInterfaceUp(const std::string & iface)204 int32_t NetsysController::SetInterfaceUp(const std::string &iface)
205 {
206 NETMGR_LOG_D("Set interface up: iface[%{public}s]", iface.c_str());
207 if (netsysService_ == nullptr) {
208 NETMGR_LOG_E("netsysService_ is null");
209 return NETSYS_NETSYSSERVICE_NULL;
210 }
211 return netsysService_->SetInterfaceUp(iface);
212 }
213
ClearInterfaceAddrs(const std::string & ifName)214 void NetsysController::ClearInterfaceAddrs(const std::string &ifName)
215 {
216 NETMGR_LOG_D("Clear addrs: ifName[%{public}s]", ifName.c_str());
217 if (netsysService_ == nullptr) {
218 NETMGR_LOG_E("netsysService_ is null");
219 return;
220 }
221 return netsysService_->ClearInterfaceAddrs(ifName);
222 }
223
GetInterfaceMtu(const std::string & ifName)224 int32_t NetsysController::GetInterfaceMtu(const std::string &ifName)
225 {
226 NETMGR_LOG_D("Get mtu: ifName[%{public}s]", ifName.c_str());
227 if (netsysService_ == nullptr) {
228 NETMGR_LOG_E("netsysService_ is null");
229 return NETSYS_NETSYSSERVICE_NULL;
230 }
231 return netsysService_->GetInterfaceMtu(ifName);
232 }
233
SetInterfaceMtu(const std::string & ifName,int32_t mtu)234 int32_t NetsysController::SetInterfaceMtu(const std::string &ifName, int32_t mtu)
235 {
236 NETMGR_LOG_D("Set mtu: ifName[%{public}s], mtu[%{public}d]", ifName.c_str(), mtu);
237 if (netsysService_ == nullptr) {
238 NETMGR_LOG_E("netsysService_ is null");
239 return NETSYS_NETSYSSERVICE_NULL;
240 }
241 return netsysService_->SetInterfaceMtu(ifName, mtu);
242 }
243
SetTcpBufferSizes(const std::string & tcpBufferSizes)244 int32_t NetsysController::SetTcpBufferSizes(const std::string &tcpBufferSizes)
245 {
246 NETMGR_LOG_D("Set tcp buffer sizes: tcpBufferSizes[%{public}s]", tcpBufferSizes.c_str());
247 if (netsysService_ == nullptr) {
248 NETMGR_LOG_E("netsysService_ is null");
249 return NETSYS_NETSYSSERVICE_NULL;
250 }
251 return netsysService_->SetTcpBufferSizes(tcpBufferSizes);
252 }
253
AddInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)254 int32_t NetsysController::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
255 int32_t prefixLength)
256 {
257 NETMGR_LOG_D("Add address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]", ifName.c_str(),
258 ToAnonymousIp(ipAddr).c_str(), prefixLength);
259 if (netsysService_ == nullptr) {
260 NETMGR_LOG_E("netsysService_ is null");
261 return NETSYS_NETSYSSERVICE_NULL;
262 }
263 return netsysService_->AddInterfaceAddress(ifName, ipAddr, prefixLength);
264 }
265
DelInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)266 int32_t NetsysController::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
267 int32_t prefixLength)
268 {
269 NETMGR_LOG_D("Delete address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]", ifName.c_str(),
270 ToAnonymousIp(ipAddr).c_str(), prefixLength);
271 if (netsysService_ == nullptr) {
272 NETMGR_LOG_E("netsysService_ is null");
273 return NETSYS_NETSYSSERVICE_NULL;
274 }
275 return netsysService_->DelInterfaceAddress(ifName, ipAddr, prefixLength);
276 }
277
InterfaceSetIpAddress(const std::string & ifaceName,const std::string & ipAddress)278 int32_t NetsysController::InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress)
279 {
280 NETMGR_LOG_D("Set Ip Address: ifName[%{public}s]", ifaceName.c_str());
281 if (netsysService_ == nullptr) {
282 NETMGR_LOG_E("netsysService_ is null");
283 return NETSYS_NETSYSSERVICE_NULL;
284 }
285 return netsysService_->InterfaceSetIpAddress(ifaceName, ipAddress);
286 }
287
InterfaceSetIffUp(const std::string & ifaceName)288 int32_t NetsysController::InterfaceSetIffUp(const std::string &ifaceName)
289 {
290 NETMGR_LOG_D("Set Iff Up: ifName[%{public}s]", ifaceName.c_str());
291 if (netsysService_ == nullptr) {
292 NETMGR_LOG_E("netsysService_ is null");
293 return NETSYS_NETSYSSERVICE_NULL;
294 }
295 return netsysService_->InterfaceSetIffUp(ifaceName);
296 }
297
SetResolverConfig(uint16_t netId,uint16_t baseTimeoutMsec,uint8_t retryCount,const std::vector<std::string> & servers,const std::vector<std::string> & domains)298 int32_t NetsysController::SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
299 const std::vector<std::string> &servers,
300 const std::vector<std::string> &domains)
301 {
302 NETMGR_LOG_D("Set resolver config: netId[%{public}d]", netId);
303 if (netsysService_ == nullptr) {
304 NETMGR_LOG_E("netsysService_ is null");
305 return NETSYS_NETSYSSERVICE_NULL;
306 }
307 return netsysService_->SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
308 }
309
GetResolverConfig(uint16_t netId,std::vector<std::string> & servers,std::vector<std::string> & domains,uint16_t & baseTimeoutMsec,uint8_t & retryCount)310 int32_t NetsysController::GetResolverConfig(uint16_t netId, std::vector<std::string> &servers,
311 std::vector<std::string> &domains, uint16_t &baseTimeoutMsec,
312 uint8_t &retryCount)
313 {
314 NETMGR_LOG_D("Get resolver config: netId[%{public}d]", netId);
315 if (netsysService_ == nullptr) {
316 NETMGR_LOG_E("netsysService_ is null");
317 return NETSYS_NETSYSSERVICE_NULL;
318 }
319 return netsysService_->GetResolverConfig(netId, servers, domains, baseTimeoutMsec, retryCount);
320 }
321
CreateNetworkCache(uint16_t netId)322 int32_t NetsysController::CreateNetworkCache(uint16_t netId)
323 {
324 NETMGR_LOG_D("create dns cache: netId[%{public}d]", netId);
325 if (netsysService_ == nullptr) {
326 NETMGR_LOG_E("netsysService_ is null");
327 return NETSYS_NETSYSSERVICE_NULL;
328 }
329 return netsysService_->CreateNetworkCache(netId);
330 }
331
DestroyNetworkCache(uint16_t netId)332 int32_t NetsysController::DestroyNetworkCache(uint16_t netId)
333 {
334 NETMGR_LOG_D("Destroy dns cache: netId[%{public}d]", netId);
335 if (netsysService_ == nullptr) {
336 NETMGR_LOG_E("netsysService_ is null");
337 return NETSYS_NETSYSSERVICE_NULL;
338 }
339 return netsysService_->DestroyNetworkCache(netId);
340 }
341
GetAddrInfo(const std::string & hostName,const std::string & serverName,const AddrInfo & hints,uint16_t netId,std::vector<AddrInfo> & res)342 int32_t NetsysController::GetAddrInfo(const std::string &hostName, const std::string &serverName, const AddrInfo &hints,
343 uint16_t netId, std::vector<AddrInfo> &res)
344 {
345 if (netsysService_ == nullptr) {
346 NETMGR_LOG_E("netsysService_ is null");
347 return NET_CONN_ERR_SERVICE_UPDATE_NET_LINK_INFO_FAIL;
348 }
349 return netsysService_->GetAddrInfo(hostName, serverName, hints, netId, res);
350 }
351
GetNetworkSharingTraffic(const std::string & downIface,const std::string & upIface,nmd::NetworkSharingTraffic & traffic)352 int32_t NetsysController::GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface,
353 nmd::NetworkSharingTraffic &traffic)
354 {
355 NETMGR_LOG_D("NetsysController GetNetworkSharingTraffic");
356 if (netsysService_ == nullptr) {
357 NETMGR_LOG_E("netsysService_ is null");
358 return NETSYS_NETSYSSERVICE_NULL;
359 }
360 return netsysService_->GetNetworkSharingTraffic(downIface, upIface, traffic);
361 }
362
GetCellularRxBytes()363 int64_t NetsysController::GetCellularRxBytes()
364 {
365 NETMGR_LOG_D("NetsysController GetCellularRxBytes");
366 if (netsysService_ == nullptr) {
367 NETMGR_LOG_E("netsysService_ is null");
368 return NETSYS_NETSYSSERVICE_NULL;
369 }
370 return netsysService_->GetCellularRxBytes();
371 }
372
GetCellularTxBytes()373 int64_t NetsysController::GetCellularTxBytes()
374 {
375 NETMGR_LOG_D("NetsysController GetCellularTxBytes");
376 if (netsysService_ == nullptr) {
377 NETMGR_LOG_E("netsysService_ is null");
378 return NETSYS_NETSYSSERVICE_NULL;
379 }
380 return netsysService_->GetCellularTxBytes();
381 }
382
GetAllRxBytes()383 int64_t NetsysController::GetAllRxBytes()
384 {
385 NETMGR_LOG_D("NetsysController GetAllRxBytes");
386 if (netsysService_ == nullptr) {
387 NETMGR_LOG_E("netsysService_ is null");
388 return NETSYS_NETSYSSERVICE_NULL;
389 }
390 return netsysService_->GetAllRxBytes();
391 }
392
GetAllTxBytes()393 int64_t NetsysController::GetAllTxBytes()
394 {
395 NETMGR_LOG_D("NetsysController GetAllTxBytes");
396 if (netsysService_ == nullptr) {
397 NETMGR_LOG_E("netsysService_ is null");
398 return NETSYS_NETSYSSERVICE_NULL;
399 }
400 return netsysService_->GetAllTxBytes();
401 }
402
GetUidRxBytes(uint32_t uid)403 int64_t NetsysController::GetUidRxBytes(uint32_t uid)
404 {
405 NETMGR_LOG_D("NetsysController GetUidRxBytes");
406 if (netsysService_ == nullptr) {
407 NETMGR_LOG_E("netsysService_ is null");
408 return NETSYS_NETSYSSERVICE_NULL;
409 }
410 return netsysService_->GetUidRxBytes(uid);
411 }
412
GetUidTxBytes(uint32_t uid)413 int64_t NetsysController::GetUidTxBytes(uint32_t uid)
414 {
415 NETMGR_LOG_D("NetsysController GetUidTxBytes");
416 if (netsysService_ == nullptr) {
417 NETMGR_LOG_E("netsysService_ is null");
418 return NETSYS_NETSYSSERVICE_NULL;
419 }
420 return netsysService_->GetUidTxBytes(uid);
421 }
422
GetUidOnIfaceRxBytes(uint32_t uid,const std::string & interfaceName)423 int64_t NetsysController::GetUidOnIfaceRxBytes(uint32_t uid, const std::string &interfaceName)
424 {
425 NETMGR_LOG_D("NetsysController GetUidOnIfaceRxBytes");
426 if (netsysService_ == nullptr) {
427 NETMGR_LOG_E("netsysService_ is null");
428 return NETSYS_NETSYSSERVICE_NULL;
429 }
430 return netsysService_->GetUidOnIfaceRxBytes(uid, interfaceName);
431 }
432
GetUidOnIfaceTxBytes(uint32_t uid,const std::string & interfaceName)433 int64_t NetsysController::GetUidOnIfaceTxBytes(uint32_t uid, const std::string &interfaceName)
434 {
435 NETMGR_LOG_D("NetsysController GetUidOnIfaceTxBytes");
436 if (netsysService_ == nullptr) {
437 NETMGR_LOG_E("netsysService_ is null");
438 return NETSYS_NETSYSSERVICE_NULL;
439 }
440 return netsysService_->GetUidOnIfaceTxBytes(uid, interfaceName);
441 }
442
GetIfaceRxBytes(const std::string & interfaceName)443 int64_t NetsysController::GetIfaceRxBytes(const std::string &interfaceName)
444 {
445 NETMGR_LOG_D("NetsysController GetIfaceRxBytes");
446 if (netsysService_ == nullptr) {
447 NETMGR_LOG_E("netsysService_ is null");
448 return NETSYS_NETSYSSERVICE_NULL;
449 }
450 return netsysService_->GetIfaceRxBytes(interfaceName);
451 }
452
GetIfaceTxBytes(const std::string & interfaceName)453 int64_t NetsysController::GetIfaceTxBytes(const std::string &interfaceName)
454 {
455 NETMGR_LOG_D("NetsysController GetIfaceTxBytes");
456 if (netsysService_ == nullptr) {
457 NETMGR_LOG_E("netsysService_ is null");
458 return NETSYS_NETSYSSERVICE_NULL;
459 }
460 return netsysService_->GetIfaceTxBytes(interfaceName);
461 }
462
InterfaceGetList()463 std::vector<std::string> NetsysController::InterfaceGetList()
464 {
465 NETMGR_LOG_D("NetsysController InterfaceGetList");
466 if (netsysService_ == nullptr) {
467 NETMGR_LOG_E("netsysService_ is null");
468 return {};
469 }
470 return netsysService_->InterfaceGetList();
471 }
472
UidGetList()473 std::vector<std::string> NetsysController::UidGetList()
474 {
475 NETMGR_LOG_D("NetsysController UidGetList");
476 if (netsysService_ == nullptr) {
477 NETMGR_LOG_E("netsysService_ is null");
478 return {};
479 }
480 return netsysService_->UidGetList();
481 }
482
GetIfaceRxPackets(const std::string & interfaceName)483 int64_t NetsysController::GetIfaceRxPackets(const std::string &interfaceName)
484 {
485 NETMGR_LOG_D("NetsysController GetIfaceRxPackets");
486 if (netsysService_ == nullptr) {
487 NETMGR_LOG_E("netsysService_ is null");
488 return NETSYS_NETSYSSERVICE_NULL;
489 }
490 return netsysService_->GetIfaceRxPackets(interfaceName);
491 }
492
GetIfaceTxPackets(const std::string & interfaceName)493 int64_t NetsysController::GetIfaceTxPackets(const std::string &interfaceName)
494 {
495 NETMGR_LOG_D("NetsysController GetIfaceTxPackets");
496 if (netsysService_ == nullptr) {
497 NETMGR_LOG_E("netsysService_ is null");
498 return NETSYS_NETSYSSERVICE_NULL;
499 }
500 return netsysService_->GetIfaceTxPackets(interfaceName);
501 }
502
SetDefaultNetWork(int32_t netId)503 int32_t NetsysController::SetDefaultNetWork(int32_t netId)
504 {
505 NETMGR_LOG_D("Set DefaultNetWork: netId[%{public}d]", netId);
506 if (netsysService_ == nullptr) {
507 NETMGR_LOG_E("netsysService_ is null");
508 return NETSYS_NETSYSSERVICE_NULL;
509 }
510 return netsysService_->SetDefaultNetWork(netId);
511 }
512
ClearDefaultNetWorkNetId()513 int32_t NetsysController::ClearDefaultNetWorkNetId()
514 {
515 NETMGR_LOG_D("ClearDefaultNetWorkNetId");
516 if (netsysService_ == nullptr) {
517 NETMGR_LOG_E("netsysService_ is null");
518 return NETSYS_NETSYSSERVICE_NULL;
519 }
520 return netsysService_->ClearDefaultNetWorkNetId();
521 }
522
BindSocket(int32_t socketFd,uint32_t netId)523 int32_t NetsysController::BindSocket(int32_t socketFd, uint32_t netId)
524 {
525 NETMGR_LOG_D("NetsysController::BindSocket: netId = [%{public}u]", netId);
526 if (netsysService_ == nullptr) {
527 NETMGR_LOG_E("netsysService_ is null");
528 return NETSYS_NETSYSSERVICE_NULL;
529 }
530 return netsysService_->BindSocket(socketFd, netId);
531 }
532
IpEnableForwarding(const std::string & requestor)533 int32_t NetsysController::IpEnableForwarding(const std::string &requestor)
534 {
535 NETMGR_LOG_D("IpEnableForwarding: requestor[%{public}s]", requestor.c_str());
536 if (netsysService_ == nullptr) {
537 NETMGR_LOG_E("netsysService_ is null");
538 return NETSYS_NETSYSSERVICE_NULL;
539 }
540 return netsysService_->IpEnableForwarding(requestor);
541 }
542
IpDisableForwarding(const std::string & requestor)543 int32_t NetsysController::IpDisableForwarding(const std::string &requestor)
544 {
545 NETMGR_LOG_D("IpDisableForwarding: requestor[%{public}s]", requestor.c_str());
546 if (netsysService_ == nullptr) {
547 NETMGR_LOG_E("netsysService_ is null");
548 return NETSYS_NETSYSSERVICE_NULL;
549 }
550 return netsysService_->IpDisableForwarding(requestor);
551 }
552
EnableNat(const std::string & downstreamIface,const std::string & upstreamIface)553 int32_t NetsysController::EnableNat(const std::string &downstreamIface, const std::string &upstreamIface)
554 {
555 NETMGR_LOG_D("MockNetsysNativeClient EnableNat: intIface[%{public}s] intIface[%{public}s]", downstreamIface.c_str(),
556 upstreamIface.c_str());
557 if (netsysService_ == nullptr) {
558 NETMGR_LOG_E("netsysService_ is null");
559 return NETSYS_NETSYSSERVICE_NULL;
560 }
561 return netsysService_->EnableNat(downstreamIface, upstreamIface);
562 }
563
DisableNat(const std::string & downstreamIface,const std::string & upstreamIface)564 int32_t NetsysController::DisableNat(const std::string &downstreamIface, const std::string &upstreamIface)
565 {
566 NETMGR_LOG_D("MockNetsysNativeClient DisableNat: intIface[%{public}s] intIface[%{public}s]",
567 downstreamIface.c_str(), upstreamIface.c_str());
568 if (netsysService_ == nullptr) {
569 NETMGR_LOG_E("netsysService_ is null");
570 return NETSYS_NETSYSSERVICE_NULL;
571 }
572 return netsysService_->DisableNat(downstreamIface, upstreamIface);
573 }
574
IpfwdAddInterfaceForward(const std::string & fromIface,const std::string & toIface)575 int32_t NetsysController::IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface)
576 {
577 NETMGR_LOG_D("IpfwdAddInterfaceForward: fromIface[%{public}s], toIface[%{public}s]", fromIface.c_str(),
578 toIface.c_str());
579 if (netsysService_ == nullptr) {
580 NETMGR_LOG_E("netsysService_ is null");
581 return NETSYS_NETSYSSERVICE_NULL;
582 }
583 return netsysService_->IpfwdAddInterfaceForward(fromIface, toIface);
584 }
585
IpfwdRemoveInterfaceForward(const std::string & fromIface,const std::string & toIface)586 int32_t NetsysController::IpfwdRemoveInterfaceForward(const std::string &fromIface, const std::string &toIface)
587 {
588 NETMGR_LOG_D("IpfwdRemoveInterfaceForward: fromIface[%{public}s], toIface[%{public}s]", fromIface.c_str(),
589 toIface.c_str());
590 if (netsysService_ == nullptr) {
591 NETMGR_LOG_E("netsysService_ is null");
592 return NETSYS_NETSYSSERVICE_NULL;
593 }
594 return netsysService_->IpfwdRemoveInterfaceForward(fromIface, toIface);
595 }
596
ShareDnsSet(uint16_t netId)597 int32_t NetsysController::ShareDnsSet(uint16_t netId)
598 {
599 NETMGR_LOG_D("ShareDnsSet: netId[%{public}d]", netId);
600 if (netsysService_ == nullptr) {
601 NETMGR_LOG_E("netsysService_ is null");
602 return NETSYS_NETSYSSERVICE_NULL;
603 }
604 return netsysService_->ShareDnsSet(netId);
605 }
606
StartDnsProxyListen()607 int32_t NetsysController::StartDnsProxyListen()
608 {
609 NETMGR_LOG_D("NetsysController::StartDnsProxyListen");
610 if (netsysService_ == nullptr) {
611 NETMGR_LOG_E("netsysService_ is null");
612 return NETSYS_NETSYSSERVICE_NULL;
613 }
614 return netsysService_->StartDnsProxyListen();
615 }
616
StopDnsProxyListen()617 int32_t NetsysController::StopDnsProxyListen()
618 {
619 NETMGR_LOG_D("NetsysController::StopDnsProxyListen");
620 if (netsysService_ == nullptr) {
621 NETMGR_LOG_E("netsysService_ is null");
622 return NETSYS_NETSYSSERVICE_NULL;
623 }
624 return netsysService_->StopDnsProxyListen();
625 }
626
RegisterNetsysNotifyCallback(const NetsysNotifyCallback & callback)627 int32_t NetsysController::RegisterNetsysNotifyCallback(const NetsysNotifyCallback &callback)
628 {
629 if (netsysService_ == nullptr) {
630 NETMGR_LOG_E("netsysService_ is null");
631 return NETSYS_NETSYSSERVICE_NULL;
632 }
633 return netsysService_->RegisterNetsysNotifyCallback(callback);
634 }
635
BindNetworkServiceVpn(int32_t socketFd)636 int32_t NetsysController::BindNetworkServiceVpn(int32_t socketFd)
637 {
638 NETMGR_LOG_D("NetsysController::BindNetworkServiceVpn: socketFd[%{public}d]", socketFd);
639 if (socketFd <= 0) {
640 NETMGR_LOG_E("socketFd is null");
641 return NETSYS_ERR_VPN;
642 }
643 if (netsysService_ == nullptr) {
644 NETMGR_LOG_E("netsysService_ is null");
645 return NETSYS_NETSYSSERVICE_NULL;
646 }
647 return netsysService_->BindNetworkServiceVpn(socketFd);
648 }
649
EnableVirtualNetIfaceCard(int32_t socketFd,struct ifreq & ifRequest,int32_t & ifaceFd)650 int32_t NetsysController::EnableVirtualNetIfaceCard(int32_t socketFd, struct ifreq &ifRequest, int32_t &ifaceFd)
651 {
652 NETMGR_LOG_D("NetsysController::EnableVirtualNetIfaceCard: socketFd[%{public}d]", socketFd);
653 if (socketFd <= 0) {
654 NETMGR_LOG_E("socketFd is null");
655 return NETSYS_ERR_VPN;
656 }
657 if (netsysService_ == nullptr) {
658 NETMGR_LOG_E("netsysService_ is null");
659 return NETSYS_NETSYSSERVICE_NULL;
660 }
661 return netsysService_->EnableVirtualNetIfaceCard(socketFd, ifRequest, ifaceFd);
662 }
663
SetIpAddress(int32_t socketFd,const std::string & ipAddress,int32_t prefixLen,struct ifreq & ifRequest)664 int32_t NetsysController::SetIpAddress(int32_t socketFd, const std::string &ipAddress, int32_t prefixLen,
665 struct ifreq &ifRequest)
666 {
667 NETMGR_LOG_D("NetsysController::set addr");
668 if ((socketFd <= 0) || (ipAddress.length() == 0) || (ipAddress.length() > MAX_IPV4_ADDRESS_LEN) ||
669 (prefixLen <= 0) || (prefixLen > MAX_IPV4_ADDRESS_LEN)) {
670 NETMGR_LOG_E(
671 "The paramemters of SetIpAddress is failed, socketFd[%{public}d], "
672 "ipAddress[%{public}s], prefixLen[%{public}d].",
673 socketFd, ToAnonymousIp(ipAddress).c_str(), prefixLen);
674 return NETSYS_ERR_VPN;
675 }
676 if (netsysService_ == nullptr) {
677 NETMGR_LOG_E("netsysService_ is null");
678 return NETSYS_NETSYSSERVICE_NULL;
679 }
680 return netsysService_->SetIpAddress(socketFd, ipAddress, prefixLen, ifRequest);
681 }
682
SetBlocking(int32_t ifaceFd,bool isBlock)683 int32_t NetsysController::SetBlocking(int32_t ifaceFd, bool isBlock)
684 {
685 NETMGR_LOG_D("NetsysController::SetBlocking: ifaceFd[%{public}d], isBlock[%{public}d]", ifaceFd, isBlock);
686 if (netsysService_ == nullptr) {
687 NETMGR_LOG_E("netsysService_ is null");
688 return NETSYS_NETSYSSERVICE_NULL;
689 }
690 return netsysService_->SetBlocking(ifaceFd, isBlock);
691 }
692
StartDhcpClient(const std::string & iface,bool bIpv6)693 int32_t NetsysController::StartDhcpClient(const std::string &iface, bool bIpv6)
694 {
695 NETMGR_LOG_D("NetsysController::StartDhcpClient: iface[%{public}s], bIpv6[%{public}d]", iface.c_str(), bIpv6);
696 if (netsysService_ == nullptr) {
697 NETMGR_LOG_E("netsysService_ is null");
698 return NETSYS_NETSYSSERVICE_NULL;
699 }
700 return netsysService_->StartDhcpClient(iface, bIpv6);
701 }
702
StopDhcpClient(const std::string & iface,bool bIpv6)703 int32_t NetsysController::StopDhcpClient(const std::string &iface, bool bIpv6)
704 {
705 NETMGR_LOG_D("NetsysController::SetBlocking: iface[%{public}s], bIpv6[%{public}d]", iface.c_str(), bIpv6);
706 if (netsysService_ == nullptr) {
707 NETMGR_LOG_E("netsysService_ is null");
708 return NETSYS_NETSYSSERVICE_NULL;
709 }
710 return netsysService_->StopDhcpClient(iface, bIpv6);
711 }
712
RegisterCallback(sptr<NetsysControllerCallback> callback)713 int32_t NetsysController::RegisterCallback(sptr<NetsysControllerCallback> callback)
714 {
715 NETMGR_LOG_D("NetsysController::RegisterCallback");
716 return netsysService_->RegisterCallback(callback);
717 }
718
StartDhcpService(const std::string & iface,const std::string & ipv4addr)719 int32_t NetsysController::StartDhcpService(const std::string &iface, const std::string &ipv4addr)
720 {
721 NETMGR_LOG_D("NetsysController::StartDhcpService: iface[%{public}s], ipv4addr[%{public}s]", iface.c_str(),
722 ToAnonymousIp(ipv4addr).c_str());
723 if (netsysService_ == nullptr) {
724 NETMGR_LOG_E("netsysService_ is null");
725 return NETSYS_NETSYSSERVICE_NULL;
726 }
727 return netsysService_->StartDhcpService(iface, ipv4addr);
728 }
729
StopDhcpService(const std::string & iface)730 int32_t NetsysController::StopDhcpService(const std::string &iface)
731 {
732 NETMGR_LOG_D("NetsysController::StopDhcpService: ifaceFd[%{public}s]", iface.c_str());
733 if (netsysService_ == nullptr) {
734 NETMGR_LOG_E("netsysService_ is null");
735 return NETSYS_NETSYSSERVICE_NULL;
736 }
737 return netsysService_->StopDhcpService(iface);
738 }
739
BandwidthEnableDataSaver(bool enable)740 int32_t NetsysController::BandwidthEnableDataSaver(bool enable)
741 {
742 NETMGR_LOG_D("NetsysController::BandwidthEnableDataSaver: enable=%{public}d", enable);
743 if (netsysService_ == nullptr) {
744 NETMGR_LOG_E("netsysService_ is null");
745 return NETSYS_NETSYSSERVICE_NULL;
746 }
747 return netsysService_->BandwidthEnableDataSaver(enable);
748 }
749
BandwidthSetIfaceQuota(const std::string & ifName,int64_t bytes)750 int32_t NetsysController::BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes)
751 {
752 NETMGR_LOG_D("NetsysController::BandwidthSetIfaceQuota: ifName=%{public}s", ifName.c_str());
753 if (netsysService_ == nullptr) {
754 NETMGR_LOG_E("netsysService_ is null");
755 return NETSYS_NETSYSSERVICE_NULL;
756 }
757 return netsysService_->BandwidthSetIfaceQuota(ifName, bytes);
758 }
759
BandwidthRemoveIfaceQuota(const std::string & ifName)760 int32_t NetsysController::BandwidthRemoveIfaceQuota(const std::string &ifName)
761 {
762 NETMGR_LOG_D("NetsysController::BandwidthRemoveIfaceQuota: ifName=%{public}s", ifName.c_str());
763 if (netsysService_ == nullptr) {
764 NETMGR_LOG_E("netsysService_ is null");
765 return NETSYS_NETSYSSERVICE_NULL;
766 }
767 return netsysService_->BandwidthRemoveIfaceQuota(ifName);
768 }
769
BandwidthAddDeniedList(uint32_t uid)770 int32_t NetsysController::BandwidthAddDeniedList(uint32_t uid)
771 {
772 NETMGR_LOG_D("NetsysController::BandwidthAddDeniedList: uid=%{public}d", uid);
773 if (netsysService_ == nullptr) {
774 NETMGR_LOG_E("netsysService_ is null");
775 return NETSYS_NETSYSSERVICE_NULL;
776 }
777 return netsysService_->BandwidthAddDeniedList(uid);
778 }
779
BandwidthRemoveDeniedList(uint32_t uid)780 int32_t NetsysController::BandwidthRemoveDeniedList(uint32_t uid)
781 {
782 NETMGR_LOG_D("NetsysController::BandwidthRemoveDeniedList: uid=%{public}d", uid);
783 if (netsysService_ == nullptr) {
784 NETMGR_LOG_E("netsysService_ is null");
785 return NETSYS_NETSYSSERVICE_NULL;
786 }
787 return netsysService_->BandwidthRemoveDeniedList(uid);
788 }
789
BandwidthAddAllowedList(uint32_t uid)790 int32_t NetsysController::BandwidthAddAllowedList(uint32_t uid)
791 {
792 NETMGR_LOG_D("NetsysController::BandwidthAddAllowedList: uid=%{public}d", uid);
793 if (netsysService_ == nullptr) {
794 NETMGR_LOG_E("netsysService_ is null");
795 return NETSYS_NETSYSSERVICE_NULL;
796 }
797 return netsysService_->BandwidthAddAllowedList(uid);
798 }
799
BandwidthRemoveAllowedList(uint32_t uid)800 int32_t NetsysController::BandwidthRemoveAllowedList(uint32_t uid)
801 {
802 NETMGR_LOG_D("NetsysController::BandwidthRemoveAllowedList: uid=%{public}d", uid);
803 if (netsysService_ == nullptr) {
804 NETMGR_LOG_E("netsysService_ is null");
805 return NETSYS_NETSYSSERVICE_NULL;
806 }
807 return netsysService_->BandwidthRemoveAllowedList(uid);
808 }
809
FirewallSetUidsAllowedListChain(uint32_t chain,const std::vector<uint32_t> & uids)810 int32_t NetsysController::FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
811 {
812 NETMGR_LOG_D("NetsysController::FirewallSetUidsAllowedListChain: chain=%{public}d", chain);
813 if (netsysService_ == nullptr) {
814 NETMGR_LOG_E("netsysService_ is null");
815 return NETSYS_NETSYSSERVICE_NULL;
816 }
817 return netsysService_->FirewallSetUidsAllowedListChain(chain, uids);
818 }
819
FirewallSetUidsDeniedListChain(uint32_t chain,const std::vector<uint32_t> & uids)820 int32_t NetsysController::FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
821 {
822 NETMGR_LOG_D("NetsysController::FirewallSetUidsDeniedListChain: chain=%{public}d", chain);
823 if (netsysService_ == nullptr) {
824 NETMGR_LOG_E("netsysService_ is null");
825 return NETSYS_NETSYSSERVICE_NULL;
826 }
827 return netsysService_->FirewallSetUidsDeniedListChain(chain, uids);
828 }
829
FirewallEnableChain(uint32_t chain,bool enable)830 int32_t NetsysController::FirewallEnableChain(uint32_t chain, bool enable)
831 {
832 NETMGR_LOG_D("NetsysController::FirewallEnableChain: chain=%{public}d, enable=%{public}d", chain, enable);
833 if (netsysService_ == nullptr) {
834 NETMGR_LOG_E("netsysService_ is null");
835 return NETSYS_NETSYSSERVICE_NULL;
836 }
837 return netsysService_->FirewallEnableChain(chain, enable);
838 }
839
FirewallSetUidRule(uint32_t chain,const std::vector<uint32_t> & uids,uint32_t firewallRule)840 int32_t NetsysController::FirewallSetUidRule(uint32_t chain, const std::vector<uint32_t> &uids, uint32_t firewallRule)
841 {
842 NETMGR_LOG_D("NetsysController::FirewallSetUidRule Start");
843 if (netsysService_ == nullptr) {
844 NETMGR_LOG_E("netsysService_ is null");
845 return NETSYS_NETSYSSERVICE_NULL;
846 }
847 return netsysService_->FirewallSetUidRule(chain, uids, firewallRule);
848 }
849
FreeAddrInfo(addrinfo * aihead)850 void NetsysController::FreeAddrInfo(addrinfo *aihead)
851 {
852 addrinfo *tmpNext = nullptr;
853 for (addrinfo *tmp = aihead; tmp != nullptr;) {
854 if (tmp->ai_addr != nullptr) {
855 free(tmp->ai_addr);
856 }
857 if (tmp->ai_canonname != nullptr) {
858 free(tmp->ai_canonname);
859 }
860 tmpNext = tmp->ai_next;
861 free(tmp);
862 tmp = tmpNext;
863 }
864 }
865
GetTotalStats(uint64_t & stats,uint32_t type)866 int32_t NetsysController::GetTotalStats(uint64_t &stats, uint32_t type)
867 {
868 if (netsysService_ == nullptr) {
869 NETMGR_LOG_E("netsysService is null");
870 return NETSYS_NETSYSSERVICE_NULL;
871 }
872 return netsysService_->GetTotalStats(stats, static_cast<uint32_t>(type));
873 }
874
GetUidStats(uint64_t & stats,uint32_t type,uint32_t uid)875 int32_t NetsysController::GetUidStats(uint64_t &stats, uint32_t type, uint32_t uid)
876 {
877 if (netsysService_ == nullptr) {
878 NETMGR_LOG_E("netsysService is null");
879 return NETSYS_NETSYSSERVICE_NULL;
880 }
881 return netsysService_->GetUidStats(stats, static_cast<uint32_t>(type), uid);
882 }
883
GetIfaceStats(uint64_t & stats,uint32_t type,const std::string & interfaceName)884 int32_t NetsysController::GetIfaceStats(uint64_t &stats, uint32_t type, const std::string &interfaceName)
885 {
886 if (netsysService_ == nullptr) {
887 NETMGR_LOG_E("netsysService is null");
888 return NETSYS_NETSYSSERVICE_NULL;
889 }
890 return netsysService_->GetIfaceStats(stats, static_cast<uint32_t>(type), interfaceName);
891 }
892
GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> & stats)893 int32_t NetsysController::GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats)
894 {
895 if (netsysService_ == nullptr) {
896 NETMGR_LOG_E("netsysService is null");
897 return NETSYS_NETSYSSERVICE_NULL;
898 }
899 return netsysService_->GetAllStatsInfo(stats);
900 }
901
SetIptablesCommandForRes(const std::string & cmd,std::string & respond)902 int32_t NetsysController::SetIptablesCommandForRes(const std::string &cmd, std::string &respond)
903 {
904 if (cmd.empty()) {
905 NETMGR_LOG_E("SetIptablesCommandForRes cmd is empty");
906 return ERR_INVALID_DATA;
907 }
908 if (netsysService_ == nullptr) {
909 NETMGR_LOG_E("SetIptablesCommandForRes netsysService is null");
910 return NETSYS_NETSYSSERVICE_NULL;
911 }
912 return netsysService_->SetIptablesCommandForRes(cmd, respond);
913 }
914
NetDiagPingHost(const OHOS::NetsysNative::NetDiagPingOption & pingOption,const sptr<OHOS::NetsysNative::INetDiagCallback> & callback)915 int32_t NetsysController::NetDiagPingHost(const OHOS::NetsysNative::NetDiagPingOption &pingOption,
916 const sptr<OHOS::NetsysNative::INetDiagCallback> &callback)
917 {
918 if (netsysService_ == nullptr) {
919 NETMGR_LOG_E("netsysService is null");
920 return NETSYS_NETSYSSERVICE_NULL;
921 }
922 return netsysService_->NetDiagPingHost(pingOption, callback);
923 }
924
NetDiagGetRouteTable(std::list<OHOS::NetsysNative::NetDiagRouteTable> & routeTables)925 int32_t NetsysController::NetDiagGetRouteTable(std::list<OHOS::NetsysNative::NetDiagRouteTable> &routeTables)
926 {
927 if (netsysService_ == nullptr) {
928 NETMGR_LOG_E("netsysService is null");
929 return NETSYS_NETSYSSERVICE_NULL;
930 }
931 return netsysService_->NetDiagGetRouteTable(routeTables);
932 }
933
NetDiagGetSocketsInfo(OHOS::NetsysNative::NetDiagProtocolType socketType,OHOS::NetsysNative::NetDiagSocketsInfo & socketsInfo)934 int32_t NetsysController::NetDiagGetSocketsInfo(OHOS::NetsysNative::NetDiagProtocolType socketType,
935 OHOS::NetsysNative::NetDiagSocketsInfo &socketsInfo)
936 {
937 if (netsysService_ == nullptr) {
938 NETMGR_LOG_E("netsysService is null");
939 return NETSYS_NETSYSSERVICE_NULL;
940 }
941 return netsysService_->NetDiagGetSocketsInfo(socketType, socketsInfo);
942 }
943
NetDiagGetInterfaceConfig(std::list<OHOS::NetsysNative::NetDiagIfaceConfig> & configs,const std::string & ifaceName)944 int32_t NetsysController::NetDiagGetInterfaceConfig(std::list<OHOS::NetsysNative::NetDiagIfaceConfig> &configs,
945 const std::string &ifaceName)
946 {
947 if (netsysService_ == nullptr) {
948 NETMGR_LOG_E("netsysService is null");
949 return NETSYS_NETSYSSERVICE_NULL;
950 }
951 return netsysService_->NetDiagGetInterfaceConfig(configs, ifaceName);
952 }
953
NetDiagUpdateInterfaceConfig(const OHOS::NetsysNative::NetDiagIfaceConfig & config,const std::string & ifaceName,bool add)954 int32_t NetsysController::NetDiagUpdateInterfaceConfig(const OHOS::NetsysNative::NetDiagIfaceConfig &config,
955 const std::string &ifaceName, bool add)
956 {
957 if (netsysService_ == nullptr) {
958 NETMGR_LOG_E("netsysService is null");
959 return NETSYS_NETSYSSERVICE_NULL;
960 }
961 return netsysService_->NetDiagUpdateInterfaceConfig(config, ifaceName, add);
962 }
963
NetDiagSetInterfaceActiveState(const std::string & ifaceName,bool up)964 int32_t NetsysController::NetDiagSetInterfaceActiveState(const std::string &ifaceName, bool up)
965 {
966 if (netsysService_ == nullptr) {
967 NETMGR_LOG_E("netsysService is null");
968 return NETSYS_NETSYSSERVICE_NULL;
969 }
970 return netsysService_->NetDiagSetInterfaceActiveState(ifaceName, up);
971 }
972
AddStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)973 int32_t NetsysController::AddStaticArp(const std::string &ipAddr, const std::string &macAddr,
974 const std::string &ifName)
975 {
976 if (netsysService_ == nullptr) {
977 NETMGR_LOG_E("AddStaticArp netsysService is null");
978 return NETSYS_NETSYSSERVICE_NULL;
979 }
980 return netsysService_->AddStaticArp(ipAddr, macAddr, ifName);
981 }
982
DelStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)983 int32_t NetsysController::DelStaticArp(const std::string &ipAddr, const std::string &macAddr,
984 const std::string &ifName)
985 {
986 if (netsysService_ == nullptr) {
987 NETMGR_LOG_E("DelStaticArp netsysService is null");
988 return NETSYS_NETSYSSERVICE_NULL;
989 }
990 return netsysService_->DelStaticArp(ipAddr, macAddr, ifName);
991 }
992
RegisterDnsResultCallback(const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> & callback,uint32_t timeStep)993 int32_t NetsysController::RegisterDnsResultCallback(
994 const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback, uint32_t timeStep)
995 {
996 if (netsysService_ == nullptr) {
997 NETMGR_LOG_E("netsysService is null");
998 return NETSYS_NETSYSSERVICE_NULL;
999 }
1000 return netsysService_->RegisterDnsResultCallback(callback, timeStep);
1001 }
1002
UnregisterDnsResultCallback(const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> & callback)1003 int32_t NetsysController::UnregisterDnsResultCallback(
1004 const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback)
1005 {
1006 if (netsysService_ == nullptr) {
1007 NETMGR_LOG_E("netsysService is null");
1008 return NETSYS_NETSYSSERVICE_NULL;
1009 }
1010 return netsysService_->UnregisterDnsResultCallback(callback);
1011 }
1012
RegisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> & callback)1013 int32_t NetsysController::RegisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> &callback)
1014 {
1015 if (netsysService_ == nullptr) {
1016 NETMGR_LOG_E("netsysService is null");
1017 return NETSYS_NETSYSSERVICE_NULL;
1018 }
1019 return netsysService_->RegisterDnsHealthCallback(callback);
1020 }
1021
UnregisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> & callback)1022 int32_t NetsysController::UnregisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> &callback)
1023 {
1024 if (netsysService_ == nullptr) {
1025 NETMGR_LOG_E("netsysService is null");
1026 return NETSYS_NETSYSSERVICE_NULL;
1027 }
1028 return netsysService_->UnregisterDnsHealthCallback(callback);
1029 }
1030
GetCookieStats(uint64_t & stats,uint32_t type,uint64_t cookie)1031 int32_t NetsysController::GetCookieStats(uint64_t &stats, uint32_t type, uint64_t cookie)
1032 {
1033 if (netsysService_ == nullptr) {
1034 NETMGR_LOG_E("GetCookieStats netsysService is null");
1035 return NETSYS_NETSYSSERVICE_NULL;
1036 }
1037 return netsysService_->GetCookieStats(stats, type, cookie);
1038 }
1039 } // namespace NetManagerStandard
1040 } // namespace OHOS
1041