• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 {
28 static constexpr uint32_t IPV4_MAX_LENGTH = 32;
29 
NetsysController()30 NetsysController::NetsysController()
31 {
32     NETMGR_LOG_I("netsys Init");
33     netsysService_ = std::make_unique<NetsysControllerServiceImpl>().release();
34     netsysService_->Init();
35 }
36 
GetInstance()37 NetsysController &NetsysController::GetInstance()
38 {
39     static NetsysController singleInstance_;
40     return singleInstance_;
41 }
42 
SetInternetPermission(uint32_t uid,uint8_t allow)43 int32_t NetsysController::SetInternetPermission(uint32_t uid, uint8_t allow)
44 {
45     // LCOV_EXCL_START This will never happen.
46     if (netsysService_ == nullptr) {
47         NETMGR_LOG_E("netsysService_ is null");
48         return NETSYS_NETSYSSERVICE_NULL;
49     }
50     // LCOV_EXCL_STOP
51     return netsysService_->SetInternetPermission(uid, allow);
52 }
53 
NetworkCreatePhysical(int32_t netId,int32_t permission)54 int32_t NetsysController::NetworkCreatePhysical(int32_t netId, int32_t permission)
55 {
56     NETMGR_LOG_I("Create Physical network: netId[%{public}d], permission[%{public}d]", netId, permission);
57     // LCOV_EXCL_START This will never happen.
58     if (netsysService_ == nullptr) {
59         NETMGR_LOG_E("netsysService_ is null");
60         return NETSYS_NETSYSSERVICE_NULL;
61     }
62     // LCOV_EXCL_STOP
63     return netsysService_->NetworkCreatePhysical(netId, permission);
64 }
65 
NetworkCreateVirtual(int32_t netId,bool hasDns)66 int32_t NetsysController::NetworkCreateVirtual(int32_t netId, bool hasDns)
67 {
68     NETMGR_LOG_I("Create Virtual network: netId[%{public}d], hasDns[%{public}d]", netId, hasDns);
69     // LCOV_EXCL_START This will never happen.
70     if (netsysService_ == nullptr) {
71         NETMGR_LOG_E("netsysService_ is null");
72         return NETSYS_NETSYSSERVICE_NULL;
73     }
74     // LCOV_EXCL_STOP
75     return netsysService_->NetworkCreateVirtual(netId, hasDns);
76 }
77 
NetworkDestroy(int32_t netId,bool isVpnNet)78 int32_t NetsysController::NetworkDestroy(int32_t netId, bool isVpnNet)
79 {
80     NETMGR_LOG_I("Destroy network: netId[%{public}d]", netId);
81     // LCOV_EXCL_START This will never happen.
82     if (netsysService_ == nullptr) {
83         NETMGR_LOG_E("netsysService_ is null");
84         return NETSYS_NETSYSSERVICE_NULL;
85     }
86     // LCOV_EXCL_STOP
87     return netsysService_->NetworkDestroy(netId, isVpnNet);
88 }
89 
CreateVnic(uint16_t mtu,const std::string & tunAddr,int32_t prefix,const std::set<int32_t> & uids)90 int32_t NetsysController::CreateVnic(uint16_t mtu, const std::string &tunAddr, int32_t prefix,
91                                      const std::set<int32_t> &uids)
92 {
93     NETMGR_LOG_I("Create Vnic network");
94     // LCOV_EXCL_START This will never happen.
95     if (netsysService_ == nullptr) {
96         NETMGR_LOG_E("netsysService_ is null");
97         return NETSYS_NETSYSSERVICE_NULL;
98     }
99     // LCOV_EXCL_STOP
100     return netsysService_->CreateVnic(mtu, tunAddr, prefix, uids);
101 }
102 
DestroyVnic()103 int32_t NetsysController::DestroyVnic()
104 {
105     NETMGR_LOG_I("Destroy Vnic network");
106     // LCOV_EXCL_START This will never happen.
107     if (netsysService_ == nullptr) {
108         NETMGR_LOG_E("netsysService_ is null");
109         return NETSYS_NETSYSSERVICE_NULL;
110     }
111     // LCOV_EXCL_STOP
112     return netsysService_->DestroyVnic();
113 }
114 
EnableDistributedClientNet(const std::string & virnicAddr,const std::string & iif)115 int32_t NetsysController::EnableDistributedClientNet(const std::string &virnicAddr, const std::string &iif)
116 {
117     if (netsysService_ == nullptr) {
118         NETMGR_LOG_E("netsysService_ is null");
119         return NETSYS_NETSYSSERVICE_NULL;
120     }
121     return netsysService_->EnableDistributedClientNet(virnicAddr, iif);
122 }
123 
EnableDistributedServerNet(const std::string & iif,const std::string & devIface,const std::string & dstAddr)124 int32_t NetsysController::EnableDistributedServerNet(const std::string &iif, const std::string &devIface,
125                                                      const std::string &dstAddr)
126 {
127     if (netsysService_ == nullptr) {
128         NETMGR_LOG_E("netsysService_ is null");
129         return NETSYS_NETSYSSERVICE_NULL;
130     }
131     return netsysService_->EnableDistributedServerNet(iif, devIface, dstAddr);
132 }
133 
DisableDistributedNet(bool isServer)134 int32_t NetsysController::DisableDistributedNet(bool isServer)
135 {
136     if (netsysService_ == nullptr) {
137         NETMGR_LOG_E("netsysService_ is null");
138         return NETSYS_NETSYSSERVICE_NULL;
139     }
140     return netsysService_->DisableDistributedNet(isServer);
141 }
142 
NetworkAddUids(int32_t netId,const std::vector<int32_t> & beginUids,const std::vector<int32_t> & endUids)143 int32_t NetsysController::NetworkAddUids(int32_t netId, const std::vector<int32_t> &beginUids,
144                                          const std::vector<int32_t> &endUids)
145 {
146     NETMGR_LOG_I("Destroy network: netId[%{public}d]", netId);
147     // LCOV_EXCL_START This will never happen.
148     if (netsysService_ == nullptr) {
149         NETMGR_LOG_E("netsysService_ is null");
150         return NETSYS_NETSYSSERVICE_NULL;
151     }
152     // LCOV_EXCL_STOP
153     if (beginUids.size() != endUids.size()) {
154         NETMGR_LOG_E("beginUids and endUids size is mismatch");
155         return NETMANAGER_ERR_INTERNAL;
156     }
157     std::vector<UidRange> uidRanges;
158     for (size_t i = 0; i < beginUids.size(); i++) {
159         uidRanges.emplace_back(UidRange(beginUids[i], endUids[i]));
160     }
161     return netsysService_->NetworkAddUids(netId, uidRanges);
162 }
163 
NetworkDelUids(int32_t netId,const std::vector<int32_t> & beginUids,const std::vector<int32_t> & endUids)164 int32_t NetsysController::NetworkDelUids(int32_t netId, const std::vector<int32_t> &beginUids,
165                                          const std::vector<int32_t> &endUids)
166 {
167     NETMGR_LOG_I("Destroy network: netId[%{public}d]", netId);
168     // LCOV_EXCL_START This will never happen.
169     if (netsysService_ == nullptr) {
170         NETMGR_LOG_E("netsysService_ is null");
171         return NETSYS_NETSYSSERVICE_NULL;
172     }
173     // LCOV_EXCL_STOP
174     if (beginUids.size() != endUids.size()) {
175         NETMGR_LOG_E("beginUids and endUids size is mismatch");
176         return NETMANAGER_ERR_INTERNAL;
177     }
178     std::vector<UidRange> uidRanges;
179     for (size_t i = 0; i < beginUids.size(); i++) {
180         uidRanges.emplace_back(UidRange(beginUids[i], endUids[i]));
181     }
182     return netsysService_->NetworkDelUids(netId, uidRanges);
183 }
184 
NetworkAddInterface(int32_t netId,const std::string & iface,NetBearType netBearerType)185 int32_t NetsysController::NetworkAddInterface(int32_t netId, const std::string &iface, NetBearType netBearerType)
186 {
187     NETMGR_LOG_I("Add network interface: netId[%{public}d], iface[%{public}s, bearerType[%{public}u]]", netId,
188                  iface.c_str(), netBearerType);
189     // LCOV_EXCL_START This will never happen.
190     if (netsysService_ == nullptr) {
191         NETMGR_LOG_E("netsysService_ is null");
192         return NETSYS_NETSYSSERVICE_NULL;
193     }
194     // LCOV_EXCL_STOP
195     return netsysService_->NetworkAddInterface(netId, iface, netBearerType);
196 }
197 
NetworkRemoveInterface(int32_t netId,const std::string & iface)198 int32_t NetsysController::NetworkRemoveInterface(int32_t netId, const std::string &iface)
199 {
200     NETMGR_LOG_I("Remove network interface: netId[%{public}d], iface[%{public}s]", netId, iface.c_str());
201     // LCOV_EXCL_START This will never happen.
202     if (netsysService_ == nullptr) {
203         NETMGR_LOG_E("netsysService_ is null");
204         return NETSYS_NETSYSSERVICE_NULL;
205     }
206     // LCOV_EXCL_STOP
207     return netsysService_->NetworkRemoveInterface(netId, iface);
208 }
209 
NetworkAddRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)210 int32_t NetsysController::NetworkAddRoute(int32_t netId, const std::string &ifName, const std::string &destination,
211                                           const std::string &nextHop)
212 {
213     NETMGR_LOG_D("Add Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]",
214                  netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
215     // LCOV_EXCL_START This will never happen.
216     if (netsysService_ == nullptr) {
217         NETMGR_LOG_E("netsysService_ is null");
218         return NETSYS_NETSYSSERVICE_NULL;
219     }
220     // LCOV_EXCL_STOP
221     return netsysService_->NetworkAddRoute(netId, ifName, destination, nextHop);
222 }
223 
NetworkRemoveRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)224 int32_t NetsysController::NetworkRemoveRoute(int32_t netId, const std::string &ifName, const std::string &destination,
225                                              const std::string &nextHop)
226 {
227     NETMGR_LOG_D("Remove Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]",
228                  netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
229     // LCOV_EXCL_START This will never happen.
230     if (netsysService_ == nullptr) {
231         NETMGR_LOG_E("netsysService_ is null");
232         return NETSYS_NETSYSSERVICE_NULL;
233     }
234     // LCOV_EXCL_STOP
235     return netsysService_->NetworkRemoveRoute(netId, ifName, destination, nextHop);
236 }
237 
GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel & cfg)238 int32_t NetsysController::GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel &cfg)
239 {
240     NETMGR_LOG_D("get interface config");
241     // LCOV_EXCL_START This will never happen.
242     if (netsysService_ == nullptr) {
243         NETMGR_LOG_E("netsysService_ is null");
244         return NETSYS_NETSYSSERVICE_NULL;
245     }
246     // LCOV_EXCL_STOP
247     return netsysService_->GetInterfaceConfig(cfg);
248 }
249 
SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel & cfg)250 int32_t NetsysController::SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel &cfg)
251 {
252     NETMGR_LOG_I("set interface config");
253     // LCOV_EXCL_START This will never happen.
254     if (netsysService_ == nullptr) {
255         NETMGR_LOG_E("netsysService_ is null");
256         return NETSYS_NETSYSSERVICE_NULL;
257     }
258     // LCOV_EXCL_STOP
259     return netsysService_->SetInterfaceConfig(cfg);
260 }
261 
SetInterfaceDown(const std::string & iface)262 int32_t NetsysController::SetInterfaceDown(const std::string &iface)
263 {
264     NETMGR_LOG_I("Set interface down: iface[%{public}s]", iface.c_str());
265     // LCOV_EXCL_START This will never happen.
266     if (netsysService_ == nullptr) {
267         NETMGR_LOG_E("netsysService_ is null");
268         return NETSYS_NETSYSSERVICE_NULL;
269     }
270     // LCOV_EXCL_STOP
271     return netsysService_->SetInterfaceDown(iface);
272 }
273 
SetInterfaceUp(const std::string & iface)274 int32_t NetsysController::SetInterfaceUp(const std::string &iface)
275 {
276     NETMGR_LOG_I("Set interface up: iface[%{public}s]", iface.c_str());
277     // LCOV_EXCL_START This will never happen.
278     if (netsysService_ == nullptr) {
279         NETMGR_LOG_E("netsysService_ is null");
280         return NETSYS_NETSYSSERVICE_NULL;
281     }
282     // LCOV_EXCL_STOP
283     return netsysService_->SetInterfaceUp(iface);
284 }
285 
ClearInterfaceAddrs(const std::string & ifName)286 void NetsysController::ClearInterfaceAddrs(const std::string &ifName)
287 {
288     NETMGR_LOG_I("Clear addrs: ifName[%{public}s]", ifName.c_str());
289     // LCOV_EXCL_START This will never happen.
290     if (netsysService_ == nullptr) {
291         NETMGR_LOG_E("netsysService_ is null");
292         return;
293     }
294     // LCOV_EXCL_STOP
295     return netsysService_->ClearInterfaceAddrs(ifName);
296 }
297 
GetInterfaceMtu(const std::string & ifName)298 int32_t NetsysController::GetInterfaceMtu(const std::string &ifName)
299 {
300     NETMGR_LOG_I("Get mtu: ifName[%{public}s]", ifName.c_str());
301     // LCOV_EXCL_START This will never happen.
302     if (netsysService_ == nullptr) {
303         NETMGR_LOG_E("netsysService_ is null");
304         return NETSYS_NETSYSSERVICE_NULL;
305     }
306     // LCOV_EXCL_STOP
307     return netsysService_->GetInterfaceMtu(ifName);
308 }
309 
SetInterfaceMtu(const std::string & ifName,int32_t mtu)310 int32_t NetsysController::SetInterfaceMtu(const std::string &ifName, int32_t mtu)
311 {
312     NETMGR_LOG_I("Set mtu: ifName[%{public}s], mtu[%{public}d]", ifName.c_str(), mtu);
313     // LCOV_EXCL_START This will never happen.
314     if (netsysService_ == nullptr) {
315         NETMGR_LOG_E("netsysService_ is null");
316         return NETSYS_NETSYSSERVICE_NULL;
317     }
318     // LCOV_EXCL_STOP
319     return netsysService_->SetInterfaceMtu(ifName, mtu);
320 }
321 
SetTcpBufferSizes(const std::string & tcpBufferSizes)322 int32_t NetsysController::SetTcpBufferSizes(const std::string &tcpBufferSizes)
323 {
324     NETMGR_LOG_I("Set tcp buffer sizes: tcpBufferSizes[%{public}s]", tcpBufferSizes.c_str());
325     // LCOV_EXCL_START This will never happen.
326     if (netsysService_ == nullptr) {
327         NETMGR_LOG_E("netsysService_ is null");
328         return NETSYS_NETSYSSERVICE_NULL;
329     }
330     // LCOV_EXCL_STOP
331     return netsysService_->SetTcpBufferSizes(tcpBufferSizes);
332 }
333 
AddInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)334 int32_t NetsysController::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
335                                               int32_t prefixLength)
336 {
337     NETMGR_LOG_I("Add address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]",
338         ifName.c_str(), ToAnonymousIp(ipAddr).c_str(), prefixLength);
339     // LCOV_EXCL_START This will never happen.
340     if (netsysService_ == nullptr) {
341         NETMGR_LOG_E("netsysService_ is null");
342         return NETSYS_NETSYSSERVICE_NULL;
343     }
344     // LCOV_EXCL_STOP
345     return netsysService_->AddInterfaceAddress(ifName, ipAddr, prefixLength);
346 }
347 
DelInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)348 int32_t NetsysController::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
349                                               int32_t prefixLength)
350 {
351     NETMGR_LOG_I("Delete address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]",
352         ifName.c_str(), ToAnonymousIp(ipAddr).c_str(), prefixLength);
353     // LCOV_EXCL_START This will never happen.
354     if (netsysService_ == nullptr) {
355         NETMGR_LOG_E("netsysService_ is null");
356         return NETSYS_NETSYSSERVICE_NULL;
357     }
358     // LCOV_EXCL_STOP
359     return netsysService_->DelInterfaceAddress(ifName, ipAddr, prefixLength);
360 }
361 
DelInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength,const std::string & netCapabilities)362 int32_t NetsysController::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
363                                               int32_t prefixLength, const std::string &netCapabilities)
364 {
365     NETMGR_LOG_I("Delete address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]",
366         ifName.c_str(), ToAnonymousIp(ipAddr).c_str(), prefixLength);
367     // LCOV_EXCL_START This will never happen.
368     if (netsysService_ == nullptr) {
369         NETMGR_LOG_E("netsysService_ is null");
370         return NETSYS_NETSYSSERVICE_NULL;
371     }
372     // LCOV_EXCL_STOP
373     return netsysService_->DelInterfaceAddress(ifName, ipAddr, prefixLength, netCapabilities);
374 }
375 
InterfaceSetIpAddress(const std::string & ifaceName,const std::string & ipAddress)376 int32_t NetsysController::InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress)
377 {
378     NETMGR_LOG_D("Set Ip Address: ifName[%{public}s]", ifaceName.c_str());
379     // LCOV_EXCL_START This will never happen.
380     if (netsysService_ == nullptr) {
381         NETMGR_LOG_E("netsysService_ is null");
382         return NETSYS_NETSYSSERVICE_NULL;
383     }
384     // LCOV_EXCL_STOP
385     return netsysService_->InterfaceSetIpAddress(ifaceName, ipAddress);
386 }
387 
InterfaceSetIffUp(const std::string & ifaceName)388 int32_t NetsysController::InterfaceSetIffUp(const std::string &ifaceName)
389 {
390     NETMGR_LOG_D("Set Iff Up: ifName[%{public}s]", ifaceName.c_str());
391     // LCOV_EXCL_START This will never happen.
392     if (netsysService_ == nullptr) {
393         NETMGR_LOG_E("netsysService_ is null");
394         return NETSYS_NETSYSSERVICE_NULL;
395     }
396     // LCOV_EXCL_STOP
397     return netsysService_->InterfaceSetIffUp(ifaceName);
398 }
399 
SetResolverConfig(uint16_t netId,uint16_t baseTimeoutMsec,uint8_t retryCount,const std::vector<std::string> & servers,const std::vector<std::string> & domains)400 int32_t NetsysController::SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
401                                             const std::vector<std::string> &servers,
402                                             const std::vector<std::string> &domains)
403 {
404     NETMGR_LOG_I("Set resolver config: netId[%{public}d]", netId);
405     // LCOV_EXCL_START This will never happen.
406     if (netsysService_ == nullptr) {
407         NETMGR_LOG_E("netsysService_ is null");
408         return NETSYS_NETSYSSERVICE_NULL;
409     }
410     // LCOV_EXCL_STOP
411     return netsysService_->SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
412 }
413 
GetResolverConfig(uint16_t netId,std::vector<std::string> & servers,std::vector<std::string> & domains,uint16_t & baseTimeoutMsec,uint8_t & retryCount)414 int32_t NetsysController::GetResolverConfig(uint16_t netId, std::vector<std::string> &servers,
415                                             std::vector<std::string> &domains, uint16_t &baseTimeoutMsec,
416                                             uint8_t &retryCount)
417 {
418     NETMGR_LOG_I("Get resolver config: netId[%{public}d]", netId);
419     // LCOV_EXCL_START This will never happen.
420     if (netsysService_ == nullptr) {
421         NETMGR_LOG_E("netsysService_ is null");
422         return NETSYS_NETSYSSERVICE_NULL;
423     }
424     // LCOV_EXCL_STOP
425     return netsysService_->GetResolverConfig(netId, servers, domains, baseTimeoutMsec, retryCount);
426 }
427 
CreateNetworkCache(uint16_t netId,bool isVpnNet)428 int32_t NetsysController::CreateNetworkCache(uint16_t netId, bool isVpnNet)
429 {
430     NETMGR_LOG_I("create dns cache: netId[%{public}d]", netId);
431     // LCOV_EXCL_START This will never happen.
432     if (netsysService_ == nullptr) {
433         NETMGR_LOG_E("netsysService_ is null");
434         return NETSYS_NETSYSSERVICE_NULL;
435     }
436     // LCOV_EXCL_STOP
437     return netsysService_->CreateNetworkCache(netId, isVpnNet);
438 }
439 
DestroyNetworkCache(uint16_t netId,bool isVpnNet)440 int32_t NetsysController::DestroyNetworkCache(uint16_t netId, bool isVpnNet)
441 {
442     NETMGR_LOG_I("Destroy dns cache: netId[%{public}d]", netId);
443     // LCOV_EXCL_START This will never happen.
444     if (netsysService_ == nullptr) {
445         NETMGR_LOG_E("netsysService_ is null");
446         return NETSYS_NETSYSSERVICE_NULL;
447     }
448     // LCOV_EXCL_STOP
449     return netsysService_->DestroyNetworkCache(netId, isVpnNet);
450 }
451 
GetAddrInfo(const std::string & hostName,const std::string & serverName,const AddrInfo & hints,uint16_t netId,std::vector<AddrInfo> & res)452 int32_t NetsysController::GetAddrInfo(const std::string &hostName, const std::string &serverName, const AddrInfo &hints,
453                                       uint16_t netId, std::vector<AddrInfo> &res)
454 {
455     // LCOV_EXCL_START This will never happen.
456     if (netsysService_ == nullptr) {
457         NETMGR_LOG_E("netsysService_ is null");
458         return NET_CONN_ERR_SERVICE_UPDATE_NET_LINK_INFO_FAIL;
459     }
460     // LCOV_EXCL_STOP
461     return netsysService_->GetAddrInfo(hostName, serverName, hints, netId, res);
462 }
463 
GetNetworkSharingTraffic(const std::string & downIface,const std::string & upIface,nmd::NetworkSharingTraffic & traffic)464 int32_t NetsysController::GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface,
465                                                    nmd::NetworkSharingTraffic &traffic)
466 {
467     NETMGR_LOG_I("NetsysController GetNetworkSharingTraffic");
468     // LCOV_EXCL_START This will never happen.
469     if (netsysService_ == nullptr) {
470         NETMGR_LOG_E("netsysService_ is null");
471         return NETSYS_NETSYSSERVICE_NULL;
472     }
473     // LCOV_EXCL_STOP
474     return netsysService_->GetNetworkSharingTraffic(downIface, upIface, traffic);
475 }
476 
GetNetworkCellularSharingTraffic(nmd::NetworkSharingTraffic & traffic,std::string & ifaceName)477 int32_t NetsysController::GetNetworkCellularSharingTraffic(nmd::NetworkSharingTraffic &traffic, std::string &ifaceName)
478 {
479     NETMGR_LOG_I("NetsysController GetNetworkCellularSharingTraffic");
480     // LCOV_EXCL_START This will never happen.
481     if (netsysService_ == nullptr) {
482         NETMGR_LOG_E("netsysService_ is null");
483         return NETSYS_NETSYSSERVICE_NULL;
484     }
485     // LCOV_EXCL_STOP
486     return netsysService_->GetNetworkCellularSharingTraffic(traffic, ifaceName);
487 }
488 
GetCellularRxBytes()489 int64_t NetsysController::GetCellularRxBytes()
490 {
491     NETMGR_LOG_D("NetsysController GetCellularRxBytes");
492     // LCOV_EXCL_START This will never happen.
493     if (netsysService_ == nullptr) {
494         NETMGR_LOG_E("netsysService_ is null");
495         return NETSYS_NETSYSSERVICE_NULL;
496     }
497     // LCOV_EXCL_STOP
498     return netsysService_->GetCellularRxBytes();
499 }
500 
GetCellularTxBytes()501 int64_t NetsysController::GetCellularTxBytes()
502 {
503     NETMGR_LOG_D("NetsysController GetCellularTxBytes");
504     // LCOV_EXCL_START This will never happen.
505     if (netsysService_ == nullptr) {
506         NETMGR_LOG_E("netsysService_ is null");
507         return NETSYS_NETSYSSERVICE_NULL;
508     }
509     // LCOV_EXCL_STOP
510     return netsysService_->GetCellularTxBytes();
511 }
512 
GetAllRxBytes()513 int64_t NetsysController::GetAllRxBytes()
514 {
515     NETMGR_LOG_D("NetsysController GetAllRxBytes");
516     // LCOV_EXCL_START This will never happen.
517     if (netsysService_ == nullptr) {
518         NETMGR_LOG_E("netsysService_ is null");
519         return NETSYS_NETSYSSERVICE_NULL;
520     }
521     // LCOV_EXCL_STOP
522     return netsysService_->GetAllRxBytes();
523 }
524 
GetAllTxBytes()525 int64_t NetsysController::GetAllTxBytes()
526 {
527     NETMGR_LOG_D("NetsysController GetAllTxBytes");
528     // LCOV_EXCL_START This will never happen.
529     if (netsysService_ == nullptr) {
530         NETMGR_LOG_E("netsysService_ is null");
531         return NETSYS_NETSYSSERVICE_NULL;
532     }
533     // LCOV_EXCL_STOP
534     return netsysService_->GetAllTxBytes();
535 }
536 
GetUidRxBytes(uint32_t uid)537 int64_t NetsysController::GetUidRxBytes(uint32_t uid)
538 {
539     NETMGR_LOG_D("NetsysController GetUidRxBytes");
540     // LCOV_EXCL_START This will never happen.
541     if (netsysService_ == nullptr) {
542         NETMGR_LOG_E("netsysService_ is null");
543         return NETSYS_NETSYSSERVICE_NULL;
544     }
545     // LCOV_EXCL_STOP
546     return netsysService_->GetUidRxBytes(uid);
547 }
548 
GetUidTxBytes(uint32_t uid)549 int64_t NetsysController::GetUidTxBytes(uint32_t uid)
550 {
551     NETMGR_LOG_D("NetsysController GetUidTxBytes");
552     // LCOV_EXCL_START This will never happen.
553     if (netsysService_ == nullptr) {
554         NETMGR_LOG_E("netsysService_ is null");
555         return NETSYS_NETSYSSERVICE_NULL;
556     }
557     // LCOV_EXCL_STOP
558     return netsysService_->GetUidTxBytes(uid);
559 }
560 
GetUidOnIfaceRxBytes(uint32_t uid,const std::string & interfaceName)561 int64_t NetsysController::GetUidOnIfaceRxBytes(uint32_t uid, const std::string &interfaceName)
562 {
563     NETMGR_LOG_D("NetsysController GetUidOnIfaceRxBytes");
564     // LCOV_EXCL_START This will never happen.
565     if (netsysService_ == nullptr) {
566         NETMGR_LOG_E("netsysService_ is null");
567         return NETSYS_NETSYSSERVICE_NULL;
568     }
569     // LCOV_EXCL_STOP
570     return netsysService_->GetUidOnIfaceRxBytes(uid, interfaceName);
571 }
572 
GetUidOnIfaceTxBytes(uint32_t uid,const std::string & interfaceName)573 int64_t NetsysController::GetUidOnIfaceTxBytes(uint32_t uid, const std::string &interfaceName)
574 {
575     NETMGR_LOG_D("NetsysController GetUidOnIfaceTxBytes");
576     // LCOV_EXCL_START This will never happen.
577     if (netsysService_ == nullptr) {
578         NETMGR_LOG_E("netsysService_ is null");
579         return NETSYS_NETSYSSERVICE_NULL;
580     }
581     // LCOV_EXCL_STOP
582     return netsysService_->GetUidOnIfaceTxBytes(uid, interfaceName);
583 }
584 
GetIfaceRxBytes(const std::string & interfaceName)585 int64_t NetsysController::GetIfaceRxBytes(const std::string &interfaceName)
586 {
587     NETMGR_LOG_D("NetsysController GetIfaceRxBytes");
588     // LCOV_EXCL_START This will never happen.
589     if (netsysService_ == nullptr) {
590         NETMGR_LOG_E("netsysService_ is null");
591         return NETSYS_NETSYSSERVICE_NULL;
592     }
593     // LCOV_EXCL_STOP
594     return netsysService_->GetIfaceRxBytes(interfaceName);
595 }
596 
GetIfaceTxBytes(const std::string & interfaceName)597 int64_t NetsysController::GetIfaceTxBytes(const std::string &interfaceName)
598 {
599     NETMGR_LOG_D("NetsysController GetIfaceTxBytes");
600     // LCOV_EXCL_START This will never happen.
601     if (netsysService_ == nullptr) {
602         NETMGR_LOG_E("netsysService_ is null");
603         return NETSYS_NETSYSSERVICE_NULL;
604     }
605     // LCOV_EXCL_STOP
606     return netsysService_->GetIfaceTxBytes(interfaceName);
607 }
608 
InterfaceGetList()609 std::vector<std::string> NetsysController::InterfaceGetList()
610 {
611     NETMGR_LOG_I("InterfaceGetList");
612     // LCOV_EXCL_START This will never happen.
613     if (netsysService_ == nullptr) {
614         NETMGR_LOG_E("netsysService_ is null");
615         return {};
616     }
617     // LCOV_EXCL_STOP
618     return netsysService_->InterfaceGetList();
619 }
620 
UidGetList()621 std::vector<std::string> NetsysController::UidGetList()
622 {
623     NETMGR_LOG_I("UidGetList");
624     // LCOV_EXCL_START This will never happen.
625     if (netsysService_ == nullptr) {
626         NETMGR_LOG_E("netsysService_ is null");
627         return {};
628     }
629     // LCOV_EXCL_STOP
630     return netsysService_->UidGetList();
631 }
632 
GetIfaceRxPackets(const std::string & interfaceName)633 int64_t NetsysController::GetIfaceRxPackets(const std::string &interfaceName)
634 {
635     NETMGR_LOG_D("NetsysController GetIfaceRxPackets");
636     // LCOV_EXCL_START This will never happen.
637     if (netsysService_ == nullptr) {
638         NETMGR_LOG_E("netsysService_ is null");
639         return NETSYS_NETSYSSERVICE_NULL;
640     }
641     // LCOV_EXCL_STOP
642     return netsysService_->GetIfaceRxPackets(interfaceName);
643 }
644 
GetIfaceTxPackets(const std::string & interfaceName)645 int64_t NetsysController::GetIfaceTxPackets(const std::string &interfaceName)
646 {
647     NETMGR_LOG_D("NetsysController GetIfaceTxPackets");
648     // LCOV_EXCL_START This will never happen.
649     if (netsysService_ == nullptr) {
650         NETMGR_LOG_E("netsysService_ is null");
651         return NETSYS_NETSYSSERVICE_NULL;
652     }
653     // LCOV_EXCL_STOP
654     return netsysService_->GetIfaceTxPackets(interfaceName);
655 }
656 
SetDefaultNetWork(int32_t netId)657 int32_t NetsysController::SetDefaultNetWork(int32_t netId)
658 {
659     NETMGR_LOG_D("Set DefaultNetWork: netId[%{public}d]", netId);
660     // LCOV_EXCL_START This will never happen.
661     if (netsysService_ == nullptr) {
662         NETMGR_LOG_E("netsysService_ is null");
663         return NETSYS_NETSYSSERVICE_NULL;
664     }
665     // LCOV_EXCL_STOP
666     return netsysService_->SetDefaultNetWork(netId);
667 }
668 
ClearDefaultNetWorkNetId()669 int32_t NetsysController::ClearDefaultNetWorkNetId()
670 {
671     NETMGR_LOG_D("ClearDefaultNetWorkNetId");
672     // LCOV_EXCL_START This will never happen.
673     if (netsysService_ == nullptr) {
674         NETMGR_LOG_E("netsysService_ is null");
675         return NETSYS_NETSYSSERVICE_NULL;
676     }
677     // LCOV_EXCL_STOP
678     return netsysService_->ClearDefaultNetWorkNetId();
679 }
680 
BindSocket(int32_t socketFd,uint32_t netId)681 int32_t NetsysController::BindSocket(int32_t socketFd, uint32_t netId)
682 {
683     NETMGR_LOG_D("NetsysController::BindSocket: netId = [%{public}u]", netId);
684     // LCOV_EXCL_START This will never happen.
685     if (netsysService_ == nullptr) {
686         NETMGR_LOG_E("netsysService_ is null");
687         return NETSYS_NETSYSSERVICE_NULL;
688     }
689     // LCOV_EXCL_STOP
690     return netsysService_->BindSocket(socketFd, netId);
691 }
692 
IpEnableForwarding(const std::string & requestor)693 int32_t NetsysController::IpEnableForwarding(const std::string &requestor)
694 {
695     NETMGR_LOG_I("IpEnableForwarding: requestor[%{public}s]", requestor.c_str());
696     // LCOV_EXCL_START This will never happen.
697     if (netsysService_ == nullptr) {
698         NETMGR_LOG_E("netsysService_ is null");
699         return NETSYS_NETSYSSERVICE_NULL;
700     }
701     // LCOV_EXCL_STOP
702     return netsysService_->IpEnableForwarding(requestor);
703 }
704 
IpDisableForwarding(const std::string & requestor)705 int32_t NetsysController::IpDisableForwarding(const std::string &requestor)
706 {
707     NETMGR_LOG_I("IpDisableForwarding: requestor[%{public}s]", requestor.c_str());
708     // LCOV_EXCL_START This will never happen.
709     if (netsysService_ == nullptr) {
710         NETMGR_LOG_E("netsysService_ is null");
711         return NETSYS_NETSYSSERVICE_NULL;
712     }
713     // LCOV_EXCL_STOP
714     return netsysService_->IpDisableForwarding(requestor);
715 }
716 
EnableNat(const std::string & downstreamIface,const std::string & upstreamIface)717 int32_t NetsysController::EnableNat(const std::string &downstreamIface, const std::string &upstreamIface)
718 {
719     NETMGR_LOG_I("EnableNat: intIface[%{public}s] intIface[%{public}s]", downstreamIface.c_str(),
720                  upstreamIface.c_str());
721     // LCOV_EXCL_START This will never happen.
722     if (netsysService_ == nullptr) {
723         NETMGR_LOG_E("netsysService_ is null");
724         return NETSYS_NETSYSSERVICE_NULL;
725     }
726     // LCOV_EXCL_STOP
727     return netsysService_->EnableNat(downstreamIface, upstreamIface);
728 }
729 
DisableNat(const std::string & downstreamIface,const std::string & upstreamIface)730 int32_t NetsysController::DisableNat(const std::string &downstreamIface, const std::string &upstreamIface)
731 {
732     NETMGR_LOG_I("DisableNat: intIface[%{public}s] intIface[%{public}s]",
733                  downstreamIface.c_str(), upstreamIface.c_str());
734     // LCOV_EXCL_START This will never happen.
735     if (netsysService_ == nullptr) {
736         NETMGR_LOG_E("netsysService_ is null");
737         return NETSYS_NETSYSSERVICE_NULL;
738     }
739     // LCOV_EXCL_STOP
740     return netsysService_->DisableNat(downstreamIface, upstreamIface);
741 }
742 
IpfwdAddInterfaceForward(const std::string & fromIface,const std::string & toIface)743 int32_t NetsysController::IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface)
744 {
745     NETMGR_LOG_I("IpfwdAddInterfaceForward: fromIface[%{public}s], toIface[%{public}s]", fromIface.c_str(),
746                  toIface.c_str());
747     // LCOV_EXCL_START This will never happen.
748     if (netsysService_ == nullptr) {
749         NETMGR_LOG_E("netsysService_ is null");
750         return NETSYS_NETSYSSERVICE_NULL;
751     }
752     // LCOV_EXCL_STOP
753     return netsysService_->IpfwdAddInterfaceForward(fromIface, toIface);
754 }
755 
IpfwdRemoveInterfaceForward(const std::string & fromIface,const std::string & toIface)756 int32_t NetsysController::IpfwdRemoveInterfaceForward(const std::string &fromIface, const std::string &toIface)
757 {
758     NETMGR_LOG_I("IpfwdRemoveInterfaceForward: fromIface[%{public}s], toIface[%{public}s]", fromIface.c_str(),
759                  toIface.c_str());
760     // LCOV_EXCL_START This will never happen.
761     if (netsysService_ == nullptr) {
762         NETMGR_LOG_E("netsysService_ is null");
763         return NETSYS_NETSYSSERVICE_NULL;
764     }
765     // LCOV_EXCL_STOP
766     return netsysService_->IpfwdRemoveInterfaceForward(fromIface, toIface);
767 }
768 
ShareDnsSet(uint16_t netId)769 int32_t NetsysController::ShareDnsSet(uint16_t netId)
770 {
771     NETMGR_LOG_I("ShareDnsSet: netId[%{public}d]", netId);
772     // LCOV_EXCL_START This will never happen.
773     if (netsysService_ == nullptr) {
774         NETMGR_LOG_E("netsysService_ is null");
775         return NETSYS_NETSYSSERVICE_NULL;
776     }
777     // LCOV_EXCL_STOP
778     return netsysService_->ShareDnsSet(netId);
779 }
780 
StartDnsProxyListen()781 int32_t NetsysController::StartDnsProxyListen()
782 {
783     NETMGR_LOG_I("StartDnsProxyListen");
784     // LCOV_EXCL_START This will never happen.
785     if (netsysService_ == nullptr) {
786         NETMGR_LOG_E("netsysService_ is null");
787         return NETSYS_NETSYSSERVICE_NULL;
788     }
789     // LCOV_EXCL_STOP
790     return netsysService_->StartDnsProxyListen();
791 }
792 
StopDnsProxyListen()793 int32_t NetsysController::StopDnsProxyListen()
794 {
795     NETMGR_LOG_I("StopDnsProxyListen");
796     // LCOV_EXCL_START This will never happen.
797     if (netsysService_ == nullptr) {
798         NETMGR_LOG_E("netsysService_ is null");
799         return NETSYS_NETSYSSERVICE_NULL;
800     }
801     // LCOV_EXCL_STOP
802     return netsysService_->StopDnsProxyListen();
803 }
804 
RegisterNetsysNotifyCallback(const NetsysNotifyCallback & callback)805 int32_t NetsysController::RegisterNetsysNotifyCallback(const NetsysNotifyCallback &callback)
806 {
807     // LCOV_EXCL_START This will never happen.
808     if (netsysService_ == nullptr) {
809         NETMGR_LOG_E("netsysService_ is null");
810         return NETSYS_NETSYSSERVICE_NULL;
811     }
812     // LCOV_EXCL_STOP
813     return netsysService_->RegisterNetsysNotifyCallback(callback);
814 }
815 
BindNetworkServiceVpn(int32_t socketFd)816 int32_t NetsysController::BindNetworkServiceVpn(int32_t socketFd)
817 {
818     NETMGR_LOG_I("BindNetworkServiceVpn: socketFd[%{public}d]", socketFd);
819     if (socketFd <= 0) {
820         NETMGR_LOG_E("socketFd is null");
821         return NETSYS_ERR_VPN;
822     }
823     // LCOV_EXCL_START This will never happen.
824     if (netsysService_ == nullptr) {
825         NETMGR_LOG_E("netsysService_ is null");
826         return NETSYS_NETSYSSERVICE_NULL;
827     }
828     // LCOV_EXCL_STOP
829     return netsysService_->BindNetworkServiceVpn(socketFd);
830 }
831 
EnableVirtualNetIfaceCard(int32_t socketFd,struct ifreq & ifRequest,int32_t & ifaceFd)832 int32_t NetsysController::EnableVirtualNetIfaceCard(int32_t socketFd, struct ifreq &ifRequest, int32_t &ifaceFd)
833 {
834     NETMGR_LOG_I("EnableVirtualNetIfaceCard: socketFd[%{public}d]", socketFd);
835     if (socketFd <= 0) {
836         NETMGR_LOG_E("socketFd is null");
837         return NETSYS_ERR_VPN;
838     }
839     // LCOV_EXCL_START This will never happen.
840     if (netsysService_ == nullptr) {
841         NETMGR_LOG_E("netsysService_ is null");
842         return NETSYS_NETSYSSERVICE_NULL;
843     }
844     // LCOV_EXCL_STOP
845     return netsysService_->EnableVirtualNetIfaceCard(socketFd, ifRequest, ifaceFd);
846 }
847 
SetIpAddress(int32_t socketFd,const std::string & ipAddress,int32_t prefixLen,struct ifreq & ifRequest)848 int32_t NetsysController::SetIpAddress(int32_t socketFd, const std::string &ipAddress, int32_t prefixLen,
849                                        struct ifreq &ifRequest)
850 {
851     NETMGR_LOG_D("NetsysController::set addr");
852     if ((socketFd <= 0) || (ipAddress.length() == 0) || (static_cast<uint32_t>(ipAddress.length()) > IPV4_MAX_LENGTH) ||
853 	    (prefixLen <= 0) || (static_cast<uint32_t>(prefixLen) > IPV4_MAX_LENGTH)) {
854         NETMGR_LOG_E(
855             "The paramemters of SetIpAddress is failed, socketFd[%{public}d], "
856             "ipAddress[%{public}s], prefixLen[%{public}d].",
857             socketFd, ToAnonymousIp(ipAddress).c_str(), prefixLen);
858         return NETSYS_ERR_VPN;
859     }
860     // LCOV_EXCL_START This will never happen.
861     if (netsysService_ == nullptr) {
862         NETMGR_LOG_E("netsysService_ is null");
863         return NETSYS_NETSYSSERVICE_NULL;
864     }
865     // LCOV_EXCL_STOP
866     return netsysService_->SetIpAddress(socketFd, ipAddress, prefixLen, ifRequest);
867 }
868 
SetBlocking(int32_t ifaceFd,bool isBlock)869 int32_t NetsysController::SetBlocking(int32_t ifaceFd, bool isBlock)
870 {
871     NETMGR_LOG_D("NetsysController::SetBlocking: ifaceFd[%{public}d], isBlock[%{public}d]", ifaceFd, isBlock);
872     // LCOV_EXCL_START This will never happen.
873     if (netsysService_ == nullptr) {
874         NETMGR_LOG_E("netsysService_ is null");
875         return NETSYS_NETSYSSERVICE_NULL;
876     }
877     // LCOV_EXCL_STOP
878     return netsysService_->SetBlocking(ifaceFd, isBlock);
879 }
880 
StartDhcpClient(const std::string & iface,bool bIpv6)881 int32_t NetsysController::StartDhcpClient(const std::string &iface, bool bIpv6)
882 {
883     NETMGR_LOG_I("StartDhcpClient: iface[%{public}s], bIpv6[%{public}d]", iface.c_str(), bIpv6);
884     // LCOV_EXCL_START This will never happen.
885     if (netsysService_ == nullptr) {
886         NETMGR_LOG_E("netsysService_ is null");
887         return NETSYS_NETSYSSERVICE_NULL;
888     }
889     // LCOV_EXCL_STOP
890     return netsysService_->StartDhcpClient(iface, bIpv6);
891 }
892 
StopDhcpClient(const std::string & iface,bool bIpv6)893 int32_t NetsysController::StopDhcpClient(const std::string &iface, bool bIpv6)
894 {
895     NETMGR_LOG_I("StopDhcpClient: iface[%{public}s], bIpv6[%{public}d]", iface.c_str(), bIpv6);
896     // LCOV_EXCL_START This will never happen.
897     if (netsysService_ == nullptr) {
898         NETMGR_LOG_E("netsysService_ is null");
899         return NETSYS_NETSYSSERVICE_NULL;
900     }
901     // LCOV_EXCL_STOP
902     return netsysService_->StopDhcpClient(iface, bIpv6);
903 }
904 
RegisterCallback(sptr<NetsysControllerCallback> callback)905 int32_t NetsysController::RegisterCallback(sptr<NetsysControllerCallback> callback)
906 {
907     NETMGR_LOG_D("NetsysController::RegisterCallback");
908     // LCOV_EXCL_START This will never happen.
909     if (netsysService_ == nullptr) {
910         NETMGR_LOG_E("netsysService_ is null");
911         return NETSYS_NETSYSSERVICE_NULL;
912     }
913     // LCOV_EXCL_STOP
914     return netsysService_->RegisterCallback(callback);
915 }
916 
StartDhcpService(const std::string & iface,const std::string & ipv4addr)917 int32_t NetsysController::StartDhcpService(const std::string &iface, const std::string &ipv4addr)
918 {
919     NETMGR_LOG_I("StartDhcpService: iface[%{public}s], ipv4addr[%{public}s]",
920         iface.c_str(), ToAnonymousIp(ipv4addr).c_str());
921     // LCOV_EXCL_START This will never happen.
922     if (netsysService_ == nullptr) {
923         NETMGR_LOG_E("netsysService_ is null");
924         return NETSYS_NETSYSSERVICE_NULL;
925     }
926     // LCOV_EXCL_STOP
927     return netsysService_->StartDhcpService(iface, ipv4addr);
928 }
929 
StopDhcpService(const std::string & iface)930 int32_t NetsysController::StopDhcpService(const std::string &iface)
931 {
932     NETMGR_LOG_I("StopDhcpService: ifaceFd[%{public}s]", iface.c_str());
933     // LCOV_EXCL_START This will never happen.
934     if (netsysService_ == nullptr) {
935         NETMGR_LOG_E("netsysService_ is null");
936         return NETSYS_NETSYSSERVICE_NULL;
937     }
938     // LCOV_EXCL_STOP
939     return netsysService_->StopDhcpService(iface);
940 }
941 
BandwidthEnableDataSaver(bool enable)942 int32_t NetsysController::BandwidthEnableDataSaver(bool enable)
943 {
944     NETMGR_LOG_D("NetsysController::BandwidthEnableDataSaver: enable=%{public}d", enable);
945     // LCOV_EXCL_START This will never happen.
946     if (netsysService_ == nullptr) {
947         NETMGR_LOG_E("netsysService_ is null");
948         return NETSYS_NETSYSSERVICE_NULL;
949     }
950     // LCOV_EXCL_STOP
951     return netsysService_->BandwidthEnableDataSaver(enable);
952 }
953 
BandwidthSetIfaceQuota(const std::string & ifName,int64_t bytes)954 int32_t NetsysController::BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes)
955 {
956     NETMGR_LOG_D("NetsysController::BandwidthSetIfaceQuota: ifName=%{public}s", ifName.c_str());
957     // LCOV_EXCL_START This will never happen.
958     if (netsysService_ == nullptr) {
959         NETMGR_LOG_E("netsysService_ is null");
960         return NETSYS_NETSYSSERVICE_NULL;
961     }
962     // LCOV_EXCL_STOP
963     return netsysService_->BandwidthSetIfaceQuota(ifName, bytes);
964 }
965 
BandwidthRemoveIfaceQuota(const std::string & ifName)966 int32_t NetsysController::BandwidthRemoveIfaceQuota(const std::string &ifName)
967 {
968     NETMGR_LOG_D("NetsysController::BandwidthRemoveIfaceQuota: ifName=%{public}s", ifName.c_str());
969     // LCOV_EXCL_START This will never happen.
970     if (netsysService_ == nullptr) {
971         NETMGR_LOG_E("netsysService_ is null");
972         return NETSYS_NETSYSSERVICE_NULL;
973     }
974     // LCOV_EXCL_STOP
975     return netsysService_->BandwidthRemoveIfaceQuota(ifName);
976 }
977 
BandwidthAddDeniedList(uint32_t uid)978 int32_t NetsysController::BandwidthAddDeniedList(uint32_t uid)
979 {
980     NETMGR_LOG_D("NetsysController::BandwidthAddDeniedList: uid=%{public}d", uid);
981     // LCOV_EXCL_START This will never happen.
982     if (netsysService_ == nullptr) {
983         NETMGR_LOG_E("netsysService_ is null");
984         return NETSYS_NETSYSSERVICE_NULL;
985     }
986     // LCOV_EXCL_STOP
987     return netsysService_->BandwidthAddDeniedList(uid);
988 }
989 
BandwidthRemoveDeniedList(uint32_t uid)990 int32_t NetsysController::BandwidthRemoveDeniedList(uint32_t uid)
991 {
992     NETMGR_LOG_D("NetsysController::BandwidthRemoveDeniedList: uid=%{public}d", uid);
993     // LCOV_EXCL_START This will never happen.
994     if (netsysService_ == nullptr) {
995         NETMGR_LOG_E("netsysService_ is null");
996         return NETSYS_NETSYSSERVICE_NULL;
997     }
998     // LCOV_EXCL_STOP
999     return netsysService_->BandwidthRemoveDeniedList(uid);
1000 }
1001 
BandwidthAddAllowedList(uint32_t uid)1002 int32_t NetsysController::BandwidthAddAllowedList(uint32_t uid)
1003 {
1004     NETMGR_LOG_D("NetsysController::BandwidthAddAllowedList: uid=%{public}d", uid);
1005     // LCOV_EXCL_START This will never happen.
1006     if (netsysService_ == nullptr) {
1007         NETMGR_LOG_E("netsysService_ is null");
1008         return NETSYS_NETSYSSERVICE_NULL;
1009     }
1010     // LCOV_EXCL_STOP
1011     return netsysService_->BandwidthAddAllowedList(uid);
1012 }
1013 
BandwidthRemoveAllowedList(uint32_t uid)1014 int32_t NetsysController::BandwidthRemoveAllowedList(uint32_t uid)
1015 {
1016     NETMGR_LOG_D("NetsysController::BandwidthRemoveAllowedList: uid=%{public}d", uid);
1017     // LCOV_EXCL_START This will never happen.
1018     if (netsysService_ == nullptr) {
1019         NETMGR_LOG_E("netsysService_ is null");
1020         return NETSYS_NETSYSSERVICE_NULL;
1021     }
1022     // LCOV_EXCL_STOP
1023     return netsysService_->BandwidthRemoveAllowedList(uid);
1024 }
1025 
FirewallSetUidsAllowedListChain(uint32_t chain,const std::vector<uint32_t> & uids)1026 int32_t NetsysController::FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
1027 {
1028     NETMGR_LOG_I("NetsysController::FirewallSetUidsAllowedListChain: chain=%{public}d", chain);
1029     // LCOV_EXCL_START This will never happen.
1030     if (netsysService_ == nullptr) {
1031         NETMGR_LOG_E("netsysService_ is null");
1032         return NETSYS_NETSYSSERVICE_NULL;
1033     }
1034     // LCOV_EXCL_STOP
1035     return netsysService_->FirewallSetUidsAllowedListChain(chain, uids);
1036 }
1037 
FirewallSetUidsDeniedListChain(uint32_t chain,const std::vector<uint32_t> & uids)1038 int32_t NetsysController::FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
1039 {
1040     NETMGR_LOG_I("NetsysController::FirewallSetUidsDeniedListChain: chain=%{public}d", chain);
1041     // LCOV_EXCL_START This will never happen.
1042     if (netsysService_ == nullptr) {
1043         NETMGR_LOG_E("netsysService_ is null");
1044         return NETSYS_NETSYSSERVICE_NULL;
1045     }
1046     // LCOV_EXCL_STOP
1047     return netsysService_->FirewallSetUidsDeniedListChain(chain, uids);
1048 }
1049 
FirewallEnableChain(uint32_t chain,bool enable)1050 int32_t NetsysController::FirewallEnableChain(uint32_t chain, bool enable)
1051 {
1052     NETMGR_LOG_I("NetsysController::FirewallEnableChain: chain=%{public}d, enable=%{public}d", chain, enable);
1053     // LCOV_EXCL_START This will never happen.
1054     if (netsysService_ == nullptr) {
1055         NETMGR_LOG_E("netsysService_ is null");
1056         return NETSYS_NETSYSSERVICE_NULL;
1057     }
1058     // LCOV_EXCL_STOP
1059     return netsysService_->FirewallEnableChain(chain, enable);
1060 }
1061 
FirewallSetUidRule(uint32_t chain,const std::vector<uint32_t> & uids,uint32_t firewallRule)1062 int32_t NetsysController::FirewallSetUidRule(uint32_t chain, const std::vector<uint32_t> &uids, uint32_t firewallRule)
1063 {
1064     NETMGR_LOG_I("NetsysController::FirewallSetUidRule Start");
1065     // LCOV_EXCL_START This will never happen.
1066     if (netsysService_ == nullptr) {
1067         NETMGR_LOG_E("netsysService_ is null");
1068         return NETSYS_NETSYSSERVICE_NULL;
1069     }
1070     // LCOV_EXCL_STOP
1071     return netsysService_->FirewallSetUidRule(chain, uids, firewallRule);
1072 }
1073 
FreeAddrInfo(addrinfo * aihead)1074 void NetsysController::FreeAddrInfo(addrinfo *aihead)
1075 {
1076     addrinfo *tmpNext = nullptr;
1077     for (addrinfo *tmp = aihead; tmp != nullptr;) {
1078         if (tmp->ai_addr != nullptr) {
1079             free(tmp->ai_addr);
1080         }
1081         if (tmp->ai_canonname != nullptr) {
1082             free(tmp->ai_canonname);
1083         }
1084         tmpNext = tmp->ai_next;
1085         free(tmp);
1086         tmp = tmpNext;
1087     }
1088 }
1089 
GetTotalStats(uint64_t & stats,uint32_t type)1090 int32_t NetsysController::GetTotalStats(uint64_t &stats, uint32_t type)
1091 {
1092     // LCOV_EXCL_START This will never happen.
1093     if (netsysService_ == nullptr) {
1094         NETMGR_LOG_E("netsysService is null");
1095         return NETSYS_NETSYSSERVICE_NULL;
1096     }
1097     // LCOV_EXCL_STOP
1098     return netsysService_->GetTotalStats(stats, static_cast<uint32_t>(type));
1099 }
1100 
GetUidStats(uint64_t & stats,uint32_t type,uint32_t uid)1101 int32_t NetsysController::GetUidStats(uint64_t &stats, uint32_t type, uint32_t uid)
1102 {
1103     // LCOV_EXCL_START This will never happen.
1104     if (netsysService_ == nullptr) {
1105         NETMGR_LOG_E("netsysService is null");
1106         return NETSYS_NETSYSSERVICE_NULL;
1107     }
1108     // LCOV_EXCL_STOP
1109     return netsysService_->GetUidStats(stats, static_cast<uint32_t>(type), uid);
1110 }
1111 
GetIfaceStats(uint64_t & stats,uint32_t type,const std::string & interfaceName)1112 int32_t NetsysController::GetIfaceStats(uint64_t &stats, uint32_t type, const std::string &interfaceName)
1113 {
1114     // LCOV_EXCL_START This will never happen.
1115     if (netsysService_ == nullptr) {
1116         NETMGR_LOG_E("netsysService is null");
1117         return NETSYS_NETSYSSERVICE_NULL;
1118     }
1119     // LCOV_EXCL_STOP
1120     return netsysService_->GetIfaceStats(stats, static_cast<uint32_t>(type), interfaceName);
1121 }
1122 
GetAllSimStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> & stats)1123 int32_t NetsysController::GetAllSimStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats)
1124 {
1125     // LCOV_EXCL_START This will never happen.
1126     if (netsysService_ == nullptr) {
1127         NETMGR_LOG_E("netsysService is null");
1128         return NETSYS_NETSYSSERVICE_NULL;
1129     }
1130     // LCOV_EXCL_STOP
1131     return netsysService_->GetAllSimStatsInfo(stats);
1132 }
1133 
DeleteSimStatsInfo(uint32_t uid)1134 int32_t NetsysController::DeleteSimStatsInfo(uint32_t uid)
1135 {
1136     // LCOV_EXCL_START This will never happen.
1137     if (netsysService_ == nullptr) {
1138         NETMGR_LOG_E("netsysService is null");
1139         return NETSYS_NETSYSSERVICE_NULL;
1140     }
1141     // LCOV_EXCL_STOP
1142     return netsysService_->DeleteSimStatsInfo(uid);
1143 }
1144 
GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> & stats)1145 int32_t NetsysController::GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats)
1146 {
1147     // LCOV_EXCL_START This will never happen.
1148     if (netsysService_ == nullptr) {
1149         NETMGR_LOG_E("netsysService is null");
1150         return NETSYS_NETSYSSERVICE_NULL;
1151     }
1152     // LCOV_EXCL_STOP
1153     return netsysService_->GetAllStatsInfo(stats);
1154 }
1155 
DeleteStatsInfo(uint32_t uid)1156 int32_t NetsysController::DeleteStatsInfo(uint32_t uid)
1157 {
1158     // LCOV_EXCL_START This will never happen.
1159     if (netsysService_ == nullptr) {
1160         NETMGR_LOG_E("netsysService is null");
1161         return NETSYS_NETSYSSERVICE_NULL;
1162     }
1163     // LCOV_EXCL_STOP
1164     return netsysService_->DeleteStatsInfo(uid);
1165 }
1166 
SetNetStateTrafficMap(uint8_t flag,uint64_t availableTraffic)1167 int32_t NetsysController::SetNetStateTrafficMap(uint8_t flag, uint64_t availableTraffic)
1168 {
1169     // LCOV_EXCL_START This will never happen.
1170     if (netsysService_ == nullptr) {
1171         NETMGR_LOG_E("netsysService is null");
1172         return NETSYS_NETSYSSERVICE_NULL;
1173     }
1174     // LCOV_EXCL_STOP
1175     return netsysService_->SetNetStateTrafficMap(flag, availableTraffic);
1176 }
GetNetStateTrafficMap(uint8_t flag,uint64_t & availableTraffic)1177 int32_t NetsysController::GetNetStateTrafficMap(uint8_t flag, uint64_t &availableTraffic)
1178 {
1179     // LCOV_EXCL_START This will never happen.
1180     if (netsysService_ == nullptr) {
1181         NETMGR_LOG_E("netsysService is null");
1182         return NETSYS_NETSYSSERVICE_NULL;
1183     }
1184     // LCOV_EXCL_STOP
1185     return netsysService_->GetNetStateTrafficMap(flag, availableTraffic);
1186 }
1187 
ClearIncreaseTrafficMap()1188 int32_t NetsysController::ClearIncreaseTrafficMap()
1189 {
1190     // LCOV_EXCL_START This will never happen.
1191     if (netsysService_ == nullptr) {
1192         NETMGR_LOG_E("netsysService is null");
1193         return NETSYS_NETSYSSERVICE_NULL;
1194     }
1195     // LCOV_EXCL_STOP
1196     return netsysService_->ClearIncreaseTrafficMap();
1197 }
1198 
UpdateIfIndexMap(int8_t key,uint64_t index)1199 int32_t NetsysController::UpdateIfIndexMap(int8_t key, uint64_t index)
1200 {
1201     // LCOV_EXCL_START This will never happen.
1202     if (netsysService_ == nullptr) {
1203         NETMGR_LOG_E("netsysService is null");
1204         return NETSYS_NETSYSSERVICE_NULL;
1205     }
1206     // LCOV_EXCL_STOP
1207     return netsysService_->UpdateIfIndexMap(key, index);
1208 }
1209 
SetIptablesCommandForRes(const std::string & cmd,std::string & respond,NetsysNative::IptablesType ipType)1210 int32_t NetsysController::SetIptablesCommandForRes(const std::string &cmd, std::string &respond,
1211     NetsysNative::IptablesType ipType)
1212 {
1213     if (cmd.empty()) {
1214         NETMGR_LOG_E("SetIptablesCommandForRes cmd is empty");
1215         return ERR_INVALID_DATA;
1216     }
1217     // LCOV_EXCL_START This will never happen.
1218     if (netsysService_ == nullptr) {
1219         NETMGR_LOG_E("SetIptablesCommandForRes netsysService is null");
1220         return NETSYS_NETSYSSERVICE_NULL;
1221     }
1222     // LCOV_EXCL_STOP
1223     NETMGR_LOG_I("SetIptablesCommandForRes, iptables is %{public}d.", ipType);
1224     return netsysService_->SetIptablesCommandForRes(cmd, respond, ipType);
1225 }
1226 
SetIpCommandForRes(const std::string & cmd,std::string & respond)1227 int32_t NetsysController::SetIpCommandForRes(const std::string &cmd, std::string &respond)
1228 {
1229     if (cmd.empty()) {
1230         NETMGR_LOG_E("SetIpCommandForRes cmd is empty");
1231         return ERR_INVALID_DATA;
1232     }
1233     // LCOV_EXCL_START This will never happen.
1234     if (netsysService_ == nullptr) {
1235         NETMGR_LOG_E("SetIpCommandForRes netsysService is null");
1236         return NETSYS_NETSYSSERVICE_NULL;
1237     }
1238     // LCOV_EXCL_STOP
1239     NETMGR_LOG_I("SetIpCommandForRes");
1240     return netsysService_->SetIpCommandForRes(cmd, respond);
1241 }
1242 
NetDiagPingHost(const OHOS::NetsysNative::NetDiagPingOption & pingOption,const sptr<OHOS::NetsysNative::INetDiagCallback> & callback)1243 int32_t NetsysController::NetDiagPingHost(const OHOS::NetsysNative::NetDiagPingOption &pingOption,
1244                                           const sptr<OHOS::NetsysNative::INetDiagCallback> &callback)
1245 {
1246     // LCOV_EXCL_START This will never happen.
1247     if (netsysService_ == nullptr) {
1248         NETMGR_LOG_E("netsysService is null");
1249         return NETSYS_NETSYSSERVICE_NULL;
1250     }
1251     // LCOV_EXCL_STOP
1252     return netsysService_->NetDiagPingHost(pingOption, callback);
1253 }
1254 
NetDiagGetRouteTable(std::list<OHOS::NetsysNative::NetDiagRouteTable> & routeTables)1255 int32_t NetsysController::NetDiagGetRouteTable(std::list<OHOS::NetsysNative::NetDiagRouteTable> &routeTables)
1256 {
1257     // LCOV_EXCL_START This will never happen.
1258     if (netsysService_ == nullptr) {
1259         NETMGR_LOG_E("netsysService is null");
1260         return NETSYS_NETSYSSERVICE_NULL;
1261     }
1262     // LCOV_EXCL_STOP
1263     return netsysService_->NetDiagGetRouteTable(routeTables);
1264 }
1265 
NetDiagGetSocketsInfo(OHOS::NetsysNative::NetDiagProtocolType socketType,OHOS::NetsysNative::NetDiagSocketsInfo & socketsInfo)1266 int32_t NetsysController::NetDiagGetSocketsInfo(OHOS::NetsysNative::NetDiagProtocolType socketType,
1267                                                 OHOS::NetsysNative::NetDiagSocketsInfo &socketsInfo)
1268 {
1269     // LCOV_EXCL_START This will never happen.
1270     if (netsysService_ == nullptr) {
1271         NETMGR_LOG_E("netsysService is null");
1272         return NETSYS_NETSYSSERVICE_NULL;
1273     }
1274     // LCOV_EXCL_STOP
1275     return netsysService_->NetDiagGetSocketsInfo(socketType, socketsInfo);
1276 }
1277 
NetDiagGetInterfaceConfig(std::list<OHOS::NetsysNative::NetDiagIfaceConfig> & configs,const std::string & ifaceName)1278 int32_t NetsysController::NetDiagGetInterfaceConfig(std::list<OHOS::NetsysNative::NetDiagIfaceConfig> &configs,
1279                                                     const std::string &ifaceName)
1280 {
1281     // LCOV_EXCL_START This will never happen.
1282     if (netsysService_ == nullptr) {
1283         NETMGR_LOG_E("netsysService is null");
1284         return NETSYS_NETSYSSERVICE_NULL;
1285     }
1286     // LCOV_EXCL_STOP
1287     return netsysService_->NetDiagGetInterfaceConfig(configs, ifaceName);
1288 }
1289 
NetDiagUpdateInterfaceConfig(const OHOS::NetsysNative::NetDiagIfaceConfig & config,const std::string & ifaceName,bool add)1290 int32_t NetsysController::NetDiagUpdateInterfaceConfig(const OHOS::NetsysNative::NetDiagIfaceConfig &config,
1291                                                        const std::string &ifaceName, bool add)
1292 {
1293     // LCOV_EXCL_START This will never happen.
1294     if (netsysService_ == nullptr) {
1295         NETMGR_LOG_E("netsysService is null");
1296         return NETSYS_NETSYSSERVICE_NULL;
1297     }
1298     // LCOV_EXCL_STOP
1299     return netsysService_->NetDiagUpdateInterfaceConfig(config, ifaceName, add);
1300 }
1301 
NetDiagSetInterfaceActiveState(const std::string & ifaceName,bool up)1302 int32_t NetsysController::NetDiagSetInterfaceActiveState(const std::string &ifaceName, bool up)
1303 {
1304     // LCOV_EXCL_START This will never happen.
1305     if (netsysService_ == nullptr) {
1306         NETMGR_LOG_E("netsysService is null");
1307         return NETSYS_NETSYSSERVICE_NULL;
1308     }
1309     // LCOV_EXCL_STOP
1310     return netsysService_->NetDiagSetInterfaceActiveState(ifaceName, up);
1311 }
1312 
AddStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)1313 int32_t NetsysController::AddStaticArp(const std::string &ipAddr, const std::string &macAddr,
1314                                        const std::string &ifName)
1315 {
1316     // LCOV_EXCL_START This will never happen.
1317     if (netsysService_ == nullptr) {
1318         NETMGR_LOG_E("AddStaticArp netsysService is null");
1319         return NETSYS_NETSYSSERVICE_NULL;
1320     }
1321     // LCOV_EXCL_STOP
1322     return netsysService_->AddStaticArp(ipAddr, macAddr, ifName);
1323 }
1324 
DelStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)1325 int32_t NetsysController::DelStaticArp(const std::string &ipAddr, const std::string &macAddr,
1326                                        const std::string &ifName)
1327 {
1328     // LCOV_EXCL_START This will never happen.
1329     if (netsysService_ == nullptr) {
1330         NETMGR_LOG_E("DelStaticArp netsysService is null");
1331         return NETSYS_NETSYSSERVICE_NULL;
1332     }
1333     // LCOV_EXCL_STOP
1334     return netsysService_->DelStaticArp(ipAddr, macAddr, ifName);
1335 }
1336 
RegisterDnsResultCallback(const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> & callback,uint32_t timeStep)1337 int32_t NetsysController::RegisterDnsResultCallback(
1338     const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback, uint32_t timeStep)
1339 {
1340     // LCOV_EXCL_START This will never happen.
1341     if (netsysService_ == nullptr) {
1342         NETMGR_LOG_E("netsysService is null");
1343         return NETSYS_NETSYSSERVICE_NULL;
1344     }
1345     // LCOV_EXCL_STOP
1346     return netsysService_->RegisterDnsResultCallback(callback, timeStep);
1347 }
1348 
UnregisterDnsResultCallback(const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> & callback)1349 int32_t NetsysController::UnregisterDnsResultCallback(
1350     const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback)
1351 {
1352     // LCOV_EXCL_START This will never happen.
1353     if (netsysService_ == nullptr) {
1354         NETMGR_LOG_E("netsysService is null");
1355         return NETSYS_NETSYSSERVICE_NULL;
1356     }
1357     // LCOV_EXCL_STOP
1358     return netsysService_->UnregisterDnsResultCallback(callback);
1359 }
1360 
RegisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> & callback)1361 int32_t NetsysController::RegisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> &callback)
1362 {
1363     // LCOV_EXCL_START This will never happen.
1364     if (netsysService_ == nullptr) {
1365         NETMGR_LOG_E("netsysService is null");
1366         return NETSYS_NETSYSSERVICE_NULL;
1367     }
1368     // LCOV_EXCL_STOP
1369     return netsysService_->RegisterDnsHealthCallback(callback);
1370 }
1371 
UnregisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> & callback)1372 int32_t NetsysController::UnregisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> &callback)
1373 {
1374     // LCOV_EXCL_START This will never happen.
1375     if (netsysService_ == nullptr) {
1376         NETMGR_LOG_E("netsysService is null");
1377         return NETSYS_NETSYSSERVICE_NULL;
1378     }
1379     // LCOV_EXCL_STOP
1380     return netsysService_->UnregisterDnsHealthCallback(callback);
1381 }
1382 
GetCookieStats(uint64_t & stats,uint32_t type,uint64_t cookie)1383 int32_t NetsysController::GetCookieStats(uint64_t &stats, uint32_t type, uint64_t cookie)
1384 {
1385     // LCOV_EXCL_START This will never happen.
1386     if (netsysService_ == nullptr) {
1387         NETMGR_LOG_E("GetCookieStats netsysService is null");
1388         return NETSYS_NETSYSSERVICE_NULL;
1389     }
1390     // LCOV_EXCL_STOP
1391     return netsysService_->GetCookieStats(stats, type, cookie);
1392 }
1393 
GetNetworkSharingType(std::set<uint32_t> & sharingTypeIsOn)1394 int32_t NetsysController::GetNetworkSharingType(std::set<uint32_t>& sharingTypeIsOn)
1395 {
1396     // LCOV_EXCL_START This will never happen.
1397     if (netsysService_ == nullptr) {
1398         NETMGR_LOG_E("GetNetworkSharingType netsysService is null");
1399         return NETSYS_NETSYSSERVICE_NULL;
1400     }
1401     // LCOV_EXCL_STOP
1402     return netsysService_->GetNetworkSharingType(sharingTypeIsOn);
1403 }
1404 
UpdateNetworkSharingType(uint32_t type,bool isOpen)1405 int32_t NetsysController::UpdateNetworkSharingType(uint32_t type, bool isOpen)
1406 {
1407     // LCOV_EXCL_START This will never happen.
1408     if (netsysService_ == nullptr) {
1409         NETMGR_LOG_E("UpdateNetworkSharingType netsysService is null");
1410         return NETSYS_NETSYSSERVICE_NULL;
1411     }
1412     // LCOV_EXCL_STOP
1413     return netsysService_->UpdateNetworkSharingType(type, isOpen);
1414 }
1415 
1416 #ifdef FEATURE_NET_FIREWALL_ENABLE
SetFirewallRules(NetFirewallRuleType type,const std::vector<sptr<NetFirewallBaseRule>> & ruleList,bool isFinish)1417 int32_t NetsysController::SetFirewallRules(NetFirewallRuleType type,
1418                                            const std::vector<sptr<NetFirewallBaseRule>> &ruleList, bool isFinish)
1419 {
1420     NETMGR_LOG_I("NetsysController::SetFirewallRules");
1421     // LCOV_EXCL_START This will never happen.
1422     if (netsysService_ == nullptr) {
1423         NETMGR_LOG_E("SetFirewallRules netsysService is null");
1424         return NETSYS_NETSYSSERVICE_NULL;
1425     }
1426     // LCOV_EXCL_STOP
1427     return netsysService_->SetFirewallRules(type, ruleList, isFinish);
1428 }
1429 
SetFirewallDefaultAction(int32_t userId,FirewallRuleAction inDefault,FirewallRuleAction outDefault)1430 int32_t NetsysController::SetFirewallDefaultAction(int32_t userId, FirewallRuleAction inDefault,
1431     FirewallRuleAction outDefault)
1432 {
1433     NETMGR_LOG_I("NetsysController::SetFirewallDefaultAction");
1434     // LCOV_EXCL_START This will never happen.
1435     if (netsysService_ == nullptr) {
1436         NETMGR_LOG_E("SetFirewallDefaultAction netsysService is null");
1437         return NETSYS_NETSYSSERVICE_NULL;
1438     }
1439     // LCOV_EXCL_STOP
1440     return netsysService_->SetFirewallDefaultAction(userId, inDefault, outDefault);
1441 }
1442 
SetFirewallCurrentUserId(int32_t userId)1443 int32_t NetsysController::SetFirewallCurrentUserId(int32_t userId)
1444 {
1445     NETMGR_LOG_I("NetsysController::SetFirewallCurrentUserId");
1446     // LCOV_EXCL_START This will never happen.
1447     if (netsysService_ == nullptr) {
1448         NETMGR_LOG_E("SetFirewallCurrentUserId netsysService is null");
1449         return NETSYS_NETSYSSERVICE_NULL;
1450     }
1451     // LCOV_EXCL_STOP
1452     return netsysService_->SetFirewallCurrentUserId(userId);
1453 }
1454 
ClearFirewallRules(NetFirewallRuleType type)1455 int32_t NetsysController::ClearFirewallRules(NetFirewallRuleType type)
1456 {
1457     NETMGR_LOG_I("NetsysController::ClearFirewallRules");
1458     // LCOV_EXCL_START This will never happen.
1459     if (netsysService_ == nullptr) {
1460         NETMGR_LOG_E("ClearFirewallRules netsysService is null");
1461         return NETSYS_NETSYSSERVICE_NULL;
1462     }
1463     // LCOV_EXCL_STOP
1464     return netsysService_->ClearFirewallRules(type);
1465 }
1466 
RegisterNetFirewallCallback(const sptr<NetsysNative::INetFirewallCallback> & callback)1467 int32_t NetsysController::RegisterNetFirewallCallback(const sptr<NetsysNative::INetFirewallCallback> &callback)
1468 {
1469     // LCOV_EXCL_START This will never happen.
1470     if (netsysService_ == nullptr) {
1471         NETMGR_LOG_E("netsysService is null");
1472         return NETSYS_NETSYSSERVICE_NULL;
1473     }
1474     // LCOV_EXCL_STOP
1475     return netsysService_->RegisterNetFirewallCallback(callback);
1476 }
1477 
UnRegisterNetFirewallCallback(const sptr<NetsysNative::INetFirewallCallback> & callback)1478 int32_t NetsysController::UnRegisterNetFirewallCallback(const sptr<NetsysNative::INetFirewallCallback> &callback)
1479 {
1480     // LCOV_EXCL_START This will never happen.
1481     if (netsysService_ == nullptr) {
1482         NETMGR_LOG_E("netsysService is null");
1483         return NETSYS_NETSYSSERVICE_NULL;
1484     }
1485     // LCOV_EXCL_STOP
1486     return netsysService_->UnRegisterNetFirewallCallback(callback);
1487 }
1488 #endif
1489 
1490 #ifdef FEATURE_WEARABLE_DISTRIBUTED_NET_ENABLE
EnableWearableDistributedNetForward(const int32_t tcpPortId,const int32_t udpPortId)1491 int32_t NetsysController::EnableWearableDistributedNetForward(const int32_t tcpPortId, const int32_t udpPortId)
1492 {
1493     if (netsysService_ == nullptr) {
1494         NETMGR_LOG_E("NetsysService is null in EnableWearableDistributedNetForward");
1495         return NETSYS_NETSYSSERVICE_NULL;
1496     }
1497     return netsysService_->EnableWearableDistributedNetForward(tcpPortId, udpPortId);
1498 }
1499 
DisableWearableDistributedNetForward()1500 int32_t NetsysController::DisableWearableDistributedNetForward()
1501 {
1502     if (netsysService_ == nullptr) {
1503         NETMGR_LOG_E("NetsysService is null in DisableWearableDistributedNetForward");
1504         return NETSYS_NETSYSSERVICE_NULL;
1505     }
1506     return netsysService_->DisableWearableDistributedNetForward();
1507 }
1508 #endif
1509 
RegisterNetsysTrafficCallback(const sptr<NetsysNative::INetsysTrafficCallback> & callback)1510 int32_t NetsysController::RegisterNetsysTrafficCallback(const sptr<NetsysNative::INetsysTrafficCallback> &callback)
1511 {
1512     NETMGR_LOG_E("RegisterNetsysTrafficCallback start");
1513     // LCOV_EXCL_START This will never happen.
1514     if (netsysService_ == nullptr) {
1515         NETMGR_LOG_E("netsysService is null");
1516         return NETSYS_NETSYSSERVICE_NULL;
1517     }
1518     // LCOV_EXCL_STOP
1519     return netsysService_->RegisterNetsysTrafficCallback(callback);
1520 }
1521 
UnRegisterNetsysTrafficCallback(const sptr<NetsysNative::INetsysTrafficCallback> & callback)1522 int32_t NetsysController::UnRegisterNetsysTrafficCallback(const sptr<NetsysNative::INetsysTrafficCallback> &callback)
1523 {
1524     // LCOV_EXCL_START This will never happen.
1525     if (netsysService_ == nullptr) {
1526         NETMGR_LOG_E("netsysService is null");
1527         return NETSYS_NETSYSSERVICE_NULL;
1528     }
1529     // LCOV_EXCL_STOP
1530     return netsysService_->UnRegisterNetsysTrafficCallback(callback);
1531 }
1532 
SetIpv6PrivacyExtensions(const std::string & interfaceName,const uint32_t on)1533 int32_t NetsysController::SetIpv6PrivacyExtensions(const std::string &interfaceName, const uint32_t on)
1534 {
1535     // LCOV_EXCL_START This will never happen.
1536     if (netsysService_ == nullptr) {
1537         NETMGR_LOG_E("SetIpv6PrivacyExtensions netsysService is null");
1538         return NETSYS_NETSYSSERVICE_NULL;
1539     }
1540     // LCOV_EXCL_STOP
1541     return netsysService_->SetIpv6PrivacyExtensions(interfaceName, on);
1542 }
1543 
SetEnableIpv6(const std::string & interfaceName,const uint32_t on)1544 int32_t NetsysController::SetEnableIpv6(const std::string &interfaceName, const uint32_t on)
1545 {
1546     // LCOV_EXCL_START This will never happen.
1547     if (netsysService_ == nullptr) {
1548         NETMGR_LOG_E("SetEnableIpv6 netsysService is null");
1549         return NETSYS_NETSYSSERVICE_NULL;
1550     }
1551     // LCOV_EXCL_STOP
1552     return netsysService_->SetEnableIpv6(interfaceName, on);
1553 }
1554 
SetNetworkAccessPolicy(uint32_t uid,NetworkAccessPolicy policy,bool reconfirmFlag)1555 int32_t NetsysController::SetNetworkAccessPolicy(uint32_t uid, NetworkAccessPolicy policy, bool reconfirmFlag)
1556 {
1557     // LCOV_EXCL_START This will never happen.
1558     if (netsysService_ == nullptr) {
1559         NETMGR_LOG_E("netsysService_ is null");
1560         return NETSYS_NETSYSSERVICE_NULL;
1561     }
1562     // LCOV_EXCL_STOP
1563     return netsysService_->SetNetworkAccessPolicy(uid, policy, reconfirmFlag);
1564 }
1565 
NotifyNetBearerTypeChange(std::set<NetBearType> bearerTypes)1566 int32_t NetsysController::NotifyNetBearerTypeChange(std::set<NetBearType> bearerTypes)
1567 {
1568     // LCOV_EXCL_START This will never happen.
1569     if (netsysService_ == nullptr) {
1570         NETMGR_LOG_E("netsysService_ is null");
1571         return NETSYS_NETSYSSERVICE_NULL;
1572     }
1573     // LCOV_EXCL_STOP
1574     return netsysService_->NotifyNetBearerTypeChange(bearerTypes);
1575 }
1576 
DeleteNetworkAccessPolicy(uint32_t uid)1577 int32_t NetsysController::DeleteNetworkAccessPolicy(uint32_t uid)
1578 {
1579     // LCOV_EXCL_START This will never happen.
1580     if (netsysService_ == nullptr) {
1581         NETMGR_LOG_E("netsysService_ is null");
1582         return NETSYS_NETSYSSERVICE_NULL;
1583     }
1584     // LCOV_EXCL_STOP
1585     return netsysService_->DeleteNetworkAccessPolicy(uid);
1586 }
1587 
ClearFirewallAllRules()1588 int32_t NetsysController::ClearFirewallAllRules()
1589 {
1590     // LCOV_EXCL_START This will never happen.
1591     if (netsysService_ == nullptr) {
1592         NETMGR_LOG_E("netsysService_ is null");
1593         return NETSYS_NETSYSSERVICE_NULL;
1594     }
1595     // LCOV_EXCL_STOP
1596     return netsysService_->ClearFirewallAllRules();
1597 }
1598 
StartClat(const std::string & interfaceName,int32_t netId,const std::string & nat64PrefixStr)1599 int32_t NetsysController::StartClat(const std::string &interfaceName, int32_t netId, const std::string &nat64PrefixStr)
1600 {
1601     // LCOV_EXCL_START This will never happen.
1602     if (netsysService_ == nullptr) {
1603         NETMGR_LOG_E("StartClat netsysService is null");
1604         return NETSYS_NETSYSSERVICE_NULL;
1605     }
1606     // LCOV_EXCL_STOP
1607     return netsysService_->StartClat(interfaceName, netId, nat64PrefixStr);
1608 }
1609 
StopClat(const std::string & interfaceName)1610 int32_t NetsysController::StopClat(const std::string &interfaceName)
1611 {
1612     // LCOV_EXCL_START This will never happen.
1613     if (netsysService_ == nullptr) {
1614         NETMGR_LOG_E("StopClat netsysService is null");
1615         return NETSYS_NETSYSSERVICE_NULL;
1616     }
1617     // LCOV_EXCL_STOP
1618     return netsysService_->StopClat(interfaceName);
1619 }
1620 
SetNicTrafficAllowed(const std::vector<std::string> & ifaceNames,bool status)1621 int32_t NetsysController::SetNicTrafficAllowed(const std::vector<std::string> &ifaceNames, bool status)
1622 {
1623     // LCOV_EXCL_START This will never happen.
1624     if (netsysService_ == nullptr) {
1625         NETMGR_LOG_E("SetNicTrafficAllowed netsysService is null");
1626         return NETSYS_NETSYSSERVICE_NULL;
1627     }
1628     // LCOV_EXCL_STOP
1629     return netsysService_->SetNicTrafficAllowed(ifaceNames, status);
1630 }
1631 
SetUserDefinedServerFlag(uint16_t netId,bool isUserDefinedServer)1632 int32_t NetsysController::SetUserDefinedServerFlag(uint16_t netId, bool isUserDefinedServer)
1633 {
1634     if (netsysService_ == nullptr) {
1635         NETMGR_LOG_E("SetUserDefinedServerFlag netsysService is null");
1636         return NETSYS_NETSYSSERVICE_NULL;
1637     }
1638     return netsysService_->SetUserDefinedServerFlag(netId, isUserDefinedServer);
1639 }
1640 
1641 #ifdef SUPPORT_SYSVPN
ProcessVpnStage(NetsysNative::SysVpnStageCode stage)1642 int32_t NetsysController::ProcessVpnStage(NetsysNative::SysVpnStageCode stage)
1643 {
1644     // LCOV_EXCL_START This will never happen.
1645     if (netsysService_ == nullptr) {
1646         NETMGR_LOG_E("ProcessVpnStage netsysService is null");
1647         return NETSYS_NETSYSSERVICE_NULL;
1648     }
1649     // LCOV_EXCL_STOP
1650     return netsysService_->ProcessVpnStage(stage);
1651 }
1652 #endif // SUPPORT_SYSVPN
1653 
CloseSocketsUid(const std::string & ipAddr,uint32_t uid)1654 int32_t NetsysController::CloseSocketsUid(const std::string &ipAddr, uint32_t uid)
1655 {
1656     NETMGR_LOG_D("Set CloseSocketsUid: uid[%{public}d]", uid);
1657     if (netsysService_ == nullptr) {
1658         NETMGR_LOG_E("netsysService_ is null");
1659         return NETSYS_NETSYSSERVICE_NULL;
1660     }
1661     return netsysService_->CloseSocketsUid(ipAddr, uid);
1662 }
1663 
SetBrokerUidAccessPolicyMap(const std::unordered_map<uint32_t,uint32_t> & uidMaps)1664 int32_t NetsysController::SetBrokerUidAccessPolicyMap(const std::unordered_map<uint32_t, uint32_t> &uidMaps)
1665 {
1666     NETMGR_LOG_D("SetBrokerUidAccessPolicyMap Enter");
1667     if (netsysService_ == nullptr) {
1668         NETMGR_LOG_E("netsysService_ is null");
1669         return NETSYS_NETSYSSERVICE_NULL;
1670     }
1671     return netsysService_->SetBrokerUidAccessPolicyMap(uidMaps);
1672 }
1673 
DelBrokerUidAccessPolicyMap(uint32_t uid)1674 int32_t NetsysController::DelBrokerUidAccessPolicyMap(uint32_t uid)
1675 {
1676     NETMGR_LOG_D("DelBrokerUidAccessPolicyMap Enter");
1677     if (netsysService_ == nullptr) {
1678         NETMGR_LOG_E("netsysService_ is null");
1679         return NETSYS_NETSYSSERVICE_NULL;
1680     }
1681     return netsysService_->DelBrokerUidAccessPolicyMap(uid);
1682 }
1683 } // namespace NetManagerStandard
1684 } // namespace OHOS
1685