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