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