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