• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
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 {
Init()24 void NetsysControllerServiceImpl::Init()
25 {
26     mockNetsysClient_.RegisterMockApi();
27 }
28 
SetInternetPermission(uint32_t uid,uint8_t allow)29 int32_t NetsysControllerServiceImpl::SetInternetPermission(uint32_t uid, uint8_t allow)
30 {
31     return netsysClient_.SetInternetPermission(uid, allow);
32 }
33 
NetworkCreatePhysical(int32_t netId,int32_t permission)34 int32_t NetsysControllerServiceImpl::NetworkCreatePhysical(int32_t netId, int32_t permission)
35 {
36     NETMGR_LOG_I("Create Physical network: netId[%{public}d], permission[%{public}d]", netId, permission);
37     if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKCREATEPHYSICAL_API)) {
38         return mockNetsysClient_.NetworkCreatePhysical(netId, permission);
39     }
40     return netsysClient_.NetworkCreatePhysical(netId, permission);
41 }
42 
NetworkCreateVirtual(int32_t netId,bool hasDns)43 int32_t NetsysControllerServiceImpl::NetworkCreateVirtual(int32_t netId, bool hasDns)
44 {
45     NETMGR_LOG_I("Create Virtual network: netId[%{public}d], hasDns[%{public}d]", netId, hasDns);
46     return netsysClient_.NetworkCreateVirtual(netId, hasDns);
47 }
48 
NetworkDestroy(int32_t netId)49 int32_t NetsysControllerServiceImpl::NetworkDestroy(int32_t netId)
50 {
51     NETMGR_LOG_I("Destroy network: netId[%{public}d]", netId);
52     if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKDESTROY_API)) {
53         return mockNetsysClient_.NetworkDestroy(netId);
54     }
55     return netsysClient_.NetworkDestroy(netId);
56 }
57 
NetworkAddUids(int32_t netId,const std::vector<UidRange> & uidRanges)58 int32_t NetsysControllerServiceImpl::NetworkAddUids(int32_t netId, const std::vector<UidRange> &uidRanges)
59 {
60     NETMGR_LOG_I("Add uids to vpn network: netId[%{public}d]", netId);
61     return netsysClient_.NetworkAddUids(netId, uidRanges);
62 }
63 
NetworkDelUids(int32_t netId,const std::vector<UidRange> & uidRanges)64 int32_t NetsysControllerServiceImpl::NetworkDelUids(int32_t netId, const std::vector<UidRange> &uidRanges)
65 {
66     NETMGR_LOG_I("Remove uids from vpn network: netId[%{public}d]", netId);
67     return netsysClient_.NetworkDelUids(netId, uidRanges);
68 }
69 
NetworkAddInterface(int32_t netId,const std::string & iface)70 int32_t NetsysControllerServiceImpl::NetworkAddInterface(int32_t netId, const std::string &iface)
71 {
72     NETMGR_LOG_I("Add network interface: netId[%{public}d], iface[%{public}s]", netId, iface.c_str());
73     if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKADDINTERFACE_API)) {
74         return mockNetsysClient_.NetworkAddInterface(netId, iface);
75     }
76     return netsysClient_.NetworkAddInterface(netId, iface);
77 }
78 
NetworkRemoveInterface(int32_t netId,const std::string & iface)79 int32_t NetsysControllerServiceImpl::NetworkRemoveInterface(int32_t netId, const std::string &iface)
80 {
81     NETMGR_LOG_I("Remove network interface: netId[%{public}d], iface[%{public}s]", netId, iface.c_str());
82     if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKREMOVEINTERFACE_API)) {
83         return mockNetsysClient_.NetworkRemoveInterface(netId, iface);
84     }
85     return netsysClient_.NetworkRemoveInterface(netId, iface);
86 }
87 
NetworkAddRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)88 int32_t NetsysControllerServiceImpl::NetworkAddRoute(int32_t netId, const std::string &ifName,
89                                                      const std::string &destination, const std::string &nextHop)
90 {
91     NETMGR_LOG_I("Add Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]",
92                  netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
93     if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKADDROUTE_API)) {
94         return mockNetsysClient_.NetworkAddRoute(netId, ifName, destination, nextHop);
95     }
96     return netsysClient_.NetworkAddRoute(netId, ifName, destination, nextHop);
97 }
98 
NetworkRemoveRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)99 int32_t NetsysControllerServiceImpl::NetworkRemoveRoute(int32_t netId, const std::string &ifName,
100                                                         const std::string &destination, const std::string &nextHop)
101 {
102     NETMGR_LOG_I("Remove Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]",
103                  netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
104     if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKREMOVEROUTE_API)) {
105         return mockNetsysClient_.NetworkRemoveRoute(netId, ifName, destination, nextHop);
106     }
107     return netsysClient_.NetworkRemoveRoute(netId, ifName, destination, nextHop);
108 }
109 
GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel & cfg)110 int32_t NetsysControllerServiceImpl::GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel &cfg)
111 {
112     NETMGR_LOG_I("Interface get config");
113     return netsysClient_.GetInterfaceConfig(cfg);
114 }
115 
SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel & cfg)116 int32_t NetsysControllerServiceImpl::SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel &cfg)
117 {
118     NETMGR_LOG_I("Interface set config");
119     return netsysClient_.SetInterfaceConfig(cfg);
120 }
121 
SetInterfaceDown(const std::string & iface)122 int32_t NetsysControllerServiceImpl::SetInterfaceDown(const std::string &iface)
123 {
124     NETMGR_LOG_I("Set interface down: iface[%{public}s]", iface.c_str());
125     if (mockNetsysClient_.CheckMockApi(MOCK_SETINTERFACEDOWN_API)) {
126         return mockNetsysClient_.SetInterfaceDown(iface);
127     }
128     return netsysClient_.SetInterfaceDown(iface);
129 }
130 
SetInterfaceUp(const std::string & iface)131 int32_t NetsysControllerServiceImpl::SetInterfaceUp(const std::string &iface)
132 {
133     NETMGR_LOG_I("Set interface up: iface[%{public}s]", iface.c_str());
134     if (mockNetsysClient_.CheckMockApi(MOCK_SETINTERFACEUP_API)) {
135         return mockNetsysClient_.SetInterfaceUp(iface);
136     }
137     return netsysClient_.SetInterfaceUp(iface);
138 }
139 
ClearInterfaceAddrs(const std::string & ifName)140 void NetsysControllerServiceImpl::ClearInterfaceAddrs(const std::string &ifName)
141 {
142     NETMGR_LOG_I("Clear addrs: ifName[%{public}s]", ifName.c_str());
143     if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACECLEARADDRS_API)) {
144         return mockNetsysClient_.ClearInterfaceAddrs(ifName);
145     }
146     return netsysClient_.ClearInterfaceAddrs(ifName);
147 }
148 
GetInterfaceMtu(const std::string & ifName)149 int32_t NetsysControllerServiceImpl::GetInterfaceMtu(const std::string &ifName)
150 {
151     NETMGR_LOG_I("Get mtu: ifName[%{public}s]", ifName.c_str());
152     if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACEGETMTU_API)) {
153         return mockNetsysClient_.GetInterfaceMtu(ifName);
154     }
155     return netsysClient_.GetInterfaceMtu(ifName);
156 }
157 
SetInterfaceMtu(const std::string & ifName,int32_t mtu)158 int32_t NetsysControllerServiceImpl::SetInterfaceMtu(const std::string &ifName, int32_t mtu)
159 {
160     NETMGR_LOG_I("Set mtu: ifName[%{public}s], mtu[%{public}d]", ifName.c_str(), mtu);
161     if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACESETMTU_API)) {
162         return mockNetsysClient_.SetInterfaceMtu(ifName, mtu);
163     }
164     return netsysClient_.SetInterfaceMtu(ifName, mtu);
165 }
166 
AddInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)167 int32_t NetsysControllerServiceImpl::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
168                                                          int32_t prefixLength)
169 {
170     NETMGR_LOG_I("Add address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]", ifName.c_str(),
171                  ToAnonymousIp(ipAddr).c_str(), prefixLength);
172     if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACEADDADDRESS_API)) {
173         return mockNetsysClient_.AddInterfaceAddress(ifName, ipAddr, prefixLength);
174     }
175     return netsysClient_.AddInterfaceAddress(ifName, ipAddr, prefixLength);
176 }
177 
DelInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)178 int32_t NetsysControllerServiceImpl::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
179                                                          int32_t prefixLength)
180 {
181     NETMGR_LOG_I("Delete address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]", ifName.c_str(),
182                  ToAnonymousIp(ipAddr).c_str(), prefixLength);
183     if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACEDELADDRESS_API)) {
184         return mockNetsysClient_.DelInterfaceAddress(ifName, ipAddr, prefixLength);
185     }
186     return netsysClient_.DelInterfaceAddress(ifName, ipAddr, prefixLength);
187 }
188 
InterfaceSetIpAddress(const std::string & ifaceName,const std::string & ipAddress)189 int32_t NetsysControllerServiceImpl::InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress)
190 {
191     NETMGR_LOG_I("set ip address: ifName[%{public}s], ipAddr[%{public}s]", ifaceName.c_str(),
192                  ToAnonymousIp(ipAddress).c_str());
193     return netsysClient_.InterfaceSetIpAddress(ifaceName, ipAddress);
194 }
195 
InterfaceSetIffUp(const std::string & ifaceName)196 int32_t NetsysControllerServiceImpl::InterfaceSetIffUp(const std::string &ifaceName)
197 {
198     NETMGR_LOG_I("set iff up: ifName[%{public}s]", ifaceName.c_str());
199     return netsysClient_.InterfaceSetIffUp(ifaceName);
200 }
201 
SetResolverConfig(uint16_t netId,uint16_t baseTimeoutMsec,uint8_t retryCount,const std::vector<std::string> & servers,const std::vector<std::string> & domains)202 int32_t NetsysControllerServiceImpl::SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
203                                                        const std::vector<std::string> &servers,
204                                                        const std::vector<std::string> &domains)
205 {
206     NETMGR_LOG_I("Set resolver config: netId[%{public}d]", netId);
207     if (mockNetsysClient_.CheckMockApi(MOCK_SETRESOLVERCONFIG_API)) {
208         return mockNetsysClient_.SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
209     }
210     return netsysClient_.SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
211 }
212 
GetResolverConfig(uint16_t netId,std::vector<std::string> & servers,std::vector<std::string> & domains,uint16_t & baseTimeoutMsec,uint8_t & retryCount)213 int32_t NetsysControllerServiceImpl::GetResolverConfig(uint16_t netId, std::vector<std::string> &servers,
214                                                        std::vector<std::string> &domains, uint16_t &baseTimeoutMsec,
215                                                        uint8_t &retryCount)
216 {
217     NETMGR_LOG_I("Get resolver config: netId[%{public}d]", netId);
218     if (mockNetsysClient_.CheckMockApi(MOCK_GETRESOLVERICONFIG_API)) {
219         return mockNetsysClient_.GetResolverConfig(netId, servers, domains, baseTimeoutMsec, retryCount);
220     }
221     return netsysClient_.GetResolverConfig(netId, servers, domains, baseTimeoutMsec, retryCount);
222 }
223 
CreateNetworkCache(uint16_t netId)224 int32_t NetsysControllerServiceImpl::CreateNetworkCache(uint16_t netId)
225 {
226     NETMGR_LOG_I("create dns cache: netId[%{public}d]", netId);
227     if (mockNetsysClient_.CheckMockApi(MOCK_CREATENETWORKCACHE_API)) {
228         return mockNetsysClient_.CreateNetworkCache(netId);
229     }
230     return netsysClient_.CreateNetworkCache(netId);
231 }
232 
DestroyNetworkCache(uint16_t netId)233 int32_t NetsysControllerServiceImpl::DestroyNetworkCache(uint16_t netId)
234 {
235     NETMGR_LOG_D("Destroy dns cache: netId[%{public}d]", netId);
236     return netsysClient_.DestroyNetworkCache(netId);
237 }
238 
GetAddrInfo(const std::string & hostName,const std::string & serverName,const AddrInfo & hints,uint16_t netId,std::vector<AddrInfo> & res)239 int32_t NetsysControllerServiceImpl::GetAddrInfo(const std::string &hostName, const std::string &serverName,
240                                                  const AddrInfo &hints, uint16_t netId, std::vector<AddrInfo> &res)
241 {
242     return netsysClient_.GetAddrInfo(hostName, serverName, hints, netId, res);
243 }
244 
GetNetworkSharingTraffic(const std::string & downIface,const std::string & upIface,nmd::NetworkSharingTraffic & traffic)245 int32_t NetsysControllerServiceImpl::GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface,
246                                                               nmd::NetworkSharingTraffic &traffic)
247 {
248     NETMGR_LOG_I("NetsysControllerServiceImpl GetNetworkSharingTraffic");
249     return netsysClient_.GetNetworkSharingTraffic(downIface, upIface, traffic);
250 }
251 
GetCellularRxBytes()252 int64_t NetsysControllerServiceImpl::GetCellularRxBytes()
253 {
254     NETMGR_LOG_I("NetsysControllerServiceImpl GetCellularRxBytes");
255     if (mockNetsysClient_.CheckMockApi(MOCK_GETCELLULARRXBYTES_API)) {
256         return mockNetsysClient_.GetCellularRxBytes();
257     }
258     return netsysClient_.GetCellularRxBytes();
259 }
260 
GetCellularTxBytes()261 int64_t NetsysControllerServiceImpl::GetCellularTxBytes()
262 {
263     NETMGR_LOG_I("NetsysControllerServiceImpl GetCellularTxBytes");
264     if (mockNetsysClient_.CheckMockApi(MOCK_GETCELLULARTXBYTES_API)) {
265         return mockNetsysClient_.GetCellularTxBytes();
266     }
267     return netsysClient_.GetCellularTxBytes();
268 }
269 
GetAllRxBytes()270 int64_t NetsysControllerServiceImpl::GetAllRxBytes()
271 {
272     NETMGR_LOG_I("NetsysControllerServiceImpl GetAllRxBytes");
273     if (mockNetsysClient_.CheckMockApi(MOCK_GETALLRXBYTES_API)) {
274         return mockNetsysClient_.GetAllRxBytes();
275     }
276     return netsysClient_.GetAllRxBytes();
277 }
278 
GetAllTxBytes()279 int64_t NetsysControllerServiceImpl::GetAllTxBytes()
280 {
281     NETMGR_LOG_I("NetsysControllerServiceImpl GetAllTxBytes");
282     if (mockNetsysClient_.CheckMockApi(MOCK_GETALLTXBYTES_API)) {
283         return mockNetsysClient_.GetAllTxBytes();
284     }
285     return netsysClient_.GetAllTxBytes();
286 }
287 
GetUidRxBytes(uint32_t uid)288 int64_t NetsysControllerServiceImpl::GetUidRxBytes(uint32_t uid)
289 {
290     NETMGR_LOG_I("NetsysControllerServiceImpl GetUidRxBytes");
291     if (mockNetsysClient_.CheckMockApi(MOCK_GETUIDRXBYTES_API)) {
292         return mockNetsysClient_.GetUidRxBytes(uid);
293     }
294     return netsysClient_.GetUidRxBytes(uid);
295 }
296 
GetUidTxBytes(uint32_t uid)297 int64_t NetsysControllerServiceImpl::GetUidTxBytes(uint32_t uid)
298 {
299     NETMGR_LOG_I("NetsysControllerServiceImpl GetUidTxBytes");
300     if (mockNetsysClient_.CheckMockApi(MOCK_GETUIDTXBYTES_API)) {
301         return mockNetsysClient_.GetUidTxBytes(uid);
302     }
303     return netsysClient_.GetUidTxBytes(uid);
304 }
305 
GetUidOnIfaceRxBytes(uint32_t uid,const std::string & interfaceName)306 int64_t NetsysControllerServiceImpl::GetUidOnIfaceRxBytes(uint32_t uid, const std::string &interfaceName)
307 {
308     NETMGR_LOG_I("NetsysControllerServiceImpl GetUidOnIfaceRxBytes");
309     if (mockNetsysClient_.CheckMockApi(MOCK_GETUIDRXBYTES_API)) {
310         return mockNetsysClient_.GetUidOnIfaceRxBytes(uid, interfaceName);
311     }
312     return netsysClient_.GetUidOnIfaceRxBytes(uid, interfaceName);
313 }
314 
GetUidOnIfaceTxBytes(uint32_t uid,const std::string & interfaceName)315 int64_t NetsysControllerServiceImpl::GetUidOnIfaceTxBytes(uint32_t uid, const std::string &interfaceName)
316 {
317     NETMGR_LOG_I("NetsysControllerServiceImpl GetUidOnIfaceTxBytes");
318     if (mockNetsysClient_.CheckMockApi(MOCK_GETUIDTXBYTES_API)) {
319         return mockNetsysClient_.GetUidOnIfaceTxBytes(uid, interfaceName);
320     }
321     return netsysClient_.GetUidOnIfaceTxBytes(uid, interfaceName);
322 }
323 
GetIfaceRxBytes(const std::string & interfaceName)324 int64_t NetsysControllerServiceImpl::GetIfaceRxBytes(const std::string &interfaceName)
325 {
326     NETMGR_LOG_I("NetsysControllerServiceImpl GetIfaceRxBytes");
327     if (mockNetsysClient_.CheckMockApi(MOCK_GETIFACERXBYTES_API)) {
328         return mockNetsysClient_.GetIfaceRxBytes(interfaceName);
329     }
330     return netsysClient_.GetIfaceRxBytes(interfaceName);
331 }
332 
GetIfaceTxBytes(const std::string & interfaceName)333 int64_t NetsysControllerServiceImpl::GetIfaceTxBytes(const std::string &interfaceName)
334 {
335     NETMGR_LOG_I("NetsysControllerServiceImpl GetIfaceTxBytes");
336     if (mockNetsysClient_.CheckMockApi(MOCK_GETIFACETXBYTES_API)) {
337         return mockNetsysClient_.GetIfaceTxBytes(interfaceName);
338     }
339     return netsysClient_.GetIfaceTxBytes(interfaceName);
340 }
341 
InterfaceGetList()342 std::vector<std::string> NetsysControllerServiceImpl::InterfaceGetList()
343 {
344     NETMGR_LOG_I("NetsysControllerServiceImpl InterfaceGetList");
345     if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACEGETLIST_API)) {
346         return mockNetsysClient_.InterfaceGetList();
347     }
348     return netsysClient_.InterfaceGetList();
349 }
350 
UidGetList()351 std::vector<std::string> NetsysControllerServiceImpl::UidGetList()
352 {
353     NETMGR_LOG_I("NetsysControllerServiceImpl UidGetList");
354     if (mockNetsysClient_.CheckMockApi(MOCK_UIDGETLIST_API)) {
355         return mockNetsysClient_.UidGetList();
356     }
357     return netsysClient_.UidGetList();
358 }
359 
GetIfaceRxPackets(const std::string & interfaceName)360 int64_t NetsysControllerServiceImpl::GetIfaceRxPackets(const std::string &interfaceName)
361 {
362     NETMGR_LOG_D("NetsysControllerServiceImpl GetIfaceRxPackets");
363     if (mockNetsysClient_.CheckMockApi(MOCK_GETIFACERXPACKETS_API)) {
364         return mockNetsysClient_.GetIfaceRxPackets(interfaceName);
365     }
366     return netsysClient_.GetIfaceRxPackets(interfaceName);
367 }
368 
GetIfaceTxPackets(const std::string & interfaceName)369 int64_t NetsysControllerServiceImpl::GetIfaceTxPackets(const std::string &interfaceName)
370 {
371     NETMGR_LOG_D("NetsysControllerServiceImpl GetIfaceTxPackets");
372     if (mockNetsysClient_.CheckMockApi(MOCK_GETIFACETXPACKETS_API)) {
373         return mockNetsysClient_.GetIfaceTxPackets(interfaceName);
374     }
375     return netsysClient_.GetIfaceTxPackets(interfaceName);
376 }
377 
SetDefaultNetWork(int32_t netId)378 int32_t NetsysControllerServiceImpl::SetDefaultNetWork(int32_t netId)
379 {
380     NETMGR_LOG_D("NetsysControllerServiceImpl SetDefaultNetWork");
381     if (mockNetsysClient_.CheckMockApi(MOCK_SETDEFAULTNETWORK_API)) {
382         return mockNetsysClient_.SetDefaultNetWork(netId);
383     }
384     return netsysClient_.SetDefaultNetWork(netId);
385 }
386 
ClearDefaultNetWorkNetId()387 int32_t NetsysControllerServiceImpl::ClearDefaultNetWorkNetId()
388 {
389     NETMGR_LOG_D("NetsysControllerServiceImpl ClearDefaultNetWorkNetId");
390     if (mockNetsysClient_.CheckMockApi(MOCK_CLEARDEFAULTNETWORK_API)) {
391         return mockNetsysClient_.ClearDefaultNetWorkNetId();
392     }
393     return netsysClient_.ClearDefaultNetWorkNetId();
394 }
395 
BindSocket(int32_t socketFd,uint32_t netId)396 int32_t NetsysControllerServiceImpl::BindSocket(int32_t socketFd, uint32_t netId)
397 {
398     NETMGR_LOG_D("NetsysControllerServiceImpl BindSocket");
399     if (mockNetsysClient_.CheckMockApi(MOCK_BINDSOCKET_API)) {
400         return mockNetsysClient_.BindSocket(socketFd, netId);
401     }
402     return netsysClient_.BindSocket(socketFd, netId);
403 }
404 
IpEnableForwarding(const std::string & requestor)405 int32_t NetsysControllerServiceImpl::IpEnableForwarding(const std::string &requestor)
406 {
407     NETMGR_LOG_D("NetsysControllerServiceImpl IpEnableForwarding");
408     return netsysClient_.IpEnableForwarding(requestor);
409 }
410 
IpDisableForwarding(const std::string & requestor)411 int32_t NetsysControllerServiceImpl::IpDisableForwarding(const std::string &requestor)
412 {
413     NETMGR_LOG_D("NetsysControllerServiceImpl IpDisableForwarding");
414     return netsysClient_.IpDisableForwarding(requestor);
415 }
416 
EnableNat(const std::string & downstreamIface,const std::string & upstreamIface)417 int32_t NetsysControllerServiceImpl::EnableNat(const std::string &downstreamIface, const std::string &upstreamIface)
418 {
419     NETMGR_LOG_D("NetsysControllerServiceImpl EnableNat");
420     return netsysClient_.EnableNat(downstreamIface, upstreamIface);
421 }
422 
DisableNat(const std::string & downstreamIface,const std::string & upstreamIface)423 int32_t NetsysControllerServiceImpl::DisableNat(const std::string &downstreamIface, const std::string &upstreamIface)
424 {
425     NETMGR_LOG_D("NetsysControllerServiceImpl DisableNat");
426     return netsysClient_.DisableNat(downstreamIface, upstreamIface);
427 }
428 
IpfwdAddInterfaceForward(const std::string & fromIface,const std::string & toIface)429 int32_t NetsysControllerServiceImpl::IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface)
430 {
431     NETMGR_LOG_D("NetsysControllerServiceImpl IpfwdAddInterfaceForward");
432     return netsysClient_.IpfwdAddInterfaceForward(fromIface, toIface);
433 }
434 
IpfwdRemoveInterfaceForward(const std::string & fromIface,const std::string & toIface)435 int32_t NetsysControllerServiceImpl::IpfwdRemoveInterfaceForward(const std::string &fromIface,
436                                                                  const std::string &toIface)
437 {
438     NETMGR_LOG_D("NetsysControllerServiceImpl IpfwdRemoveInterfaceForward");
439     return netsysClient_.IpfwdRemoveInterfaceForward(fromIface, toIface);
440 }
441 
ShareDnsSet(uint16_t netId)442 int32_t NetsysControllerServiceImpl::ShareDnsSet(uint16_t netId)
443 {
444     NETMGR_LOG_D("NetsysControllerServiceImpl IpfwdRemoveInterfaceForward");
445     if (mockNetsysClient_.CheckMockApi(MOCK_SHAREDNSSET_API)) {
446         return mockNetsysClient_.ShareDnsSet(netId);
447     }
448     return netsysClient_.ShareDnsSet(netId);
449 }
450 
StartDnsProxyListen()451 int32_t NetsysControllerServiceImpl::StartDnsProxyListen()
452 {
453     NETMGR_LOG_D("NetsysControllerServiceImpl StartDnsProxyListen");
454     return netsysClient_.StartDnsProxyListen();
455 }
456 
StopDnsProxyListen()457 int32_t NetsysControllerServiceImpl::StopDnsProxyListen()
458 {
459     NETMGR_LOG_D("NetsysControllerServiceImpl StopDnsProxyListen");
460     return netsysClient_.StopDnsProxyListen();
461 }
462 
RegisterNetsysNotifyCallback(const NetsysNotifyCallback & callback)463 int32_t NetsysControllerServiceImpl::RegisterNetsysNotifyCallback(const NetsysNotifyCallback &callback)
464 {
465     NETMGR_LOG_D("NetsysControllerServiceImpl IpfwdRemoveInterfaceForward");
466     if (mockNetsysClient_.CheckMockApi(MOCK_REGISTERNETSYSNOTIFYCALLBACK_API)) {
467         return mockNetsysClient_.RegisterNetsysNotifyCallback(callback);
468     }
469     return netsysClient_.RegisterNetsysNotifyCallback(callback);
470 }
471 
BindNetworkServiceVpn(int32_t socketFd)472 int32_t NetsysControllerServiceImpl::BindNetworkServiceVpn(int32_t socketFd)
473 {
474     NETMGR_LOG_D("NetsysNativeClient::BindNetworkServiceVpn");
475     if (mockNetsysClient_.CheckMockApi(MOCK_BINDNETWORKSERVICEVPN_API)) {
476         return mockNetsysClient_.BindNetworkServiceVpn(socketFd);
477     }
478     return netsysClient_.BindNetworkServiceVpn(socketFd);
479 }
480 
EnableVirtualNetIfaceCard(int32_t socketFd,struct ifreq & ifRequest,int32_t & ifaceFd)481 int32_t NetsysControllerServiceImpl::EnableVirtualNetIfaceCard(int32_t socketFd, struct ifreq &ifRequest,
482                                                                int32_t &ifaceFd)
483 {
484     NETMGR_LOG_D("NetsysControllerServiceImpl::EnableVirtualNetIfaceCard");
485     if (mockNetsysClient_.CheckMockApi(MOCK_ENABLEVIRTUALNETIFACECARD_API)) {
486         return mockNetsysClient_.EnableVirtualNetIfaceCard(socketFd, ifRequest, ifaceFd);
487     }
488     return netsysClient_.EnableVirtualNetIfaceCard(socketFd, ifRequest, ifaceFd);
489 }
490 
SetIpAddress(int32_t socketFd,const std::string & ipAddress,int32_t prefixLen,struct ifreq & ifRequest)491 int32_t NetsysControllerServiceImpl::SetIpAddress(int32_t socketFd, const std::string &ipAddress, int32_t prefixLen,
492                                                   struct ifreq &ifRequest)
493 {
494     NETMGR_LOG_D("NetsysControllerServiceImpl::SetIpAddress");
495     if (mockNetsysClient_.CheckMockApi(MOCK_SETIPADDRESS_API)) {
496         return mockNetsysClient_.SetIpAddress(socketFd, ipAddress, prefixLen, ifRequest);
497     }
498     return netsysClient_.SetIpAddress(socketFd, ipAddress, prefixLen, ifRequest);
499 }
500 
SetBlocking(int32_t ifaceFd,bool isBlock)501 int32_t NetsysControllerServiceImpl::SetBlocking(int32_t ifaceFd, bool isBlock)
502 {
503     NETMGR_LOG_D("NetsysControllerServiceImpl::SetBlocking");
504     if (mockNetsysClient_.CheckMockApi(MOCK_SETBLOCKING_API)) {
505         return mockNetsysClient_.SetBlocking(ifaceFd, isBlock);
506     }
507     return netsysClient_.SetBlocking(ifaceFd, isBlock);
508 }
509 
StartDhcpClient(const std::string & iface,bool bIpv6)510 int32_t NetsysControllerServiceImpl::StartDhcpClient(const std::string &iface, bool bIpv6)
511 {
512     NETMGR_LOG_D("NetsysControllerServiceImpl::StartDhcpClient");
513     if (mockNetsysClient_.CheckMockApi(MOCK_STARTDHCPCLIENT_API)) {
514         return mockNetsysClient_.StartDhcpClient(iface, bIpv6);
515     }
516     return netsysClient_.StartDhcpClient(iface, bIpv6);
517 }
518 
StopDhcpClient(const std::string & iface,bool bIpv6)519 int32_t NetsysControllerServiceImpl::StopDhcpClient(const std::string &iface, bool bIpv6)
520 {
521     NETMGR_LOG_D("NetsysControllerServiceImpl::StopDhcpClient");
522     if (mockNetsysClient_.CheckMockApi(MOCK_STOPDHCPCLIENT_API)) {
523         return mockNetsysClient_.StopDhcpClient(iface, bIpv6);
524     }
525     return netsysClient_.StopDhcpClient(iface, bIpv6);
526 }
527 
RegisterCallback(sptr<NetsysControllerCallback> callback)528 int32_t NetsysControllerServiceImpl::RegisterCallback(sptr<NetsysControllerCallback> callback)
529 {
530     NETMGR_LOG_D("NetsysControllerServiceImpl::RegisterCallback");
531     if (mockNetsysClient_.CheckMockApi(MOCK_REGISTERNOTIFYCALLBACK_API)) {
532         return mockNetsysClient_.RegisterCallback(callback);
533     }
534     return netsysClient_.RegisterCallback(callback);
535 }
536 
StartDhcpService(const std::string & iface,const std::string & ipv4addr)537 int32_t NetsysControllerServiceImpl::StartDhcpService(const std::string &iface, const std::string &ipv4addr)
538 {
539     NETMGR_LOG_D("NetsysControllerServiceImpl::SetBlocking");
540     if (mockNetsysClient_.CheckMockApi(MOCK_STARTDHCPSERVICE_API)) {
541         return mockNetsysClient_.StartDhcpService(iface, ipv4addr);
542     }
543     return netsysClient_.StartDhcpService(iface, ipv4addr);
544 }
545 
StopDhcpService(const std::string & iface)546 int32_t NetsysControllerServiceImpl::StopDhcpService(const std::string &iface)
547 {
548     NETMGR_LOG_D("NetsysControllerServiceImpl::StopDhcpService");
549     if (mockNetsysClient_.CheckMockApi(MOCK_STOPDHCPSERVICE_API)) {
550         return mockNetsysClient_.StopDhcpService(iface);
551     }
552     return netsysClient_.StopDhcpService(iface);
553 }
554 
BandwidthEnableDataSaver(bool enable)555 int32_t NetsysControllerServiceImpl::BandwidthEnableDataSaver(bool enable)
556 {
557     NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthEnableDataSaver: enable=%{public}d", enable);
558     return netsysClient_.BandwidthEnableDataSaver(enable);
559 }
560 
BandwidthSetIfaceQuota(const std::string & ifName,int64_t bytes)561 int32_t NetsysControllerServiceImpl::BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes)
562 {
563     NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthSetIfaceQuota: ifName=%{public}s", ifName.c_str());
564     return netsysClient_.BandwidthSetIfaceQuota(ifName, bytes);
565 }
566 
BandwidthRemoveIfaceQuota(const std::string & ifName)567 int32_t NetsysControllerServiceImpl::BandwidthRemoveIfaceQuota(const std::string &ifName)
568 {
569     NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthRemoveIfaceQuota: ifName=%{public}s", ifName.c_str());
570     return netsysClient_.BandwidthRemoveIfaceQuota(ifName);
571 }
572 
BandwidthAddDeniedList(uint32_t uid)573 int32_t NetsysControllerServiceImpl::BandwidthAddDeniedList(uint32_t uid)
574 {
575     NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthAddDeniedList: uid=%{public}d", uid);
576     return netsysClient_.BandwidthAddDeniedList(uid);
577 }
578 
BandwidthRemoveDeniedList(uint32_t uid)579 int32_t NetsysControllerServiceImpl::BandwidthRemoveDeniedList(uint32_t uid)
580 {
581     NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthRemoveDeniedList: uid=%{public}d", uid);
582     return netsysClient_.BandwidthRemoveDeniedList(uid);
583 }
584 
BandwidthAddAllowedList(uint32_t uid)585 int32_t NetsysControllerServiceImpl::BandwidthAddAllowedList(uint32_t uid)
586 {
587     NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthAddAllowedList: uid=%{public}d", uid);
588     return netsysClient_.BandwidthAddAllowedList(uid);
589 }
590 
BandwidthRemoveAllowedList(uint32_t uid)591 int32_t NetsysControllerServiceImpl::BandwidthRemoveAllowedList(uint32_t uid)
592 {
593     NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthRemoveAllowedList: uid=%{public}d", uid);
594     return netsysClient_.BandwidthRemoveAllowedList(uid);
595 }
596 
FirewallSetUidsAllowedListChain(uint32_t chain,const std::vector<uint32_t> & uids)597 int32_t NetsysControllerServiceImpl::FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
598 {
599     NETMGR_LOG_D("NetsysControllerServiceImpl::FirewallSetUidsAllowedListChain: chain=%{public}d", chain);
600     return netsysClient_.FirewallSetUidsAllowedListChain(chain, uids);
601 }
602 
FirewallSetUidsDeniedListChain(uint32_t chain,const std::vector<uint32_t> & uids)603 int32_t NetsysControllerServiceImpl::FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
604 {
605     NETMGR_LOG_D("NetsysControllerServiceImpl::FirewallSetUidsDeniedListChain: chain=%{public}d", chain);
606     return netsysClient_.FirewallSetUidsDeniedListChain(chain, uids);
607 }
608 
FirewallEnableChain(uint32_t chain,bool enable)609 int32_t NetsysControllerServiceImpl::FirewallEnableChain(uint32_t chain, bool enable)
610 {
611     NETMGR_LOG_D("NetsysController::FirewallEnableChain: chain=%{public}d, enable=%{public}d", chain, enable);
612     return netsysClient_.FirewallEnableChain(chain, enable);
613 }
614 
FirewallSetUidRule(uint32_t chain,const std::vector<uint32_t> & uids,uint32_t firewallRule)615 int32_t NetsysControllerServiceImpl::FirewallSetUidRule(uint32_t chain, const std::vector<uint32_t> &uids,
616                                                         uint32_t firewallRule)
617 {
618     return netsysClient_.FirewallSetUidRule(chain, uids, firewallRule);
619 }
620 
GetTotalStats(uint64_t & stats,uint32_t type)621 int32_t NetsysControllerServiceImpl::GetTotalStats(uint64_t &stats, uint32_t type)
622 {
623     NETMGR_LOG_D("NetsysControllerServiceImpl::GetTotalStats: type=%{public}d", type);
624     return netsysClient_.GetTotalStats(stats, type);
625 }
626 
GetUidStats(uint64_t & stats,uint32_t type,uint32_t uid)627 int32_t NetsysControllerServiceImpl::GetUidStats(uint64_t &stats, uint32_t type, uint32_t uid)
628 {
629     NETMGR_LOG_D("NetsysControllerServiceImpl::GetUidStats: type=%{public}d uid=%{public}d", type, uid);
630     return netsysClient_.GetUidStats(stats, type, uid);
631 }
632 
GetIfaceStats(uint64_t & stats,uint32_t type,const std::string & interfaceName)633 int32_t NetsysControllerServiceImpl::GetIfaceStats(uint64_t &stats, uint32_t type, const std::string &interfaceName)
634 {
635     NETMGR_LOG_D("NetsysControllerServiceImpl::GetIfaceStats: type=%{public}d", type);
636     return netsysClient_.GetIfaceStats(stats, type, interfaceName);
637 }
638 
GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> & stats)639 int32_t NetsysControllerServiceImpl::GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats)
640 {
641     NETMGR_LOG_D("NetsysControllerServiceImpl::GetAllStatsInfo");
642     return netsysClient_.GetAllStatsInfo(stats);
643 }
644 
SetIptablesCommandForRes(const std::string & cmd,std::string & respond)645 int32_t NetsysControllerServiceImpl::SetIptablesCommandForRes(const std::string &cmd, std::string &respond)
646 {
647     return netsysClient_.SetIptablesCommandForRes(cmd, respond);
648 }
649 
650 } // namespace NetManagerStandard
651 } // namespace OHOS
652