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