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 #ifndef NETSYS_CONTROLLER_SERVICE_IMPL_H
17 #define NETSYS_CONTROLLER_SERVICE_IMPL_H
18 
19 #include "i_netsys_controller_service.h"
20 #include "mock_netsys_native_client.h"
21 #include "netsys_native_client.h"
22 
23 namespace OHOS {
24 namespace NetManagerStandard {
25 class NetsysControllerServiceImpl : public INetsysControllerService {
26 public:
27     NetsysControllerServiceImpl() = default;
28     ~NetsysControllerServiceImpl() = default;
29     void Init() override;
30 
31     /**
32      * Disallow or allow a app to create AF_INET or AF_INET6 socket
33      *
34      * @param uid App's uid which need to be disallowed ot allowed to create AF_INET or AF_INET6 socket
35      * @param allow 0 means disallow, 1 means allow
36      * @return return 0 if OK, return error number if not OK
37      */
38     int32_t SetInternetPermission(uint32_t uid, uint8_t allow) override;
39 
40     /**
41      * Create a physical network
42      *
43      * @param netId
44      * @param permission Permission to create a physical network
45      * @return Return the return value of the netsys interface call
46      */
47     int32_t NetworkCreatePhysical(int32_t netId, int32_t permission) override;
48 
49     int32_t NetworkCreateVirtual(int32_t netId, bool hasDns) override;
50 
51     /**
52      * Destroy the network
53      *
54      * @param netId
55      * @return Return the return value of the netsys interface call
56      */
57     int32_t NetworkDestroy(int32_t netId) override;
58 
59     int32_t CreateVnic(uint16_t mtu, const std::string &tunAddr, int32_t prefix,
60                        const std::set<int32_t> &uids) override;
61     int32_t DestroyVnic() override;
62     int32_t NetworkAddUids(int32_t netId, const std::vector<UidRange> &uidRanges) override;
63     int32_t NetworkDelUids(int32_t netId, const std::vector<UidRange> &uidRanges) override;
64 
65     /**
66      * Add network port device
67      *
68      * @param netId
69      * @param iface Network port device name
70      * @return Return the return value of the netsys interface call
71      */
72     int32_t NetworkAddInterface(int32_t netId, const std::string &iface, NetBearType netBearerType) override;
73 
74     /**
75      * Delete network port device
76      *
77      * @param netId
78      * @param iface Network port device name
79      * @return Return the return value of the netsys interface call
80      */
81     int32_t NetworkRemoveInterface(int32_t netId, const std::string &iface) override;
82 
83     /**
84      * Add route
85      *
86      * @param netId
87      * @param ifName Network port device name
88      * @param destination Target host ip
89      * @param nextHop Next hop address
90      * @return Return the return value of the netsys interface call
91      */
92     int32_t NetworkAddRoute(int32_t netId, const std::string &ifName, const std::string &destination,
93                             const std::string &nextHop) override;
94 
95     /**
96      * Remove route
97      *
98      * @param netId
99      * @param ifName Network port device name
100      * @param destination Target host ip
101      * @param nextHop Next hop address
102      * @return Return the return value of the netsys interface call
103      */
104     int32_t NetworkRemoveRoute(int32_t netId, const std::string &ifName, const std::string &destination,
105                                const std::string &nextHop) override;
106 
107     /**
108      * @brief Get interface config
109      *
110      * @param iface Network port device name
111      * @return Return the result of this action, ERR_NONE is success.
112      */
113     int32_t GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel &cfg) override;
114 
115     /**
116      * @brief Set interface config
117      *
118      * @param cfg Network port info
119      * @return Return the result of this action, ERR_NONE is success.
120      */
121     int32_t SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel &cfg) override;
122 
123     /**
124      * Turn off the device
125      *
126      * @param iface Network port device name
127      * @return Return the result of this action
128      */
129     int32_t SetInterfaceDown(const std::string &iface) override;
130 
131     /**
132      * Turn on the device
133      *
134      * @param iface Network port device name
135      * @return Return the result of this action
136      */
137     int32_t SetInterfaceUp(const std::string &iface) override;
138 
139     /**
140      * Clear the network interface ip address
141      *
142      * @param ifName Network port device name
143      */
144     void ClearInterfaceAddrs(const std::string &ifName) override;
145 
146     /**
147      * Obtain mtu from the network interface device
148      *
149      * @param ifName Network port device name
150      * @return Return the return value of the netsys interface call
151      */
152     int32_t GetInterfaceMtu(const std::string &ifName) override;
153 
154     /**
155      * Set mtu to network interface device
156      *
157      * @param ifName Network port device name
158      * @param mtu
159      * @return Return the return value of the netsys interface call
160      */
161     int32_t SetInterfaceMtu(const std::string &ifName, int32_t mtu) override;
162 
163     /**
164      * Set tcp buffer sizes
165      *
166      * @param tcpBufferSizes tcpBufferSizes
167      * @return Return the return value of the netsys interface call
168      */
169     int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes) override;
170 
171     /**
172      * Add ip address
173      *
174      * @param ifName Network port device name
175      * @param ipAddr    ip address
176      * @param prefixLength  subnet mask
177      * @return Return the return value of the netsys interface call
178      */
179     int32_t AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr, int32_t prefixLength) override;
180 
181     /**
182      * Delete ip address
183      *
184      * @param ifName Network port device name
185      * @param ipAddr ip address
186      * @param prefixLength subnet mask
187      * @return Return the return value of the netsys interface call
188      */
189     int32_t DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr, int32_t prefixLength) override;
190 
191     /**
192      * Delete ip address
193      *
194      * @param ifName Network port device name
195      * @param ipAddr ip address
196      * @param prefixLength subnet mask
197      * @param netCapabilities Net capabilities in string format
198      * @return Return the return value of the netsys interface call
199      */
200     int32_t DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr, int32_t prefixLength,
201                                 const std::string &netCapabilities) override;
202 
203     /**
204      * Set iface ip address
205      *
206      * @param ifaceName Network port device name
207      * @param ipAddress Ip address
208      * @return Return the return value of the netsys interface call
209      */
210     int32_t InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress) override;
211 
212     /**
213      * Set iface up
214      *
215      * @param ifaceName Network port device name
216      * @return Return the return value of the netsys interface call
217      */
218     int32_t InterfaceSetIffUp(const std::string &ifaceName) override;
219 
220     /**
221      * Set dns
222      *
223      * @param netId
224      * @param baseTimeoutMsec
225      * @param retryCount
226      * @param servers
227      * @param domains
228      * @return Return the return value of the netsys interface call
229      */
230     int32_t SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
231                               const std::vector<std::string> &servers,
232                               const std::vector<std::string> &domains) override;
233 
234     /**
235      * Get dns server param info
236      *
237      * @param netId
238      * @param servers
239      * @param domains
240      * @param baseTimeoutMsec
241      * @param retryCount
242      * @return Return the return value of the netsys interface call
243      */
244     int32_t GetResolverConfig(uint16_t netId, std::vector<std::string> &servers, std::vector<std::string> &domains,
245                               uint16_t &baseTimeoutMsec, uint8_t &retryCount) override;
246 
247     /**
248      * Create dns cache before set dns
249      *
250      * @param netId
251      * @return Return the return value for status of call
252      */
253     int32_t CreateNetworkCache(uint16_t netId) override;
254 
255     /**
256      * Destroy dns cache
257      *
258      * @param netId
259      * @return Return the return value of the netsys interface call
260      */
261     int32_t DestroyNetworkCache(uint16_t netId) override;
262 
263     /**
264      * Domain name resolution Obtains the domain name address
265      *
266      * @param hostName Domain name to be resolved
267      * @param serverName Server name used for query
268      * @param hints Limit parameters when querying
269      * @param netId Network id
270      * @param res return addrinfo
271      * @return Return the return value of the netsys interface call
272      */
273     int32_t GetAddrInfo(const std::string &hostName, const std::string &serverName, const AddrInfo &hints,
274                         uint16_t netId, std::vector<AddrInfo> &res) override;
275 
276     /**
277      * Obtains the bytes of the sharing network.
278      *
279      * @return Success return 0.
280      */
281     int32_t GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface,
282                                      nmd::NetworkSharingTraffic &traffic) override;
283 
284     /**
285      * Obtains the bytes received over the cellular network.
286      *
287      * @return The number of received bytes.
288      */
289     int64_t GetCellularRxBytes() override;
290 
291     /**
292      * Obtains the bytes sent over the cellular network.
293      *
294      * @return The number of sent bytes.
295      */
296     int64_t GetCellularTxBytes() override;
297 
298     /**
299      * Obtains the bytes received through all NICs.
300      *
301      * @return The number of received bytes.
302      */
303     int64_t GetAllRxBytes() override;
304 
305     /**
306      * Obtains the bytes sent through all NICs.
307      *
308      * @return The number of sent bytes.
309      */
310     int64_t GetAllTxBytes() override;
311 
312     /**
313      * Obtains the bytes received through a specified UID.
314      *
315      * @param uid app id.
316      * @return The number of received bytes.
317      */
318     int64_t GetUidRxBytes(uint32_t uid) override;
319 
320     /**
321      * Obtains the bytes sent through a specified UID.
322      *
323      * @param uid app id.
324      * @return The number of sent bytes.
325      */
326     int64_t GetUidTxBytes(uint32_t uid) override;
327 
328     /**
329      * Obtains the bytes received through a specified UID on Iface.
330      *
331      * @param uid app id.
332      * @param iface The name of the interface.
333      * @return The number of received bytes.
334      */
335     int64_t GetUidOnIfaceRxBytes(uint32_t uid, const std::string &interfaceName) override;
336 
337     /**
338      * Obtains the bytes sent through a specified UID on Iface.
339      *
340      * @param uid app id.
341      * @param iface The name of the interface.
342      * @return The number of sent bytes.
343      */
344     int64_t GetUidOnIfaceTxBytes(uint32_t uid, const std::string &interfaceName) override;
345 
346     /**
347      * Obtains the bytes received through a specified NIC.
348      *
349      * @param iface The name of the interface.
350      * @return The number of received bytes.
351      */
352     int64_t GetIfaceRxBytes(const std::string &interfaceName) override;
353 
354     /**
355      * Obtains the bytes sent through a specified NIC.
356      *
357      * @param iface The name of the interface.
358      * @return The number of sent bytes.
359      */
360     int64_t GetIfaceTxBytes(const std::string &interfaceName) override;
361 
362     /**
363      * Obtains the NIC list.
364      *
365      * @return The list of interface.
366      */
367     std::vector<std::string> InterfaceGetList() override;
368 
369     /**
370      * Obtains the uid list.
371      *
372      * @return The list of uid.
373      */
374     std::vector<std::string> UidGetList() override;
375 
376     /**
377      * Obtains the packets received through a specified NIC.
378      *
379      * @param iface The name of the interface.
380      * @return The number of received packets.
381      */
382     int64_t GetIfaceRxPackets(const std::string &interfaceName) override;
383 
384     /**
385      * Obtains the packets sent through a specified NIC.
386      *
387      * @param iface The name of the interface.
388      * @return The number of sent packets.
389      */
390     int64_t GetIfaceTxPackets(const std::string &interfaceName) override;
391 
392     /**
393      *  set default network.
394      *
395      * @return Return the return value of the netsys interface call
396      */
397     int32_t SetDefaultNetWork(int32_t netId) override;
398 
399     /**
400      * clear default network netId.
401      *
402      * @return Return the return value of the netsys interface call
403      */
404     int32_t ClearDefaultNetWorkNetId() override;
405 
406     /**
407      * Obtains the NIC list.
408      *
409      * @param socketFd
410      * @param netId
411      * @return Return the return value of the netsys interface call
412      */
413     int32_t BindSocket(int32_t socketFd, uint32_t netId) override;
414 
415     /**
416      * Enable ip forwarding.
417      *
418      * @param requestor the requestor of forwarding
419      * @return Return the return value of the netsys interface call.
420      */
421     int32_t IpEnableForwarding(const std::string &requestor) override;
422 
423     /**
424      * Disable ip forwarding.
425      *
426      * @param requestor the requestor of forwarding
427      * @return Return the return value of the netsys interface call.
428      */
429     int32_t IpDisableForwarding(const std::string &requestor) override;
430 
431     /**
432      * Enable Nat.
433      *
434      * @param downstreamIface the name of downstream interface
435      * @param upstreamIface the name of upstream interface
436      * @return Return the return value of the netsys interface call.
437      */
438     int32_t EnableNat(const std::string &downstramIface, const std::string &upstreamIface) override;
439     /**
440      * Disable Nat.
441      *
442      * @param downstreamIface the name of downstream interface
443      * @param upstreamIface the name of upstream interface
444      * @return Return the return value of the netsys interface call.
445      */
446     int32_t DisableNat(const std::string &downstramIface, const std::string &upstreamIface) override;
447 
448     /**
449      * Add interface forward.
450      *
451      * @param fromIface the name of incoming interface
452      * @param toIface the name of outcoming interface
453      * @return Return the return value of the netsys interface call.
454      */
455     int32_t IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface) override;
456 
457     /**
458      * Remove interface forward.
459      *
460      * @param fromIface the name of incoming interface
461      * @param toIface the name of outcoming interface
462      * @return Return the return value of the netsys interface call.
463      */
464     int32_t IpfwdRemoveInterfaceForward(const std::string &fromIface, const std::string &toIface) override;
465 
466     /**
467      * Set tether dns.
468      *
469      * @param netId network id
470      * @param dnsAddr the list of dns address
471      * @return Return the return value of the netsys interface call.
472      */
473     int32_t ShareDnsSet(uint16_t netId) override;
474 
475     /**
476      * start dns proxy listen
477      *
478      * @return int32_t
479      */
480     int32_t StartDnsProxyListen() override;
481 
482     /**
483      * stop dns proxy listen
484      *
485      * @return int32_t
486      */
487     int32_t StopDnsProxyListen() override;
488 
489     /**
490      * Set net callbackfuction.
491      *
492      * @param callback callbackfuction class
493      * @return Return the return value of the netsys interface call.
494      */
495     int32_t RegisterNetsysNotifyCallback(const NetsysNotifyCallback &callback) override;
496 
497     /**
498      * protect tradition network to connect VPN.
499      *
500      * @param socketFd socket file description
501      * @return Return the return value of the netsys interface call.
502      */
503     int32_t BindNetworkServiceVpn(int32_t socketFd) override;
504 
505     /**
506      * enable virtual network iterface card.
507      *
508      * @param socketFd socket file description
509      * @param ifRequest interface request
510      * @return Return the return value of the netsys interface call.
511      */
512     int32_t EnableVirtualNetIfaceCard(int32_t socketFd, struct ifreq &ifRequest, int32_t &ifaceFd) override;
513 
514     /**
515      * Set ip address.
516      *
517      * @param socketFd socket file description
518      * @param ipAddress ip address
519      * @param prefixLen the mask of ip address
520      * @param ifRequest interface request
521      * @return Return the return value of the netsys interface call.
522      */
523     int32_t SetIpAddress(int32_t socketFd, const std::string &ipAddress, int32_t prefixLen,
524                          struct ifreq &ifRequest) override;
525 
526     /**
527      * Set network blocking.
528      *
529      * @param ifaceFd interface file description
530      * @param isBlock network blocking
531      * @return Return the return value of the netsys interface call.
532      */
533     int32_t SetBlocking(int32_t ifaceFd, bool isBlock) override;
534     /**
535      * Start Dhcp Client.
536      *
537      * @param iface interface file description
538      * @param bIpv6 network blocking
539      * @return Return the return value of the netsys interface call.
540      */
541     int32_t StartDhcpClient(const std::string &iface, bool bIpv6) override;
542     /**
543      * Stop Dhcp Client.
544      *
545      * @param iface interface file description
546      * @param bIpv6 network blocking
547      * @return Return the return value of the netsys interface call.
548      */
549     int32_t StopDhcpClient(const std::string &iface, bool bIpv6) override;
550     /**
551      * Register Notify Callback
552      *
553      * @param callback
554      * @return Return the return value of the netsys interface call.
555      */
556     int32_t RegisterCallback(sptr<NetsysControllerCallback> callback) override;
557 
558     /**
559      * start dhcpservice.
560      *
561      * @param iface interface name
562      * @param ipv4addr ipv4 addr
563      * @return Return the return value of the netsys interface call.
564      */
565     int32_t StartDhcpService(const std::string &iface, const std::string &ipv4addr) override;
566 
567     /**
568      * stop dhcpservice.
569      *
570      * @param iface interface name
571      * @return Return the return value of the netsys interface call.
572      */
573     int32_t StopDhcpService(const std::string &iface) override;
574 
575     /**
576      * Turn on data saving mode.
577      *
578      * @param enable enable or disable
579      * @return value the return value of the netsys interface call.
580      */
581     int32_t BandwidthEnableDataSaver(bool enable) override;
582 
583     /**
584      * Set quota.
585      *
586      * @param iface interface name
587      * @param bytes
588      * @return Return the return value of the netsys interface call.
589      */
590     int32_t BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes) override;
591 
592     /**
593      * Delete quota.
594      *
595      * @param iface interface name
596      * @return Return the return value of the netsys interface call.
597      */
598     int32_t BandwidthRemoveIfaceQuota(const std::string &ifName) override;
599 
600     /**
601      * Add DeniedList.
602      *
603      * @param uid
604      * @return Return the return value of the netsys interface call.
605      */
606     int32_t BandwidthAddDeniedList(uint32_t uid) override;
607 
608     /**
609      * Remove DeniedList.
610      *
611      * @param uid
612      * @return Return the return value of the netsys interface call.
613      */
614     int32_t BandwidthRemoveDeniedList(uint32_t uid) override;
615 
616     /**
617      * Add DeniedList.
618      *
619      * @param uid
620      * @return Return the return value of the netsys interface call.
621      */
622     int32_t BandwidthAddAllowedList(uint32_t uid) override;
623 
624     /**
625      * Remove DeniedList.
626      *
627      * @param uid
628      * @return Return the return value of the netsys interface call.
629      */
630     int32_t BandwidthRemoveAllowedList(uint32_t uid) override;
631 
632     /**
633      * Set firewall rules.
634      *
635      * @param chain chain type
636      * @param isAllowedList is or not AllowedList
637      * @param uids
638      * @return value the return value of the netsys interface call.
639      */
640     int32_t FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids) override;
641 
642     /**
643      * Set firewall rules.
644      *
645      * @param chain chain type
646      * @param isAllowedList is or not AllowedList
647      * @param uids
648      * @return value the return value of the netsys interface call.
649      */
650     int32_t FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids) override;
651 
652     /**
653      * Enable or disable the specified firewall chain.
654      *
655      * @param chain chain type
656      * @param enable enable or disable
657      * @return Return the return value of the netsys interface call.
658      */
659     int32_t FirewallEnableChain(uint32_t chain, bool enable) override;
660 
661     /**
662      * Firewall set uid rule.
663      *
664      * @param chain chain type
665      * @param uid uid
666      * @param firewallRule firewall rule
667      * @return Return the return value of the netsys interface call.
668      */
669     int32_t FirewallSetUidRule(uint32_t chain, const std::vector<uint32_t> &uids, uint32_t firewallRule) override;
670 
671     /**
672      * Get total traffic
673      *
674      * @param stats stats
675      * @param type type
676      * @return returns the total traffic of the specified type
677      */
678     int32_t GetTotalStats(uint64_t &stats, uint32_t type) override;
679 
680     /**
681      * Get uid traffic
682      *
683      * @param stats stats
684      * @param type type
685      * @param uid uid
686      * @return returns the traffic of the uid
687      */
688     int32_t GetUidStats(uint64_t &stats, uint32_t type, uint32_t uid) override;
689 
690     /**
691      * Get Iface traffic
692      *
693      * @param stats stats
694      * @param type type
695      * @param interfaceName interfaceName
696      * @return returns the traffic of the Iface
697      */
698     int32_t GetIfaceStats(uint64_t &stats, uint32_t type, const std::string &interfaceName) override;
699 
700     /**
701      * Get all Sim stats info
702      * @param stats stats
703      * @return returns the all info of the stats
704      */
705     int32_t GetAllSimStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats) override;
706 
707     /**
708      * Delete the Sim Iface Stats with uid
709      *
710      * @param uid the uid of application
711      * @return returns 0 for success other as failed.
712      */
713     int32_t DeleteSimStatsInfo(uint32_t uid) override;
714 
715     /**
716      * Get all stats info
717      *
718      * @param stats stats
719      * @return returns the all info of the stats
720      */
721     int32_t GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats) override;
722 
723     /**
724      * Delete the Iface Stats with uid
725      *
726      * @param uid the uid of application
727      * @return returns 0 for success other as failed.
728      */
729     int32_t DeleteStatsInfo(uint32_t uid) override;
730 
731     /**
732      * Set iptables for result
733      *
734      * @param cmd Iptables command
735      * @param respond The respond of execute iptables command
736      * @param ipType The type of iptables command.
737      * @return Value the return value of the netsys interface call
738      */
739     int32_t SetIptablesCommandForRes(const std::string &cmd, std::string &respond,
740                                      NetsysNative::IptablesType ipType) override;
741 
742     /**
743      * Check network connectivity by sending packets to a host and reporting its response.
744      *
745      * @param pingOption Ping option
746      * @param callback The respond of execute ping cmd.
747      * @return Value the return value of the netsys interface call
748      */
749     int32_t NetDiagPingHost(const OHOS::NetsysNative::NetDiagPingOption &pingOption,
750                             const sptr<OHOS::NetsysNative::INetDiagCallback> &callback) override;
751 
752     /**
753      * Get networking route table
754      *
755      * @param routeTables Network route table list.
756      * @return Value the return value of the netsys interface call
757      */
758     int32_t NetDiagGetRouteTable(std::list<OHOS::NetsysNative::NetDiagRouteTable> &routeTables) override;
759 
760     /**
761      * Get networking sockets info.
762      *
763      * @param socketType Network protocol.
764      * @param socketsInfo The result of network sockets info.
765      * @return Value the return value of the netsys interface call
766      */
767     int32_t NetDiagGetSocketsInfo(OHOS::NetsysNative::NetDiagProtocolType socketType,
768                                   OHOS::NetsysNative::NetDiagSocketsInfo &socketsInfo) override;
769 
770     /**
771      * Get network interface configuration.
772      *
773      * @param configs The result of network interface configuration.
774      * @param ifaceName Get interface configuration information for the specified interface name.
775      *                  If the interface name is empty, default to getting all interface configuration information.
776      * @return Value the return value of the netsys interface call
777      */
778     int32_t NetDiagGetInterfaceConfig(std::list<OHOS::NetsysNative::NetDiagIfaceConfig> &configs,
779                                       const std::string &ifaceName) override;
780 
781     /**
782      * Update network interface configuration.
783      *
784      * @param configs Network interface configuration.
785      * @param ifaceName Interface name.
786      * @param add Add or delete.
787      * @return Value the return value of the netsys interface call
788      */
789     int32_t NetDiagUpdateInterfaceConfig(const OHOS::NetsysNative::NetDiagIfaceConfig &config,
790                                          const std::string &ifaceName, bool add) override;
791 
792     /**
793      * Set network interface up/down state.
794      *
795      * @param ifaceName Interface name.
796      * @param up Up or down.
797      * @return Value the return value of the netsys interface call
798      */
799     int32_t NetDiagSetInterfaceActiveState(const std::string &ifaceName, bool up) override;
800     int32_t AddStaticArp(const std::string &ipAddr, const std::string &macAddr,
801                          const std::string &ifName) override;
802 
803     int32_t DelStaticArp(const std::string &ipAddr, const std::string &macAddr,
804                          const std::string &ifName) override;
805 
806     /**
807      * Register Dns Result Callback Listener.
808      *
809      * @param callback Callback function
810      * @param timestep Time gap between two callbacks
811      * @return Value the return value of the netsys interface call
812      */
813     int32_t RegisterDnsResultCallback(const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback,
814         uint32_t timeStep) override;
815 
816     /**
817      * Unregister Dns Result Callback Listener.
818      *
819      * @param callback Callback function
820      * @return Value the return value of the netsys interface call
821      */
822     int32_t UnregisterDnsResultCallback(
823         const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback) override;
824 
825     /**
826      * Register Dns Health Callback Listener.
827      *
828      * @param callback Callback function
829      * @return Value the return value of the netsys interface call
830      */
831     int32_t RegisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> &callback) override;
832 
833     /**
834      * Unregister Dns Health Callback Listener.
835      *
836      * @param callback Callback function
837      * @return Value the return value of the netsys interface call
838      */
839     int32_t UnregisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> &callback) override;
840 
841     /**
842      * Get Cookie Stats.
843      *
844      * @param stats stats
845      * @param type type
846      * @param cookie cookie
847      * @return Value the return value of the netsys interface call
848      */
849     int32_t GetCookieStats(uint64_t &stats, uint32_t type, uint64_t cookie) override;
850 
851     int32_t GetNetworkSharingType(std::set<uint32_t>& sharingTypeIsOn) override;
852 
853     int32_t UpdateNetworkSharingType(uint32_t type, bool isOpen) override;
854 
855 #ifdef FEATURE_NET_FIREWALL_ENABLE
856     /**
857      * Set firewall rules to native
858      *
859      * @param type ip, dns, domain
860      * @param ruleList list of NetFirewallIpRule
861      * @param isFinish transmit finish or not
862      * @return 0 if success or -1 if an error occurred
863      */
864     int32_t SetFirewallRules(NetFirewallRuleType type, const std::vector<sptr<NetFirewallBaseRule>> &ruleList,
865                              bool isFinish) override;
866 
867     /**
868      * Set firewall default action
869      *
870      * @param inDefault  Default action of NetFirewallRuleDirection:RULE_IN
871      * @param outDefault Default action of NetFirewallRuleDirection:RULE_OUT
872      * @return 0 if success or -1 if an error occurred
873      */
874     int32_t SetFirewallDefaultAction(FirewallRuleAction inDefault, FirewallRuleAction outDefault) override;
875 
876     /**
877      * Set firewall current user id
878      *
879      * @param userId current user id
880      * @return 0 if success or -1 if an error occurred
881      */
882     int32_t SetFirewallCurrentUserId(int32_t userId) override;
883 
884     /**
885      * Clear firewall rules by type
886      *
887      * @param type ip, dns, domain, all
888      * @return 0 if success or -1 if an error occurred
889      */
890     int32_t ClearFirewallRules(NetFirewallRuleType type) override;
891 
892     /**
893      * Register callback for recevie intercept event
894      *
895      * @param callback implement of INetFirewallCallback
896      * @return 0 if success or -1 if an error occurred
897      */
898     int32_t RegisterNetFirewallCallback(const sptr<NetsysNative::INetFirewallCallback> &callback) override;
899 
900     /**
901      * Unregister callback for recevie intercept event
902      *
903      * @param callback register callback for recevie intercept event
904      * @return 0 if success or -1 if an error occurred
905      */
906     int32_t UnRegisterNetFirewallCallback(const sptr<NetsysNative::INetFirewallCallback> &callback) override;
907 #endif
908 
909     int32_t SetIpv6PrivacyExtensions(const std::string &interfaceName, const uint32_t on) override;
910 
911     int32_t SetEnableIpv6(const std::string &interfaceName, const uint32_t on) override;
912 
913     /**
914      * Set the policy to access the network of the specified application.
915      *
916      * @param uid - The specified UID of application.
917      * @param policy - the network access policy of application. For details, see {@link NetworkAccessPolicy}.
918      * @param reconfirmFlag true means a reconfirm diaglog trigger while policy deny network access.
919      * @param isBroker true means the broker application.
920      * @return return 0 if OK, return error number if not OK
921      */
922     int32_t SetNetworkAccessPolicy(uint32_t uid, NetworkAccessPolicy policy, bool reconfirmFlag,
923                                    bool isBroker) override;
924     int32_t DeleteNetworkAccessPolicy(uint32_t uid) override;
925     int32_t NotifyNetBearerTypeChange(std::set<NetBearType> bearerTypes) override;
926 
927     int32_t StartClat(const std::string &interfaceName, int32_t netId, const std::string &nat64PrefixStr) override;
928     int32_t StopClat(const std::string &interfaceName) override;
929 
930     /**
931      * Clear firewall All Rules
932      */
933     int32_t ClearFirewallAllRules() override;
934 
935     /**
936      * Set NIC Traffic allowed or disallowed
937      *
938      * @param ifaceNames ifaceNames
939      * @param status true for allowed, false for disallowed
940      * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
941      */
942     int32_t SetNicTrafficAllowed(const std::vector<std::string> &ifaceNames, bool status) override;
943 private:
944     MockNetsysNativeClient mockNetsysClient_;
945     NetsysNativeClient netsysClient_;
946 };
947 } // namespace NetManagerStandard
948 } // namespace OHOS
949 #endif // NETSYS_CONTROLLER_SERVICE_IMPL_H
950