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