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