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