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