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 {
24 namespace {
25 using namespace OHOS::NetsysNative;
26 } // namespace
27
Init()28 void NetsysControllerServiceImpl::Init()
29 {
30 mockNetsysClient_.RegisterMockApi();
31 }
32
SetInternetPermission(uint32_t uid,uint8_t allow)33 int32_t NetsysControllerServiceImpl::SetInternetPermission(uint32_t uid, uint8_t allow)
34 {
35 return netsysClient_.SetInternetPermission(uid, allow);
36 }
37
NetworkCreatePhysical(int32_t netId,int32_t permission)38 int32_t NetsysControllerServiceImpl::NetworkCreatePhysical(int32_t netId, int32_t permission)
39 {
40 NETMGR_LOG_I("Create Physical network: netId[%{public}d], permission[%{public}d]", netId, permission);
41 if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKCREATEPHYSICAL_API)) {
42 return mockNetsysClient_.NetworkCreatePhysical(netId, permission);
43 }
44 return netsysClient_.NetworkCreatePhysical(netId, permission);
45 }
46
NetworkCreateVirtual(int32_t netId,bool hasDns)47 int32_t NetsysControllerServiceImpl::NetworkCreateVirtual(int32_t netId, bool hasDns)
48 {
49 NETMGR_LOG_I("Create Virtual network: netId[%{public}d], hasDns[%{public}d]", netId, hasDns);
50 return netsysClient_.NetworkCreateVirtual(netId, hasDns);
51 }
52
NetworkDestroy(int32_t netId)53 int32_t NetsysControllerServiceImpl::NetworkDestroy(int32_t netId)
54 {
55 NETMGR_LOG_I("Destroy network: netId[%{public}d]", netId);
56 if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKDESTROY_API)) {
57 return mockNetsysClient_.NetworkDestroy(netId);
58 }
59 return netsysClient_.NetworkDestroy(netId);
60 }
61
NetworkAddUids(int32_t netId,const std::vector<UidRange> & uidRanges)62 int32_t NetsysControllerServiceImpl::NetworkAddUids(int32_t netId, const std::vector<UidRange> &uidRanges)
63 {
64 NETMGR_LOG_I("Add uids to vpn network: netId[%{public}d]", netId);
65 return netsysClient_.NetworkAddUids(netId, uidRanges);
66 }
67
NetworkDelUids(int32_t netId,const std::vector<UidRange> & uidRanges)68 int32_t NetsysControllerServiceImpl::NetworkDelUids(int32_t netId, const std::vector<UidRange> &uidRanges)
69 {
70 NETMGR_LOG_I("Remove uids from vpn network: netId[%{public}d]", netId);
71 return netsysClient_.NetworkDelUids(netId, uidRanges);
72 }
73
NetworkAddInterface(int32_t netId,const std::string & iface)74 int32_t NetsysControllerServiceImpl::NetworkAddInterface(int32_t netId, const std::string &iface)
75 {
76 NETMGR_LOG_I("Add network interface: netId[%{public}d], iface[%{public}s]", netId, iface.c_str());
77 if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKADDINTERFACE_API)) {
78 return mockNetsysClient_.NetworkAddInterface(netId, iface);
79 }
80 return netsysClient_.NetworkAddInterface(netId, iface);
81 }
82
NetworkRemoveInterface(int32_t netId,const std::string & iface)83 int32_t NetsysControllerServiceImpl::NetworkRemoveInterface(int32_t netId, const std::string &iface)
84 {
85 NETMGR_LOG_I("Remove network interface: netId[%{public}d], iface[%{public}s]", netId, iface.c_str());
86 if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKREMOVEINTERFACE_API)) {
87 return mockNetsysClient_.NetworkRemoveInterface(netId, iface);
88 }
89 return netsysClient_.NetworkRemoveInterface(netId, iface);
90 }
91
NetworkAddRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)92 int32_t NetsysControllerServiceImpl::NetworkAddRoute(int32_t netId, const std::string &ifName,
93 const std::string &destination, const std::string &nextHop)
94 {
95 NETMGR_LOG_I("Add Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]",
96 netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
97 if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKADDROUTE_API)) {
98 return mockNetsysClient_.NetworkAddRoute(netId, ifName, destination, nextHop);
99 }
100 return netsysClient_.NetworkAddRoute(netId, ifName, destination, nextHop);
101 }
102
NetworkRemoveRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)103 int32_t NetsysControllerServiceImpl::NetworkRemoveRoute(int32_t netId, const std::string &ifName,
104 const std::string &destination, const std::string &nextHop)
105 {
106 NETMGR_LOG_I("Remove Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]",
107 netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
108 if (mockNetsysClient_.CheckMockApi(MOCK_NETWORKREMOVEROUTE_API)) {
109 return mockNetsysClient_.NetworkRemoveRoute(netId, ifName, destination, nextHop);
110 }
111 return netsysClient_.NetworkRemoveRoute(netId, ifName, destination, nextHop);
112 }
113
GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel & cfg)114 int32_t NetsysControllerServiceImpl::GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel &cfg)
115 {
116 NETMGR_LOG_I("Interface get config");
117 return netsysClient_.GetInterfaceConfig(cfg);
118 }
119
SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel & cfg)120 int32_t NetsysControllerServiceImpl::SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel &cfg)
121 {
122 NETMGR_LOG_I("Interface set config");
123 return netsysClient_.SetInterfaceConfig(cfg);
124 }
125
SetInterfaceDown(const std::string & iface)126 int32_t NetsysControllerServiceImpl::SetInterfaceDown(const std::string &iface)
127 {
128 NETMGR_LOG_I("Set interface down: iface[%{public}s]", iface.c_str());
129 if (mockNetsysClient_.CheckMockApi(MOCK_SETINTERFACEDOWN_API)) {
130 return mockNetsysClient_.SetInterfaceDown(iface);
131 }
132 return netsysClient_.SetInterfaceDown(iface);
133 }
134
SetInterfaceUp(const std::string & iface)135 int32_t NetsysControllerServiceImpl::SetInterfaceUp(const std::string &iface)
136 {
137 NETMGR_LOG_I("Set interface up: iface[%{public}s]", iface.c_str());
138 if (mockNetsysClient_.CheckMockApi(MOCK_SETINTERFACEUP_API)) {
139 return mockNetsysClient_.SetInterfaceUp(iface);
140 }
141 return netsysClient_.SetInterfaceUp(iface);
142 }
143
ClearInterfaceAddrs(const std::string & ifName)144 void NetsysControllerServiceImpl::ClearInterfaceAddrs(const std::string &ifName)
145 {
146 NETMGR_LOG_I("Clear addrs: ifName[%{public}s]", ifName.c_str());
147 if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACECLEARADDRS_API)) {
148 return mockNetsysClient_.ClearInterfaceAddrs(ifName);
149 }
150 return netsysClient_.ClearInterfaceAddrs(ifName);
151 }
152
GetInterfaceMtu(const std::string & ifName)153 int32_t NetsysControllerServiceImpl::GetInterfaceMtu(const std::string &ifName)
154 {
155 NETMGR_LOG_I("Get mtu: ifName[%{public}s]", ifName.c_str());
156 if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACEGETMTU_API)) {
157 return mockNetsysClient_.GetInterfaceMtu(ifName);
158 }
159 return netsysClient_.GetInterfaceMtu(ifName);
160 }
161
SetInterfaceMtu(const std::string & ifName,int32_t mtu)162 int32_t NetsysControllerServiceImpl::SetInterfaceMtu(const std::string &ifName, int32_t mtu)
163 {
164 NETMGR_LOG_I("Set mtu: ifName[%{public}s], mtu[%{public}d]", ifName.c_str(), mtu);
165 if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACESETMTU_API)) {
166 return mockNetsysClient_.SetInterfaceMtu(ifName, mtu);
167 }
168 return netsysClient_.SetInterfaceMtu(ifName, mtu);
169 }
170
SetTcpBufferSizes(const std::string & tcpBufferSizes)171 int32_t NetsysControllerServiceImpl::SetTcpBufferSizes(const std::string &tcpBufferSizes)
172 {
173 NETMGR_LOG_I("Set tcp buffer sizes: tcpBufferSizes[%{public}s]", tcpBufferSizes.c_str());
174 return netsysClient_.SetTcpBufferSizes(tcpBufferSizes);
175 }
176
AddInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)177 int32_t NetsysControllerServiceImpl::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
178 int32_t prefixLength)
179 {
180 NETMGR_LOG_I("Add address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]", ifName.c_str(),
181 ToAnonymousIp(ipAddr).c_str(), prefixLength);
182 if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACEADDADDRESS_API)) {
183 return mockNetsysClient_.AddInterfaceAddress(ifName, ipAddr, prefixLength);
184 }
185 return netsysClient_.AddInterfaceAddress(ifName, ipAddr, prefixLength);
186 }
187
DelInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)188 int32_t NetsysControllerServiceImpl::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
189 int32_t prefixLength)
190 {
191 NETMGR_LOG_I("Delete address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]", ifName.c_str(),
192 ToAnonymousIp(ipAddr).c_str(), prefixLength);
193 if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACEDELADDRESS_API)) {
194 return mockNetsysClient_.DelInterfaceAddress(ifName, ipAddr, prefixLength);
195 }
196 return netsysClient_.DelInterfaceAddress(ifName, ipAddr, prefixLength);
197 }
198
InterfaceSetIpAddress(const std::string & ifaceName,const std::string & ipAddress)199 int32_t NetsysControllerServiceImpl::InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress)
200 {
201 NETMGR_LOG_I("set ip address: ifName[%{public}s], ipAddr[%{public}s]", ifaceName.c_str(),
202 ToAnonymousIp(ipAddress).c_str());
203 return netsysClient_.InterfaceSetIpAddress(ifaceName, ipAddress);
204 }
205
InterfaceSetIffUp(const std::string & ifaceName)206 int32_t NetsysControllerServiceImpl::InterfaceSetIffUp(const std::string &ifaceName)
207 {
208 NETMGR_LOG_I("set iff up: ifName[%{public}s]", ifaceName.c_str());
209 return netsysClient_.InterfaceSetIffUp(ifaceName);
210 }
211
SetResolverConfig(uint16_t netId,uint16_t baseTimeoutMsec,uint8_t retryCount,const std::vector<std::string> & servers,const std::vector<std::string> & domains)212 int32_t NetsysControllerServiceImpl::SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
213 const std::vector<std::string> &servers,
214 const std::vector<std::string> &domains)
215 {
216 NETMGR_LOG_I("Set resolver config: netId[%{public}d]", netId);
217 if (mockNetsysClient_.CheckMockApi(MOCK_SETRESOLVERCONFIG_API)) {
218 return mockNetsysClient_.SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
219 }
220 return netsysClient_.SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
221 }
222
GetResolverConfig(uint16_t netId,std::vector<std::string> & servers,std::vector<std::string> & domains,uint16_t & baseTimeoutMsec,uint8_t & retryCount)223 int32_t NetsysControllerServiceImpl::GetResolverConfig(uint16_t netId, std::vector<std::string> &servers,
224 std::vector<std::string> &domains, uint16_t &baseTimeoutMsec,
225 uint8_t &retryCount)
226 {
227 NETMGR_LOG_I("Get resolver config: netId[%{public}d]", netId);
228 if (mockNetsysClient_.CheckMockApi(MOCK_GETRESOLVERICONFIG_API)) {
229 return mockNetsysClient_.GetResolverConfig(netId, servers, domains, baseTimeoutMsec, retryCount);
230 }
231 return netsysClient_.GetResolverConfig(netId, servers, domains, baseTimeoutMsec, retryCount);
232 }
233
CreateNetworkCache(uint16_t netId)234 int32_t NetsysControllerServiceImpl::CreateNetworkCache(uint16_t netId)
235 {
236 NETMGR_LOG_I("create dns cache: netId[%{public}d]", netId);
237 if (mockNetsysClient_.CheckMockApi(MOCK_CREATENETWORKCACHE_API)) {
238 return mockNetsysClient_.CreateNetworkCache(netId);
239 }
240 return netsysClient_.CreateNetworkCache(netId);
241 }
242
DestroyNetworkCache(uint16_t netId)243 int32_t NetsysControllerServiceImpl::DestroyNetworkCache(uint16_t netId)
244 {
245 NETMGR_LOG_D("Destroy dns cache: netId[%{public}d]", netId);
246 return netsysClient_.DestroyNetworkCache(netId);
247 }
248
GetAddrInfo(const std::string & hostName,const std::string & serverName,const AddrInfo & hints,uint16_t netId,std::vector<AddrInfo> & res)249 int32_t NetsysControllerServiceImpl::GetAddrInfo(const std::string &hostName, const std::string &serverName,
250 const AddrInfo &hints, uint16_t netId, std::vector<AddrInfo> &res)
251 {
252 return netsysClient_.GetAddrInfo(hostName, serverName, hints, netId, res);
253 }
254
GetNetworkSharingTraffic(const std::string & downIface,const std::string & upIface,nmd::NetworkSharingTraffic & traffic)255 int32_t NetsysControllerServiceImpl::GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface,
256 nmd::NetworkSharingTraffic &traffic)
257 {
258 NETMGR_LOG_I("NetsysControllerServiceImpl GetNetworkSharingTraffic");
259 return netsysClient_.GetNetworkSharingTraffic(downIface, upIface, traffic);
260 }
261
GetCellularRxBytes()262 int64_t NetsysControllerServiceImpl::GetCellularRxBytes()
263 {
264 NETMGR_LOG_I("NetsysControllerServiceImpl GetCellularRxBytes");
265 if (mockNetsysClient_.CheckMockApi(MOCK_GETCELLULARRXBYTES_API)) {
266 return mockNetsysClient_.GetCellularRxBytes();
267 }
268 return netsysClient_.GetCellularRxBytes();
269 }
270
GetCellularTxBytes()271 int64_t NetsysControllerServiceImpl::GetCellularTxBytes()
272 {
273 NETMGR_LOG_I("NetsysControllerServiceImpl GetCellularTxBytes");
274 if (mockNetsysClient_.CheckMockApi(MOCK_GETCELLULARTXBYTES_API)) {
275 return mockNetsysClient_.GetCellularTxBytes();
276 }
277 return netsysClient_.GetCellularTxBytes();
278 }
279
GetAllRxBytes()280 int64_t NetsysControllerServiceImpl::GetAllRxBytes()
281 {
282 NETMGR_LOG_I("NetsysControllerServiceImpl GetAllRxBytes");
283 if (mockNetsysClient_.CheckMockApi(MOCK_GETALLRXBYTES_API)) {
284 return mockNetsysClient_.GetAllRxBytes();
285 }
286 return netsysClient_.GetAllRxBytes();
287 }
288
GetAllTxBytes()289 int64_t NetsysControllerServiceImpl::GetAllTxBytes()
290 {
291 NETMGR_LOG_I("NetsysControllerServiceImpl GetAllTxBytes");
292 if (mockNetsysClient_.CheckMockApi(MOCK_GETALLTXBYTES_API)) {
293 return mockNetsysClient_.GetAllTxBytes();
294 }
295 return netsysClient_.GetAllTxBytes();
296 }
297
GetUidRxBytes(uint32_t uid)298 int64_t NetsysControllerServiceImpl::GetUidRxBytes(uint32_t uid)
299 {
300 NETMGR_LOG_I("NetsysControllerServiceImpl GetUidRxBytes");
301 if (mockNetsysClient_.CheckMockApi(MOCK_GETUIDRXBYTES_API)) {
302 return mockNetsysClient_.GetUidRxBytes(uid);
303 }
304 return netsysClient_.GetUidRxBytes(uid);
305 }
306
GetUidTxBytes(uint32_t uid)307 int64_t NetsysControllerServiceImpl::GetUidTxBytes(uint32_t uid)
308 {
309 NETMGR_LOG_I("NetsysControllerServiceImpl GetUidTxBytes");
310 if (mockNetsysClient_.CheckMockApi(MOCK_GETUIDTXBYTES_API)) {
311 return mockNetsysClient_.GetUidTxBytes(uid);
312 }
313 return netsysClient_.GetUidTxBytes(uid);
314 }
315
GetUidOnIfaceRxBytes(uint32_t uid,const std::string & interfaceName)316 int64_t NetsysControllerServiceImpl::GetUidOnIfaceRxBytes(uint32_t uid, const std::string &interfaceName)
317 {
318 NETMGR_LOG_I("NetsysControllerServiceImpl GetUidOnIfaceRxBytes");
319 if (mockNetsysClient_.CheckMockApi(MOCK_GETUIDRXBYTES_API)) {
320 return mockNetsysClient_.GetUidOnIfaceRxBytes(uid, interfaceName);
321 }
322 return netsysClient_.GetUidOnIfaceRxBytes(uid, interfaceName);
323 }
324
GetUidOnIfaceTxBytes(uint32_t uid,const std::string & interfaceName)325 int64_t NetsysControllerServiceImpl::GetUidOnIfaceTxBytes(uint32_t uid, const std::string &interfaceName)
326 {
327 NETMGR_LOG_I("NetsysControllerServiceImpl GetUidOnIfaceTxBytes");
328 if (mockNetsysClient_.CheckMockApi(MOCK_GETUIDTXBYTES_API)) {
329 return mockNetsysClient_.GetUidOnIfaceTxBytes(uid, interfaceName);
330 }
331 return netsysClient_.GetUidOnIfaceTxBytes(uid, interfaceName);
332 }
333
GetIfaceRxBytes(const std::string & interfaceName)334 int64_t NetsysControllerServiceImpl::GetIfaceRxBytes(const std::string &interfaceName)
335 {
336 NETMGR_LOG_I("NetsysControllerServiceImpl GetIfaceRxBytes");
337 if (mockNetsysClient_.CheckMockApi(MOCK_GETIFACERXBYTES_API)) {
338 return mockNetsysClient_.GetIfaceRxBytes(interfaceName);
339 }
340 return netsysClient_.GetIfaceRxBytes(interfaceName);
341 }
342
GetIfaceTxBytes(const std::string & interfaceName)343 int64_t NetsysControllerServiceImpl::GetIfaceTxBytes(const std::string &interfaceName)
344 {
345 NETMGR_LOG_I("NetsysControllerServiceImpl GetIfaceTxBytes");
346 if (mockNetsysClient_.CheckMockApi(MOCK_GETIFACETXBYTES_API)) {
347 return mockNetsysClient_.GetIfaceTxBytes(interfaceName);
348 }
349 return netsysClient_.GetIfaceTxBytes(interfaceName);
350 }
351
InterfaceGetList()352 std::vector<std::string> NetsysControllerServiceImpl::InterfaceGetList()
353 {
354 NETMGR_LOG_I("NetsysControllerServiceImpl InterfaceGetList");
355 if (mockNetsysClient_.CheckMockApi(MOCK_INTERFACEGETLIST_API)) {
356 return mockNetsysClient_.InterfaceGetList();
357 }
358 return netsysClient_.InterfaceGetList();
359 }
360
UidGetList()361 std::vector<std::string> NetsysControllerServiceImpl::UidGetList()
362 {
363 NETMGR_LOG_I("NetsysControllerServiceImpl UidGetList");
364 if (mockNetsysClient_.CheckMockApi(MOCK_UIDGETLIST_API)) {
365 return mockNetsysClient_.UidGetList();
366 }
367 return netsysClient_.UidGetList();
368 }
369
GetIfaceRxPackets(const std::string & interfaceName)370 int64_t NetsysControllerServiceImpl::GetIfaceRxPackets(const std::string &interfaceName)
371 {
372 NETMGR_LOG_D("NetsysControllerServiceImpl GetIfaceRxPackets");
373 if (mockNetsysClient_.CheckMockApi(MOCK_GETIFACERXPACKETS_API)) {
374 return mockNetsysClient_.GetIfaceRxPackets(interfaceName);
375 }
376 return netsysClient_.GetIfaceRxPackets(interfaceName);
377 }
378
GetIfaceTxPackets(const std::string & interfaceName)379 int64_t NetsysControllerServiceImpl::GetIfaceTxPackets(const std::string &interfaceName)
380 {
381 NETMGR_LOG_D("NetsysControllerServiceImpl GetIfaceTxPackets");
382 if (mockNetsysClient_.CheckMockApi(MOCK_GETIFACETXPACKETS_API)) {
383 return mockNetsysClient_.GetIfaceTxPackets(interfaceName);
384 }
385 return netsysClient_.GetIfaceTxPackets(interfaceName);
386 }
387
SetDefaultNetWork(int32_t netId)388 int32_t NetsysControllerServiceImpl::SetDefaultNetWork(int32_t netId)
389 {
390 NETMGR_LOG_D("NetsysControllerServiceImpl SetDefaultNetWork");
391 if (mockNetsysClient_.CheckMockApi(MOCK_SETDEFAULTNETWORK_API)) {
392 return mockNetsysClient_.SetDefaultNetWork(netId);
393 }
394 return netsysClient_.SetDefaultNetWork(netId);
395 }
396
ClearDefaultNetWorkNetId()397 int32_t NetsysControllerServiceImpl::ClearDefaultNetWorkNetId()
398 {
399 NETMGR_LOG_D("NetsysControllerServiceImpl ClearDefaultNetWorkNetId");
400 if (mockNetsysClient_.CheckMockApi(MOCK_CLEARDEFAULTNETWORK_API)) {
401 return mockNetsysClient_.ClearDefaultNetWorkNetId();
402 }
403 return netsysClient_.ClearDefaultNetWorkNetId();
404 }
405
BindSocket(int32_t socketFd,uint32_t netId)406 int32_t NetsysControllerServiceImpl::BindSocket(int32_t socketFd, uint32_t netId)
407 {
408 NETMGR_LOG_D("NetsysControllerServiceImpl BindSocket");
409 if (mockNetsysClient_.CheckMockApi(MOCK_BINDSOCKET_API)) {
410 return mockNetsysClient_.BindSocket(socketFd, netId);
411 }
412 return netsysClient_.BindSocket(socketFd, netId);
413 }
414
IpEnableForwarding(const std::string & requestor)415 int32_t NetsysControllerServiceImpl::IpEnableForwarding(const std::string &requestor)
416 {
417 NETMGR_LOG_D("NetsysControllerServiceImpl IpEnableForwarding");
418 return netsysClient_.IpEnableForwarding(requestor);
419 }
420
IpDisableForwarding(const std::string & requestor)421 int32_t NetsysControllerServiceImpl::IpDisableForwarding(const std::string &requestor)
422 {
423 NETMGR_LOG_D("NetsysControllerServiceImpl IpDisableForwarding");
424 return netsysClient_.IpDisableForwarding(requestor);
425 }
426
EnableNat(const std::string & downstreamIface,const std::string & upstreamIface)427 int32_t NetsysControllerServiceImpl::EnableNat(const std::string &downstreamIface, const std::string &upstreamIface)
428 {
429 NETMGR_LOG_D("NetsysControllerServiceImpl EnableNat");
430 return netsysClient_.EnableNat(downstreamIface, upstreamIface);
431 }
432
DisableNat(const std::string & downstreamIface,const std::string & upstreamIface)433 int32_t NetsysControllerServiceImpl::DisableNat(const std::string &downstreamIface, const std::string &upstreamIface)
434 {
435 NETMGR_LOG_D("NetsysControllerServiceImpl DisableNat");
436 return netsysClient_.DisableNat(downstreamIface, upstreamIface);
437 }
438
IpfwdAddInterfaceForward(const std::string & fromIface,const std::string & toIface)439 int32_t NetsysControllerServiceImpl::IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface)
440 {
441 NETMGR_LOG_D("NetsysControllerServiceImpl IpfwdAddInterfaceForward");
442 return netsysClient_.IpfwdAddInterfaceForward(fromIface, toIface);
443 }
444
IpfwdRemoveInterfaceForward(const std::string & fromIface,const std::string & toIface)445 int32_t NetsysControllerServiceImpl::IpfwdRemoveInterfaceForward(const std::string &fromIface,
446 const std::string &toIface)
447 {
448 NETMGR_LOG_D("NetsysControllerServiceImpl IpfwdRemoveInterfaceForward");
449 return netsysClient_.IpfwdRemoveInterfaceForward(fromIface, toIface);
450 }
451
ShareDnsSet(uint16_t netId)452 int32_t NetsysControllerServiceImpl::ShareDnsSet(uint16_t netId)
453 {
454 NETMGR_LOG_D("NetsysControllerServiceImpl IpfwdRemoveInterfaceForward");
455 if (mockNetsysClient_.CheckMockApi(MOCK_SHAREDNSSET_API)) {
456 return mockNetsysClient_.ShareDnsSet(netId);
457 }
458 return netsysClient_.ShareDnsSet(netId);
459 }
460
StartDnsProxyListen()461 int32_t NetsysControllerServiceImpl::StartDnsProxyListen()
462 {
463 NETMGR_LOG_D("NetsysControllerServiceImpl StartDnsProxyListen");
464 return netsysClient_.StartDnsProxyListen();
465 }
466
StopDnsProxyListen()467 int32_t NetsysControllerServiceImpl::StopDnsProxyListen()
468 {
469 NETMGR_LOG_D("NetsysControllerServiceImpl StopDnsProxyListen");
470 return netsysClient_.StopDnsProxyListen();
471 }
472
RegisterNetsysNotifyCallback(const NetsysNotifyCallback & callback)473 int32_t NetsysControllerServiceImpl::RegisterNetsysNotifyCallback(const NetsysNotifyCallback &callback)
474 {
475 NETMGR_LOG_D("NetsysControllerServiceImpl IpfwdRemoveInterfaceForward");
476 if (mockNetsysClient_.CheckMockApi(MOCK_REGISTERNETSYSNOTIFYCALLBACK_API)) {
477 return mockNetsysClient_.RegisterNetsysNotifyCallback(callback);
478 }
479 return netsysClient_.RegisterNetsysNotifyCallback(callback);
480 }
481
BindNetworkServiceVpn(int32_t socketFd)482 int32_t NetsysControllerServiceImpl::BindNetworkServiceVpn(int32_t socketFd)
483 {
484 NETMGR_LOG_D("NetsysNativeClient::BindNetworkServiceVpn");
485 if (mockNetsysClient_.CheckMockApi(MOCK_BINDNETWORKSERVICEVPN_API)) {
486 return mockNetsysClient_.BindNetworkServiceVpn(socketFd);
487 }
488 return netsysClient_.BindNetworkServiceVpn(socketFd);
489 }
490
EnableVirtualNetIfaceCard(int32_t socketFd,struct ifreq & ifRequest,int32_t & ifaceFd)491 int32_t NetsysControllerServiceImpl::EnableVirtualNetIfaceCard(int32_t socketFd, struct ifreq &ifRequest,
492 int32_t &ifaceFd)
493 {
494 NETMGR_LOG_D("NetsysControllerServiceImpl::EnableVirtualNetIfaceCard");
495 if (mockNetsysClient_.CheckMockApi(MOCK_ENABLEVIRTUALNETIFACECARD_API)) {
496 return mockNetsysClient_.EnableVirtualNetIfaceCard(socketFd, ifRequest, ifaceFd);
497 }
498 return netsysClient_.EnableVirtualNetIfaceCard(socketFd, ifRequest, ifaceFd);
499 }
500
SetIpAddress(int32_t socketFd,const std::string & ipAddress,int32_t prefixLen,struct ifreq & ifRequest)501 int32_t NetsysControllerServiceImpl::SetIpAddress(int32_t socketFd, const std::string &ipAddress, int32_t prefixLen,
502 struct ifreq &ifRequest)
503 {
504 NETMGR_LOG_D("NetsysControllerServiceImpl::SetIpAddress");
505 if (mockNetsysClient_.CheckMockApi(MOCK_SETIPADDRESS_API)) {
506 return mockNetsysClient_.SetIpAddress(socketFd, ipAddress, prefixLen, ifRequest);
507 }
508 return netsysClient_.SetIpAddress(socketFd, ipAddress, prefixLen, ifRequest);
509 }
510
SetBlocking(int32_t ifaceFd,bool isBlock)511 int32_t NetsysControllerServiceImpl::SetBlocking(int32_t ifaceFd, bool isBlock)
512 {
513 NETMGR_LOG_D("NetsysControllerServiceImpl::SetBlocking");
514 if (mockNetsysClient_.CheckMockApi(MOCK_SETBLOCKING_API)) {
515 return mockNetsysClient_.SetBlocking(ifaceFd, isBlock);
516 }
517 return netsysClient_.SetBlocking(ifaceFd, isBlock);
518 }
519
StartDhcpClient(const std::string & iface,bool bIpv6)520 int32_t NetsysControllerServiceImpl::StartDhcpClient(const std::string &iface, bool bIpv6)
521 {
522 NETMGR_LOG_D("NetsysControllerServiceImpl::StartDhcpClient");
523 if (mockNetsysClient_.CheckMockApi(MOCK_STARTDHCPCLIENT_API)) {
524 return mockNetsysClient_.StartDhcpClient(iface, bIpv6);
525 }
526 return netsysClient_.StartDhcpClient(iface, bIpv6);
527 }
528
StopDhcpClient(const std::string & iface,bool bIpv6)529 int32_t NetsysControllerServiceImpl::StopDhcpClient(const std::string &iface, bool bIpv6)
530 {
531 NETMGR_LOG_D("NetsysControllerServiceImpl::StopDhcpClient");
532 if (mockNetsysClient_.CheckMockApi(MOCK_STOPDHCPCLIENT_API)) {
533 return mockNetsysClient_.StopDhcpClient(iface, bIpv6);
534 }
535 return netsysClient_.StopDhcpClient(iface, bIpv6);
536 }
537
RegisterCallback(sptr<NetsysControllerCallback> callback)538 int32_t NetsysControllerServiceImpl::RegisterCallback(sptr<NetsysControllerCallback> callback)
539 {
540 NETMGR_LOG_D("NetsysControllerServiceImpl::RegisterCallback");
541 if (mockNetsysClient_.CheckMockApi(MOCK_REGISTERNOTIFYCALLBACK_API)) {
542 return mockNetsysClient_.RegisterCallback(callback);
543 }
544 return netsysClient_.RegisterCallback(callback);
545 }
546
StartDhcpService(const std::string & iface,const std::string & ipv4addr)547 int32_t NetsysControllerServiceImpl::StartDhcpService(const std::string &iface, const std::string &ipv4addr)
548 {
549 NETMGR_LOG_D("NetsysControllerServiceImpl::SetBlocking");
550 if (mockNetsysClient_.CheckMockApi(MOCK_STARTDHCPSERVICE_API)) {
551 return mockNetsysClient_.StartDhcpService(iface, ipv4addr);
552 }
553 return netsysClient_.StartDhcpService(iface, ipv4addr);
554 }
555
StopDhcpService(const std::string & iface)556 int32_t NetsysControllerServiceImpl::StopDhcpService(const std::string &iface)
557 {
558 NETMGR_LOG_D("NetsysControllerServiceImpl::StopDhcpService");
559 if (mockNetsysClient_.CheckMockApi(MOCK_STOPDHCPSERVICE_API)) {
560 return mockNetsysClient_.StopDhcpService(iface);
561 }
562 return netsysClient_.StopDhcpService(iface);
563 }
564
BandwidthEnableDataSaver(bool enable)565 int32_t NetsysControllerServiceImpl::BandwidthEnableDataSaver(bool enable)
566 {
567 NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthEnableDataSaver: enable=%{public}d", enable);
568 return netsysClient_.BandwidthEnableDataSaver(enable);
569 }
570
BandwidthSetIfaceQuota(const std::string & ifName,int64_t bytes)571 int32_t NetsysControllerServiceImpl::BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes)
572 {
573 NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthSetIfaceQuota: ifName=%{public}s", ifName.c_str());
574 return netsysClient_.BandwidthSetIfaceQuota(ifName, bytes);
575 }
576
BandwidthRemoveIfaceQuota(const std::string & ifName)577 int32_t NetsysControllerServiceImpl::BandwidthRemoveIfaceQuota(const std::string &ifName)
578 {
579 NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthRemoveIfaceQuota: ifName=%{public}s", ifName.c_str());
580 return netsysClient_.BandwidthRemoveIfaceQuota(ifName);
581 }
582
BandwidthAddDeniedList(uint32_t uid)583 int32_t NetsysControllerServiceImpl::BandwidthAddDeniedList(uint32_t uid)
584 {
585 NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthAddDeniedList: uid=%{public}d", uid);
586 return netsysClient_.BandwidthAddDeniedList(uid);
587 }
588
BandwidthRemoveDeniedList(uint32_t uid)589 int32_t NetsysControllerServiceImpl::BandwidthRemoveDeniedList(uint32_t uid)
590 {
591 NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthRemoveDeniedList: uid=%{public}d", uid);
592 return netsysClient_.BandwidthRemoveDeniedList(uid);
593 }
594
BandwidthAddAllowedList(uint32_t uid)595 int32_t NetsysControllerServiceImpl::BandwidthAddAllowedList(uint32_t uid)
596 {
597 NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthAddAllowedList: uid=%{public}d", uid);
598 return netsysClient_.BandwidthAddAllowedList(uid);
599 }
600
BandwidthRemoveAllowedList(uint32_t uid)601 int32_t NetsysControllerServiceImpl::BandwidthRemoveAllowedList(uint32_t uid)
602 {
603 NETMGR_LOG_D("NetsysControllerServiceImpl::BandwidthRemoveAllowedList: uid=%{public}d", uid);
604 return netsysClient_.BandwidthRemoveAllowedList(uid);
605 }
606
FirewallSetUidsAllowedListChain(uint32_t chain,const std::vector<uint32_t> & uids)607 int32_t NetsysControllerServiceImpl::FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
608 {
609 NETMGR_LOG_D("NetsysControllerServiceImpl::FirewallSetUidsAllowedListChain: chain=%{public}d", chain);
610 return netsysClient_.FirewallSetUidsAllowedListChain(chain, uids);
611 }
612
FirewallSetUidsDeniedListChain(uint32_t chain,const std::vector<uint32_t> & uids)613 int32_t NetsysControllerServiceImpl::FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
614 {
615 NETMGR_LOG_D("NetsysControllerServiceImpl::FirewallSetUidsDeniedListChain: chain=%{public}d", chain);
616 return netsysClient_.FirewallSetUidsDeniedListChain(chain, uids);
617 }
618
FirewallEnableChain(uint32_t chain,bool enable)619 int32_t NetsysControllerServiceImpl::FirewallEnableChain(uint32_t chain, bool enable)
620 {
621 NETMGR_LOG_D("NetsysController::FirewallEnableChain: chain=%{public}d, enable=%{public}d", chain, enable);
622 return netsysClient_.FirewallEnableChain(chain, enable);
623 }
624
FirewallSetUidRule(uint32_t chain,const std::vector<uint32_t> & uids,uint32_t firewallRule)625 int32_t NetsysControllerServiceImpl::FirewallSetUidRule(uint32_t chain, const std::vector<uint32_t> &uids,
626 uint32_t firewallRule)
627 {
628 return netsysClient_.FirewallSetUidRule(chain, uids, firewallRule);
629 }
630
GetTotalStats(uint64_t & stats,uint32_t type)631 int32_t NetsysControllerServiceImpl::GetTotalStats(uint64_t &stats, uint32_t type)
632 {
633 NETMGR_LOG_D("NetsysControllerServiceImpl::GetTotalStats: type=%{public}d", type);
634 return netsysClient_.GetTotalStats(stats, type);
635 }
636
GetUidStats(uint64_t & stats,uint32_t type,uint32_t uid)637 int32_t NetsysControllerServiceImpl::GetUidStats(uint64_t &stats, uint32_t type, uint32_t uid)
638 {
639 NETMGR_LOG_D("NetsysControllerServiceImpl::GetUidStats: type=%{public}d uid=%{public}d", type, uid);
640 return netsysClient_.GetUidStats(stats, type, uid);
641 }
642
GetIfaceStats(uint64_t & stats,uint32_t type,const std::string & interfaceName)643 int32_t NetsysControllerServiceImpl::GetIfaceStats(uint64_t &stats, uint32_t type, const std::string &interfaceName)
644 {
645 NETMGR_LOG_D("NetsysControllerServiceImpl::GetIfaceStats: type=%{public}d", type);
646 return netsysClient_.GetIfaceStats(stats, type, interfaceName);
647 }
648
GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> & stats)649 int32_t NetsysControllerServiceImpl::GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats)
650 {
651 NETMGR_LOG_D("NetsysControllerServiceImpl::GetAllStatsInfo");
652 return netsysClient_.GetAllStatsInfo(stats);
653 }
654
SetIptablesCommandForRes(const std::string & cmd,std::string & respond)655 int32_t NetsysControllerServiceImpl::SetIptablesCommandForRes(const std::string &cmd, std::string &respond)
656 {
657 return netsysClient_.SetIptablesCommandForRes(cmd, respond);
658 }
659
NetDiagPingHost(const OHOS::NetsysNative::NetDiagPingOption & pingOption,const sptr<OHOS::NetsysNative::INetDiagCallback> & callback)660 int32_t NetsysControllerServiceImpl::NetDiagPingHost(const OHOS::NetsysNative::NetDiagPingOption &pingOption,
661 const sptr<OHOS::NetsysNative::INetDiagCallback> &callback)
662 {
663 NETMGR_LOG_D("NetsysControllerServiceImpl::NetDiagPingHost");
664 return netsysClient_.NetDiagPingHost(pingOption, callback);
665 }
666
NetDiagGetRouteTable(std::list<OHOS::NetsysNative::NetDiagRouteTable> & routeTables)667 int32_t NetsysControllerServiceImpl::NetDiagGetRouteTable(std::list<OHOS::NetsysNative::NetDiagRouteTable> &routeTables)
668 {
669 NETMGR_LOG_D("NetsysControllerServiceImpl::NetDiagGetRouteTable");
670 return netsysClient_.NetDiagGetRouteTable(routeTables);
671 }
672
NetDiagGetSocketsInfo(OHOS::NetsysNative::NetDiagProtocolType socketType,OHOS::NetsysNative::NetDiagSocketsInfo & socketsInfo)673 int32_t NetsysControllerServiceImpl::NetDiagGetSocketsInfo(OHOS::NetsysNative::NetDiagProtocolType socketType,
674 OHOS::NetsysNative::NetDiagSocketsInfo &socketsInfo)
675 {
676 NETMGR_LOG_D("NetsysControllerServiceImpl::NetDiagGetSocketsInfo");
677 return netsysClient_.NetDiagGetSocketsInfo(socketType, socketsInfo);
678 }
679
NetDiagGetInterfaceConfig(std::list<OHOS::NetsysNative::NetDiagIfaceConfig> & configs,const std::string & ifaceName)680 int32_t NetsysControllerServiceImpl::NetDiagGetInterfaceConfig(
681 std::list<OHOS::NetsysNative::NetDiagIfaceConfig> &configs, const std::string &ifaceName)
682 {
683 NETMGR_LOG_D("NetsysControllerServiceImpl::NetDiagGetInterfaceConfig");
684 return netsysClient_.NetDiagGetInterfaceConfig(configs, ifaceName);
685 }
686
NetDiagUpdateInterfaceConfig(const OHOS::NetsysNative::NetDiagIfaceConfig & config,const std::string & ifaceName,bool add)687 int32_t NetsysControllerServiceImpl::NetDiagUpdateInterfaceConfig(const OHOS::NetsysNative::NetDiagIfaceConfig &config,
688 const std::string &ifaceName, bool add)
689 {
690 NETMGR_LOG_D("NetsysControllerServiceImpl::NetDiagUpdateInterfaceConfig");
691 return netsysClient_.NetDiagUpdateInterfaceConfig(config, ifaceName, add);
692 }
693
NetDiagSetInterfaceActiveState(const std::string & ifaceName,bool up)694 int32_t NetsysControllerServiceImpl::NetDiagSetInterfaceActiveState(const std::string &ifaceName, bool up)
695 {
696 NETMGR_LOG_D("NetsysControllerServiceImpl::NetDiagSetInterfaceActiveState");
697 return netsysClient_.NetDiagSetInterfaceActiveState(ifaceName, up);
698 }
699
AddStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)700 int32_t NetsysControllerServiceImpl::AddStaticArp(const std::string &ipAddr, const std::string &macAddr,
701 const std::string &ifName)
702 {
703 NETMGR_LOG_D("NetsysControllerServiceImpl::AddStaticArp");
704 return netsysClient_.AddStaticArp(ipAddr, macAddr, ifName);
705 }
706
DelStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)707 int32_t NetsysControllerServiceImpl::DelStaticArp(const std::string &ipAddr, const std::string &macAddr,
708 const std::string &ifName)
709 {
710 NETMGR_LOG_D("NetsysControllerServiceImpl::DelStaticArp");
711 return netsysClient_.DelStaticArp(ipAddr, macAddr, ifName);
712 }
713
RegisterDnsResultCallback(const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> & callback,uint32_t timeStep)714 int32_t NetsysControllerServiceImpl::RegisterDnsResultCallback(
715 const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback, uint32_t timeStep)
716 {
717 NETMGR_LOG_D("NetsysControllerServiceImpl::RegisterDnsResultListener");
718 return netsysClient_.RegisterDnsResultCallback(callback, timeStep);
719 }
720
UnregisterDnsResultCallback(const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> & callback)721 int32_t NetsysControllerServiceImpl::UnregisterDnsResultCallback(
722 const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback)
723 {
724 NETMGR_LOG_D("NetsysControllerServiceImpl::UnregisterDnsResultListener");
725 return netsysClient_.UnregisterDnsResultCallback(callback);
726 }
727
RegisterDnsHealthCallback(const sptr<INetDnsHealthCallback> & callback)728 int32_t NetsysControllerServiceImpl::RegisterDnsHealthCallback(const sptr<INetDnsHealthCallback> &callback)
729 {
730 NETMGR_LOG_D("NetsysControllerServiceImpl::RegisterDnsResultListener");
731 return netsysClient_.RegisterDnsHealthCallback(callback);
732 }
733
UnregisterDnsHealthCallback(const sptr<INetDnsHealthCallback> & callback)734 int32_t NetsysControllerServiceImpl::UnregisterDnsHealthCallback(const sptr<INetDnsHealthCallback> &callback)
735 {
736 NETMGR_LOG_D("NetsysControllerServiceImpl::UnregisterDnsResultListener");
737 return netsysClient_.UnregisterDnsHealthCallback(callback);
738 }
739
GetCookieStats(uint64_t & stats,uint32_t type,uint64_t cookie)740 int32_t NetsysControllerServiceImpl::GetCookieStats(uint64_t &stats, uint32_t type, uint64_t cookie)
741 {
742 NETMGR_LOG_D("NetsysControllerServiceImpl::GetCookieStats: type=%{public}d cookie=%{public}llu", type, cookie);
743 return netsysClient_.GetCookieStats(stats, type, cookie);
744 }
745 } // namespace NetManagerStandard
746 } // namespace OHOS
747