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