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