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