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