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