1b1b8bc3fSopenharmony_ci/* 2b1b8bc3fSopenharmony_ci * Copyright (c) 2021-2024 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#include "netsys_controller.h" 16b1b8bc3fSopenharmony_ci 17b1b8bc3fSopenharmony_ci#include "net_conn_constants.h" 18b1b8bc3fSopenharmony_ci#include "net_conn_types.h" 19b1b8bc3fSopenharmony_ci#include "net_mgr_log_wrapper.h" 20b1b8bc3fSopenharmony_ci#include "netmanager_base_common_utils.h" 21b1b8bc3fSopenharmony_ci#include "netsys_controller_service_impl.h" 22b1b8bc3fSopenharmony_ci#include "i_net_dns_result_callback.h" 23b1b8bc3fSopenharmony_ci#include "i_net_dns_health_callback.h" 24b1b8bc3fSopenharmony_ci 25b1b8bc3fSopenharmony_ciusing namespace OHOS::NetManagerStandard::CommonUtils; 26b1b8bc3fSopenharmony_cinamespace OHOS { 27b1b8bc3fSopenharmony_cinamespace NetManagerStandard { 28b1b8bc3fSopenharmony_cistatic constexpr uint32_t IPV4_MAX_LENGTH = 32; 29b1b8bc3fSopenharmony_ci 30b1b8bc3fSopenharmony_civoid NetsysController::Init() 31b1b8bc3fSopenharmony_ci{ 32b1b8bc3fSopenharmony_ci NETMGR_LOG_I("netsys Init"); 33b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 34b1b8bc3fSopenharmony_ci if (initFlag_) { 35b1b8bc3fSopenharmony_ci NETMGR_LOG_I("netsys initialization is complete"); 36b1b8bc3fSopenharmony_ci return; 37b1b8bc3fSopenharmony_ci } 38b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 39b1b8bc3fSopenharmony_ci netsysService_ = std::make_unique<NetsysControllerServiceImpl>().release(); 40b1b8bc3fSopenharmony_ci netsysService_->Init(); 41b1b8bc3fSopenharmony_ci initFlag_ = true; 42b1b8bc3fSopenharmony_ci} 43b1b8bc3fSopenharmony_ci 44b1b8bc3fSopenharmony_ciNetsysController &NetsysController::GetInstance() 45b1b8bc3fSopenharmony_ci{ 46b1b8bc3fSopenharmony_ci static NetsysController singleInstance_; 47b1b8bc3fSopenharmony_ci static std::mutex mutex_; 48b1b8bc3fSopenharmony_ci if (!singleInstance_.initFlag_) { 49b1b8bc3fSopenharmony_ci std::unique_lock<std::mutex> lock(mutex_); 50b1b8bc3fSopenharmony_ci if (!singleInstance_.initFlag_) { 51b1b8bc3fSopenharmony_ci singleInstance_.Init(); 52b1b8bc3fSopenharmony_ci } 53b1b8bc3fSopenharmony_ci } 54b1b8bc3fSopenharmony_ci return singleInstance_; 55b1b8bc3fSopenharmony_ci} 56b1b8bc3fSopenharmony_ci 57b1b8bc3fSopenharmony_ciint32_t NetsysController::SetInternetPermission(uint32_t uid, uint8_t allow) 58b1b8bc3fSopenharmony_ci{ 59b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 60b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 61b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 62b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 63b1b8bc3fSopenharmony_ci } 64b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 65b1b8bc3fSopenharmony_ci return netsysService_->SetInternetPermission(uid, allow); 66b1b8bc3fSopenharmony_ci} 67b1b8bc3fSopenharmony_ci 68b1b8bc3fSopenharmony_ciint32_t NetsysController::NetworkCreatePhysical(int32_t netId, int32_t permission) 69b1b8bc3fSopenharmony_ci{ 70b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Create Physical network: netId[%{public}d], permission[%{public}d]", netId, permission); 71b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 72b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 73b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 74b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 75b1b8bc3fSopenharmony_ci } 76b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 77b1b8bc3fSopenharmony_ci return netsysService_->NetworkCreatePhysical(netId, permission); 78b1b8bc3fSopenharmony_ci} 79b1b8bc3fSopenharmony_ci 80b1b8bc3fSopenharmony_ciint32_t NetsysController::NetworkCreateVirtual(int32_t netId, bool hasDns) 81b1b8bc3fSopenharmony_ci{ 82b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Create Virtual network: netId[%{public}d], hasDns[%{public}d]", netId, hasDns); 83b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 84b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 85b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 86b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 87b1b8bc3fSopenharmony_ci } 88b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 89b1b8bc3fSopenharmony_ci return netsysService_->NetworkCreateVirtual(netId, hasDns); 90b1b8bc3fSopenharmony_ci} 91b1b8bc3fSopenharmony_ci 92b1b8bc3fSopenharmony_ciint32_t NetsysController::NetworkDestroy(int32_t netId) 93b1b8bc3fSopenharmony_ci{ 94b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Destroy network: netId[%{public}d]", netId); 95b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 96b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 97b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 98b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 99b1b8bc3fSopenharmony_ci } 100b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 101b1b8bc3fSopenharmony_ci return netsysService_->NetworkDestroy(netId); 102b1b8bc3fSopenharmony_ci} 103b1b8bc3fSopenharmony_ci 104b1b8bc3fSopenharmony_ciint32_t NetsysController::CreateVnic(uint16_t mtu, const std::string &tunAddr, int32_t prefix, 105b1b8bc3fSopenharmony_ci const std::set<int32_t> &uids) 106b1b8bc3fSopenharmony_ci{ 107b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Create Vnic network"); 108b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 109b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 110b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 111b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 112b1b8bc3fSopenharmony_ci } 113b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 114b1b8bc3fSopenharmony_ci return netsysService_->CreateVnic(mtu, tunAddr, prefix, uids); 115b1b8bc3fSopenharmony_ci} 116b1b8bc3fSopenharmony_ci 117b1b8bc3fSopenharmony_ciint32_t NetsysController::DestroyVnic() 118b1b8bc3fSopenharmony_ci{ 119b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Destroy Vnic network"); 120b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 121b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 122b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 123b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 124b1b8bc3fSopenharmony_ci } 125b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 126b1b8bc3fSopenharmony_ci return netsysService_->DestroyVnic(); 127b1b8bc3fSopenharmony_ci} 128b1b8bc3fSopenharmony_ci 129b1b8bc3fSopenharmony_ciint32_t NetsysController::EnableDistributedClientNet(const std::string &virnicAddr, const std::string &iif) 130b1b8bc3fSopenharmony_ci{ 131b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 132b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 133b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 134b1b8bc3fSopenharmony_ci } 135b1b8bc3fSopenharmony_ci return netsysService_->EnableDistributedClientNet(virnicAddr, iif); 136b1b8bc3fSopenharmony_ci} 137b1b8bc3fSopenharmony_ci 138b1b8bc3fSopenharmony_ciint32_t NetsysController::EnableDistributedServerNet(const std::string &iif, const std::string &devIface, 139b1b8bc3fSopenharmony_ci const std::string &dstAddr) 140b1b8bc3fSopenharmony_ci{ 141b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 142b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 143b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 144b1b8bc3fSopenharmony_ci } 145b1b8bc3fSopenharmony_ci return netsysService_->EnableDistributedServerNet(iif, devIface, dstAddr); 146b1b8bc3fSopenharmony_ci} 147b1b8bc3fSopenharmony_ci 148b1b8bc3fSopenharmony_ciint32_t NetsysController::DisableDistributedNet(bool isServer) 149b1b8bc3fSopenharmony_ci{ 150b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 151b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 152b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 153b1b8bc3fSopenharmony_ci } 154b1b8bc3fSopenharmony_ci return netsysService_->DisableDistributedNet(isServer); 155b1b8bc3fSopenharmony_ci} 156b1b8bc3fSopenharmony_ci 157b1b8bc3fSopenharmony_ciint32_t NetsysController::NetworkAddUids(int32_t netId, const std::vector<int32_t> &beginUids, 158b1b8bc3fSopenharmony_ci const std::vector<int32_t> &endUids) 159b1b8bc3fSopenharmony_ci{ 160b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Destroy network: netId[%{public}d]", netId); 161b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 162b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 163b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 164b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 165b1b8bc3fSopenharmony_ci } 166b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 167b1b8bc3fSopenharmony_ci if (beginUids.size() != endUids.size()) { 168b1b8bc3fSopenharmony_ci NETMGR_LOG_E("beginUids and endUids size is mismatch"); 169b1b8bc3fSopenharmony_ci return NETMANAGER_ERR_INTERNAL; 170b1b8bc3fSopenharmony_ci } 171b1b8bc3fSopenharmony_ci std::vector<UidRange> uidRanges; 172b1b8bc3fSopenharmony_ci for (size_t i = 0; i < beginUids.size(); i++) { 173b1b8bc3fSopenharmony_ci uidRanges.emplace_back(UidRange(beginUids[i], endUids[i])); 174b1b8bc3fSopenharmony_ci } 175b1b8bc3fSopenharmony_ci return netsysService_->NetworkAddUids(netId, uidRanges); 176b1b8bc3fSopenharmony_ci} 177b1b8bc3fSopenharmony_ci 178b1b8bc3fSopenharmony_ciint32_t NetsysController::NetworkDelUids(int32_t netId, const std::vector<int32_t> &beginUids, 179b1b8bc3fSopenharmony_ci const std::vector<int32_t> &endUids) 180b1b8bc3fSopenharmony_ci{ 181b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Destroy network: netId[%{public}d]", netId); 182b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 183b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 184b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 185b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 186b1b8bc3fSopenharmony_ci } 187b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 188b1b8bc3fSopenharmony_ci if (beginUids.size() != endUids.size()) { 189b1b8bc3fSopenharmony_ci NETMGR_LOG_E("beginUids and endUids size is mismatch"); 190b1b8bc3fSopenharmony_ci return NETMANAGER_ERR_INTERNAL; 191b1b8bc3fSopenharmony_ci } 192b1b8bc3fSopenharmony_ci std::vector<UidRange> uidRanges; 193b1b8bc3fSopenharmony_ci for (size_t i = 0; i < beginUids.size(); i++) { 194b1b8bc3fSopenharmony_ci uidRanges.emplace_back(UidRange(beginUids[i], endUids[i])); 195b1b8bc3fSopenharmony_ci } 196b1b8bc3fSopenharmony_ci return netsysService_->NetworkDelUids(netId, uidRanges); 197b1b8bc3fSopenharmony_ci} 198b1b8bc3fSopenharmony_ci 199b1b8bc3fSopenharmony_ciint32_t NetsysController::NetworkAddInterface(int32_t netId, const std::string &iface, NetBearType netBearerType) 200b1b8bc3fSopenharmony_ci{ 201b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Add network interface: netId[%{public}d], iface[%{public}s, bearerType[%{public}u]]", netId, 202b1b8bc3fSopenharmony_ci iface.c_str(), netBearerType); 203b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 204b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 205b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 206b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 207b1b8bc3fSopenharmony_ci } 208b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 209b1b8bc3fSopenharmony_ci return netsysService_->NetworkAddInterface(netId, iface, netBearerType); 210b1b8bc3fSopenharmony_ci} 211b1b8bc3fSopenharmony_ci 212b1b8bc3fSopenharmony_ciint32_t NetsysController::NetworkRemoveInterface(int32_t netId, const std::string &iface) 213b1b8bc3fSopenharmony_ci{ 214b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Remove network interface: netId[%{public}d], iface[%{public}s]", netId, iface.c_str()); 215b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 216b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 217b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 218b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 219b1b8bc3fSopenharmony_ci } 220b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 221b1b8bc3fSopenharmony_ci return netsysService_->NetworkRemoveInterface(netId, iface); 222b1b8bc3fSopenharmony_ci} 223b1b8bc3fSopenharmony_ci 224b1b8bc3fSopenharmony_ciint32_t NetsysController::NetworkAddRoute(int32_t netId, const std::string &ifName, const std::string &destination, 225b1b8bc3fSopenharmony_ci const std::string &nextHop) 226b1b8bc3fSopenharmony_ci{ 227b1b8bc3fSopenharmony_ci NETMGR_LOG_D("Add Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]", 228b1b8bc3fSopenharmony_ci netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str()); 229b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 230b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 231b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 232b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 233b1b8bc3fSopenharmony_ci } 234b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 235b1b8bc3fSopenharmony_ci return netsysService_->NetworkAddRoute(netId, ifName, destination, nextHop); 236b1b8bc3fSopenharmony_ci} 237b1b8bc3fSopenharmony_ci 238b1b8bc3fSopenharmony_ciint32_t NetsysController::NetworkRemoveRoute(int32_t netId, const std::string &ifName, const std::string &destination, 239b1b8bc3fSopenharmony_ci const std::string &nextHop) 240b1b8bc3fSopenharmony_ci{ 241b1b8bc3fSopenharmony_ci NETMGR_LOG_D("Remove Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]", 242b1b8bc3fSopenharmony_ci netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str()); 243b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 244b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 245b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 246b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 247b1b8bc3fSopenharmony_ci } 248b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 249b1b8bc3fSopenharmony_ci return netsysService_->NetworkRemoveRoute(netId, ifName, destination, nextHop); 250b1b8bc3fSopenharmony_ci} 251b1b8bc3fSopenharmony_ci 252b1b8bc3fSopenharmony_ciint32_t NetsysController::GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel &cfg) 253b1b8bc3fSopenharmony_ci{ 254b1b8bc3fSopenharmony_ci NETMGR_LOG_I("get interface config"); 255b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 256b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 257b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 258b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 259b1b8bc3fSopenharmony_ci } 260b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 261b1b8bc3fSopenharmony_ci return netsysService_->GetInterfaceConfig(cfg); 262b1b8bc3fSopenharmony_ci} 263b1b8bc3fSopenharmony_ci 264b1b8bc3fSopenharmony_ciint32_t NetsysController::SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel &cfg) 265b1b8bc3fSopenharmony_ci{ 266b1b8bc3fSopenharmony_ci NETMGR_LOG_I("set interface config"); 267b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 268b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 269b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 270b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 271b1b8bc3fSopenharmony_ci } 272b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 273b1b8bc3fSopenharmony_ci return netsysService_->SetInterfaceConfig(cfg); 274b1b8bc3fSopenharmony_ci} 275b1b8bc3fSopenharmony_ci 276b1b8bc3fSopenharmony_ciint32_t NetsysController::SetInterfaceDown(const std::string &iface) 277b1b8bc3fSopenharmony_ci{ 278b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Set interface down: iface[%{public}s]", iface.c_str()); 279b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 280b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 281b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 282b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 283b1b8bc3fSopenharmony_ci } 284b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 285b1b8bc3fSopenharmony_ci return netsysService_->SetInterfaceDown(iface); 286b1b8bc3fSopenharmony_ci} 287b1b8bc3fSopenharmony_ci 288b1b8bc3fSopenharmony_ciint32_t NetsysController::SetInterfaceUp(const std::string &iface) 289b1b8bc3fSopenharmony_ci{ 290b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Set interface up: iface[%{public}s]", iface.c_str()); 291b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 292b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 293b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 294b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 295b1b8bc3fSopenharmony_ci } 296b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 297b1b8bc3fSopenharmony_ci return netsysService_->SetInterfaceUp(iface); 298b1b8bc3fSopenharmony_ci} 299b1b8bc3fSopenharmony_ci 300b1b8bc3fSopenharmony_civoid NetsysController::ClearInterfaceAddrs(const std::string &ifName) 301b1b8bc3fSopenharmony_ci{ 302b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Clear addrs: ifName[%{public}s]", ifName.c_str()); 303b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 304b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 305b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 306b1b8bc3fSopenharmony_ci return; 307b1b8bc3fSopenharmony_ci } 308b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 309b1b8bc3fSopenharmony_ci return netsysService_->ClearInterfaceAddrs(ifName); 310b1b8bc3fSopenharmony_ci} 311b1b8bc3fSopenharmony_ci 312b1b8bc3fSopenharmony_ciint32_t NetsysController::GetInterfaceMtu(const std::string &ifName) 313b1b8bc3fSopenharmony_ci{ 314b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Get mtu: ifName[%{public}s]", ifName.c_str()); 315b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 316b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 317b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 318b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 319b1b8bc3fSopenharmony_ci } 320b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 321b1b8bc3fSopenharmony_ci return netsysService_->GetInterfaceMtu(ifName); 322b1b8bc3fSopenharmony_ci} 323b1b8bc3fSopenharmony_ci 324b1b8bc3fSopenharmony_ciint32_t NetsysController::SetInterfaceMtu(const std::string &ifName, int32_t mtu) 325b1b8bc3fSopenharmony_ci{ 326b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Set mtu: ifName[%{public}s], mtu[%{public}d]", ifName.c_str(), mtu); 327b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 328b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 329b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 330b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 331b1b8bc3fSopenharmony_ci } 332b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 333b1b8bc3fSopenharmony_ci return netsysService_->SetInterfaceMtu(ifName, mtu); 334b1b8bc3fSopenharmony_ci} 335b1b8bc3fSopenharmony_ci 336b1b8bc3fSopenharmony_ciint32_t NetsysController::SetTcpBufferSizes(const std::string &tcpBufferSizes) 337b1b8bc3fSopenharmony_ci{ 338b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Set tcp buffer sizes: tcpBufferSizes[%{public}s]", tcpBufferSizes.c_str()); 339b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 340b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 341b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 342b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 343b1b8bc3fSopenharmony_ci } 344b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 345b1b8bc3fSopenharmony_ci return netsysService_->SetTcpBufferSizes(tcpBufferSizes); 346b1b8bc3fSopenharmony_ci} 347b1b8bc3fSopenharmony_ci 348b1b8bc3fSopenharmony_ciint32_t NetsysController::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr, 349b1b8bc3fSopenharmony_ci int32_t prefixLength) 350b1b8bc3fSopenharmony_ci{ 351b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Add address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]", 352b1b8bc3fSopenharmony_ci ifName.c_str(), ToAnonymousIp(ipAddr).c_str(), prefixLength); 353b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 354b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 355b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 356b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 357b1b8bc3fSopenharmony_ci } 358b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 359b1b8bc3fSopenharmony_ci return netsysService_->AddInterfaceAddress(ifName, ipAddr, prefixLength); 360b1b8bc3fSopenharmony_ci} 361b1b8bc3fSopenharmony_ci 362b1b8bc3fSopenharmony_ciint32_t NetsysController::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr, 363b1b8bc3fSopenharmony_ci int32_t prefixLength) 364b1b8bc3fSopenharmony_ci{ 365b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Delete address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]", 366b1b8bc3fSopenharmony_ci ifName.c_str(), ToAnonymousIp(ipAddr).c_str(), prefixLength); 367b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 368b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 369b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 370b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 371b1b8bc3fSopenharmony_ci } 372b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 373b1b8bc3fSopenharmony_ci return netsysService_->DelInterfaceAddress(ifName, ipAddr, prefixLength); 374b1b8bc3fSopenharmony_ci} 375b1b8bc3fSopenharmony_ci 376b1b8bc3fSopenharmony_ciint32_t NetsysController::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr, 377b1b8bc3fSopenharmony_ci int32_t prefixLength, const std::string &netCapabilities) 378b1b8bc3fSopenharmony_ci{ 379b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Delete address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]", 380b1b8bc3fSopenharmony_ci ifName.c_str(), ToAnonymousIp(ipAddr).c_str(), prefixLength); 381b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 382b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 383b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 384b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 385b1b8bc3fSopenharmony_ci } 386b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 387b1b8bc3fSopenharmony_ci return netsysService_->DelInterfaceAddress(ifName, ipAddr, prefixLength, netCapabilities); 388b1b8bc3fSopenharmony_ci} 389b1b8bc3fSopenharmony_ci 390b1b8bc3fSopenharmony_ciint32_t NetsysController::InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress) 391b1b8bc3fSopenharmony_ci{ 392b1b8bc3fSopenharmony_ci NETMGR_LOG_D("Set Ip Address: ifName[%{public}s]", ifaceName.c_str()); 393b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 394b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 395b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 396b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 397b1b8bc3fSopenharmony_ci } 398b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 399b1b8bc3fSopenharmony_ci return netsysService_->InterfaceSetIpAddress(ifaceName, ipAddress); 400b1b8bc3fSopenharmony_ci} 401b1b8bc3fSopenharmony_ci 402b1b8bc3fSopenharmony_ciint32_t NetsysController::InterfaceSetIffUp(const std::string &ifaceName) 403b1b8bc3fSopenharmony_ci{ 404b1b8bc3fSopenharmony_ci NETMGR_LOG_D("Set Iff Up: ifName[%{public}s]", ifaceName.c_str()); 405b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 406b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 407b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 408b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 409b1b8bc3fSopenharmony_ci } 410b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 411b1b8bc3fSopenharmony_ci return netsysService_->InterfaceSetIffUp(ifaceName); 412b1b8bc3fSopenharmony_ci} 413b1b8bc3fSopenharmony_ci 414b1b8bc3fSopenharmony_ciint32_t NetsysController::SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount, 415b1b8bc3fSopenharmony_ci const std::vector<std::string> &servers, 416b1b8bc3fSopenharmony_ci const std::vector<std::string> &domains) 417b1b8bc3fSopenharmony_ci{ 418b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Set resolver config: netId[%{public}d]", netId); 419b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 420b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 421b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 422b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 423b1b8bc3fSopenharmony_ci } 424b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 425b1b8bc3fSopenharmony_ci return netsysService_->SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains); 426b1b8bc3fSopenharmony_ci} 427b1b8bc3fSopenharmony_ci 428b1b8bc3fSopenharmony_ciint32_t NetsysController::GetResolverConfig(uint16_t netId, std::vector<std::string> &servers, 429b1b8bc3fSopenharmony_ci std::vector<std::string> &domains, uint16_t &baseTimeoutMsec, 430b1b8bc3fSopenharmony_ci uint8_t &retryCount) 431b1b8bc3fSopenharmony_ci{ 432b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Get resolver config: netId[%{public}d]", netId); 433b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 434b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 435b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 436b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 437b1b8bc3fSopenharmony_ci } 438b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 439b1b8bc3fSopenharmony_ci return netsysService_->GetResolverConfig(netId, servers, domains, baseTimeoutMsec, retryCount); 440b1b8bc3fSopenharmony_ci} 441b1b8bc3fSopenharmony_ci 442b1b8bc3fSopenharmony_ciint32_t NetsysController::CreateNetworkCache(uint16_t netId) 443b1b8bc3fSopenharmony_ci{ 444b1b8bc3fSopenharmony_ci NETMGR_LOG_I("create dns cache: netId[%{public}d]", netId); 445b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 446b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 447b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 448b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 449b1b8bc3fSopenharmony_ci } 450b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 451b1b8bc3fSopenharmony_ci return netsysService_->CreateNetworkCache(netId); 452b1b8bc3fSopenharmony_ci} 453b1b8bc3fSopenharmony_ci 454b1b8bc3fSopenharmony_ciint32_t NetsysController::DestroyNetworkCache(uint16_t netId) 455b1b8bc3fSopenharmony_ci{ 456b1b8bc3fSopenharmony_ci NETMGR_LOG_I("Destroy dns cache: netId[%{public}d]", netId); 457b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 458b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 459b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 460b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 461b1b8bc3fSopenharmony_ci } 462b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 463b1b8bc3fSopenharmony_ci return netsysService_->DestroyNetworkCache(netId); 464b1b8bc3fSopenharmony_ci} 465b1b8bc3fSopenharmony_ci 466b1b8bc3fSopenharmony_ciint32_t NetsysController::GetAddrInfo(const std::string &hostName, const std::string &serverName, const AddrInfo &hints, 467b1b8bc3fSopenharmony_ci uint16_t netId, std::vector<AddrInfo> &res) 468b1b8bc3fSopenharmony_ci{ 469b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 470b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 471b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 472b1b8bc3fSopenharmony_ci return NET_CONN_ERR_SERVICE_UPDATE_NET_LINK_INFO_FAIL; 473b1b8bc3fSopenharmony_ci } 474b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 475b1b8bc3fSopenharmony_ci return netsysService_->GetAddrInfo(hostName, serverName, hints, netId, res); 476b1b8bc3fSopenharmony_ci} 477b1b8bc3fSopenharmony_ci 478b1b8bc3fSopenharmony_ciint32_t NetsysController::GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface, 479b1b8bc3fSopenharmony_ci nmd::NetworkSharingTraffic &traffic) 480b1b8bc3fSopenharmony_ci{ 481b1b8bc3fSopenharmony_ci NETMGR_LOG_I("NetsysController GetNetworkSharingTraffic"); 482b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 483b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 484b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 485b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 486b1b8bc3fSopenharmony_ci } 487b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 488b1b8bc3fSopenharmony_ci return netsysService_->GetNetworkSharingTraffic(downIface, upIface, traffic); 489b1b8bc3fSopenharmony_ci} 490b1b8bc3fSopenharmony_ci 491b1b8bc3fSopenharmony_ciint64_t NetsysController::GetCellularRxBytes() 492b1b8bc3fSopenharmony_ci{ 493b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetCellularRxBytes"); 494b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 495b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 496b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 497b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 498b1b8bc3fSopenharmony_ci } 499b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 500b1b8bc3fSopenharmony_ci return netsysService_->GetCellularRxBytes(); 501b1b8bc3fSopenharmony_ci} 502b1b8bc3fSopenharmony_ci 503b1b8bc3fSopenharmony_ciint64_t NetsysController::GetCellularTxBytes() 504b1b8bc3fSopenharmony_ci{ 505b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetCellularTxBytes"); 506b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 507b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 508b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 509b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 510b1b8bc3fSopenharmony_ci } 511b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 512b1b8bc3fSopenharmony_ci return netsysService_->GetCellularTxBytes(); 513b1b8bc3fSopenharmony_ci} 514b1b8bc3fSopenharmony_ci 515b1b8bc3fSopenharmony_ciint64_t NetsysController::GetAllRxBytes() 516b1b8bc3fSopenharmony_ci{ 517b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetAllRxBytes"); 518b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 519b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 520b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 521b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 522b1b8bc3fSopenharmony_ci } 523b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 524b1b8bc3fSopenharmony_ci return netsysService_->GetAllRxBytes(); 525b1b8bc3fSopenharmony_ci} 526b1b8bc3fSopenharmony_ci 527b1b8bc3fSopenharmony_ciint64_t NetsysController::GetAllTxBytes() 528b1b8bc3fSopenharmony_ci{ 529b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetAllTxBytes"); 530b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 531b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 532b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 533b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 534b1b8bc3fSopenharmony_ci } 535b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 536b1b8bc3fSopenharmony_ci return netsysService_->GetAllTxBytes(); 537b1b8bc3fSopenharmony_ci} 538b1b8bc3fSopenharmony_ci 539b1b8bc3fSopenharmony_ciint64_t NetsysController::GetUidRxBytes(uint32_t uid) 540b1b8bc3fSopenharmony_ci{ 541b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetUidRxBytes"); 542b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 543b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 544b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 545b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 546b1b8bc3fSopenharmony_ci } 547b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 548b1b8bc3fSopenharmony_ci return netsysService_->GetUidRxBytes(uid); 549b1b8bc3fSopenharmony_ci} 550b1b8bc3fSopenharmony_ci 551b1b8bc3fSopenharmony_ciint64_t NetsysController::GetUidTxBytes(uint32_t uid) 552b1b8bc3fSopenharmony_ci{ 553b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetUidTxBytes"); 554b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 555b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 556b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 557b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 558b1b8bc3fSopenharmony_ci } 559b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 560b1b8bc3fSopenharmony_ci return netsysService_->GetUidTxBytes(uid); 561b1b8bc3fSopenharmony_ci} 562b1b8bc3fSopenharmony_ci 563b1b8bc3fSopenharmony_ciint64_t NetsysController::GetUidOnIfaceRxBytes(uint32_t uid, const std::string &interfaceName) 564b1b8bc3fSopenharmony_ci{ 565b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetUidOnIfaceRxBytes"); 566b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 567b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 568b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 569b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 570b1b8bc3fSopenharmony_ci } 571b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 572b1b8bc3fSopenharmony_ci return netsysService_->GetUidOnIfaceRxBytes(uid, interfaceName); 573b1b8bc3fSopenharmony_ci} 574b1b8bc3fSopenharmony_ci 575b1b8bc3fSopenharmony_ciint64_t NetsysController::GetUidOnIfaceTxBytes(uint32_t uid, const std::string &interfaceName) 576b1b8bc3fSopenharmony_ci{ 577b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetUidOnIfaceTxBytes"); 578b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 579b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 580b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 581b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 582b1b8bc3fSopenharmony_ci } 583b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 584b1b8bc3fSopenharmony_ci return netsysService_->GetUidOnIfaceTxBytes(uid, interfaceName); 585b1b8bc3fSopenharmony_ci} 586b1b8bc3fSopenharmony_ci 587b1b8bc3fSopenharmony_ciint64_t NetsysController::GetIfaceRxBytes(const std::string &interfaceName) 588b1b8bc3fSopenharmony_ci{ 589b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetIfaceRxBytes"); 590b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 591b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 592b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 593b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 594b1b8bc3fSopenharmony_ci } 595b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 596b1b8bc3fSopenharmony_ci return netsysService_->GetIfaceRxBytes(interfaceName); 597b1b8bc3fSopenharmony_ci} 598b1b8bc3fSopenharmony_ci 599b1b8bc3fSopenharmony_ciint64_t NetsysController::GetIfaceTxBytes(const std::string &interfaceName) 600b1b8bc3fSopenharmony_ci{ 601b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetIfaceTxBytes"); 602b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 603b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 604b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 605b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 606b1b8bc3fSopenharmony_ci } 607b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 608b1b8bc3fSopenharmony_ci return netsysService_->GetIfaceTxBytes(interfaceName); 609b1b8bc3fSopenharmony_ci} 610b1b8bc3fSopenharmony_ci 611b1b8bc3fSopenharmony_cistd::vector<std::string> NetsysController::InterfaceGetList() 612b1b8bc3fSopenharmony_ci{ 613b1b8bc3fSopenharmony_ci NETMGR_LOG_I("InterfaceGetList"); 614b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 615b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 616b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 617b1b8bc3fSopenharmony_ci return {}; 618b1b8bc3fSopenharmony_ci } 619b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 620b1b8bc3fSopenharmony_ci return netsysService_->InterfaceGetList(); 621b1b8bc3fSopenharmony_ci} 622b1b8bc3fSopenharmony_ci 623b1b8bc3fSopenharmony_cistd::vector<std::string> NetsysController::UidGetList() 624b1b8bc3fSopenharmony_ci{ 625b1b8bc3fSopenharmony_ci NETMGR_LOG_I("UidGetList"); 626b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 627b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 628b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 629b1b8bc3fSopenharmony_ci return {}; 630b1b8bc3fSopenharmony_ci } 631b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 632b1b8bc3fSopenharmony_ci return netsysService_->UidGetList(); 633b1b8bc3fSopenharmony_ci} 634b1b8bc3fSopenharmony_ci 635b1b8bc3fSopenharmony_ciint64_t NetsysController::GetIfaceRxPackets(const std::string &interfaceName) 636b1b8bc3fSopenharmony_ci{ 637b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetIfaceRxPackets"); 638b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 639b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 640b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 641b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 642b1b8bc3fSopenharmony_ci } 643b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 644b1b8bc3fSopenharmony_ci return netsysService_->GetIfaceRxPackets(interfaceName); 645b1b8bc3fSopenharmony_ci} 646b1b8bc3fSopenharmony_ci 647b1b8bc3fSopenharmony_ciint64_t NetsysController::GetIfaceTxPackets(const std::string &interfaceName) 648b1b8bc3fSopenharmony_ci{ 649b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController GetIfaceTxPackets"); 650b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 651b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 652b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 653b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 654b1b8bc3fSopenharmony_ci } 655b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 656b1b8bc3fSopenharmony_ci return netsysService_->GetIfaceTxPackets(interfaceName); 657b1b8bc3fSopenharmony_ci} 658b1b8bc3fSopenharmony_ci 659b1b8bc3fSopenharmony_ciint32_t NetsysController::SetDefaultNetWork(int32_t netId) 660b1b8bc3fSopenharmony_ci{ 661b1b8bc3fSopenharmony_ci NETMGR_LOG_D("Set DefaultNetWork: netId[%{public}d]", netId); 662b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 663b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 664b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 665b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 666b1b8bc3fSopenharmony_ci } 667b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 668b1b8bc3fSopenharmony_ci return netsysService_->SetDefaultNetWork(netId); 669b1b8bc3fSopenharmony_ci} 670b1b8bc3fSopenharmony_ci 671b1b8bc3fSopenharmony_ciint32_t NetsysController::ClearDefaultNetWorkNetId() 672b1b8bc3fSopenharmony_ci{ 673b1b8bc3fSopenharmony_ci NETMGR_LOG_D("ClearDefaultNetWorkNetId"); 674b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 675b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 676b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 677b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 678b1b8bc3fSopenharmony_ci } 679b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 680b1b8bc3fSopenharmony_ci return netsysService_->ClearDefaultNetWorkNetId(); 681b1b8bc3fSopenharmony_ci} 682b1b8bc3fSopenharmony_ci 683b1b8bc3fSopenharmony_ciint32_t NetsysController::BindSocket(int32_t socketFd, uint32_t netId) 684b1b8bc3fSopenharmony_ci{ 685b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::BindSocket: netId = [%{public}u]", netId); 686b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 687b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 688b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 689b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 690b1b8bc3fSopenharmony_ci } 691b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 692b1b8bc3fSopenharmony_ci return netsysService_->BindSocket(socketFd, netId); 693b1b8bc3fSopenharmony_ci} 694b1b8bc3fSopenharmony_ci 695b1b8bc3fSopenharmony_ciint32_t NetsysController::IpEnableForwarding(const std::string &requestor) 696b1b8bc3fSopenharmony_ci{ 697b1b8bc3fSopenharmony_ci NETMGR_LOG_I("IpEnableForwarding: requestor[%{public}s]", requestor.c_str()); 698b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 699b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 700b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 701b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 702b1b8bc3fSopenharmony_ci } 703b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 704b1b8bc3fSopenharmony_ci return netsysService_->IpEnableForwarding(requestor); 705b1b8bc3fSopenharmony_ci} 706b1b8bc3fSopenharmony_ci 707b1b8bc3fSopenharmony_ciint32_t NetsysController::IpDisableForwarding(const std::string &requestor) 708b1b8bc3fSopenharmony_ci{ 709b1b8bc3fSopenharmony_ci NETMGR_LOG_I("IpDisableForwarding: requestor[%{public}s]", requestor.c_str()); 710b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 711b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 712b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 713b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 714b1b8bc3fSopenharmony_ci } 715b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 716b1b8bc3fSopenharmony_ci return netsysService_->IpDisableForwarding(requestor); 717b1b8bc3fSopenharmony_ci} 718b1b8bc3fSopenharmony_ci 719b1b8bc3fSopenharmony_ciint32_t NetsysController::EnableNat(const std::string &downstreamIface, const std::string &upstreamIface) 720b1b8bc3fSopenharmony_ci{ 721b1b8bc3fSopenharmony_ci NETMGR_LOG_I("EnableNat: intIface[%{public}s] intIface[%{public}s]", downstreamIface.c_str(), 722b1b8bc3fSopenharmony_ci upstreamIface.c_str()); 723b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 724b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 725b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 726b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 727b1b8bc3fSopenharmony_ci } 728b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 729b1b8bc3fSopenharmony_ci return netsysService_->EnableNat(downstreamIface, upstreamIface); 730b1b8bc3fSopenharmony_ci} 731b1b8bc3fSopenharmony_ci 732b1b8bc3fSopenharmony_ciint32_t NetsysController::DisableNat(const std::string &downstreamIface, const std::string &upstreamIface) 733b1b8bc3fSopenharmony_ci{ 734b1b8bc3fSopenharmony_ci NETMGR_LOG_I("DisableNat: intIface[%{public}s] intIface[%{public}s]", 735b1b8bc3fSopenharmony_ci downstreamIface.c_str(), upstreamIface.c_str()); 736b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 737b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 738b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 739b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 740b1b8bc3fSopenharmony_ci } 741b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 742b1b8bc3fSopenharmony_ci return netsysService_->DisableNat(downstreamIface, upstreamIface); 743b1b8bc3fSopenharmony_ci} 744b1b8bc3fSopenharmony_ci 745b1b8bc3fSopenharmony_ciint32_t NetsysController::IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface) 746b1b8bc3fSopenharmony_ci{ 747b1b8bc3fSopenharmony_ci NETMGR_LOG_I("IpfwdAddInterfaceForward: fromIface[%{public}s], toIface[%{public}s]", fromIface.c_str(), 748b1b8bc3fSopenharmony_ci toIface.c_str()); 749b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 750b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 751b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 752b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 753b1b8bc3fSopenharmony_ci } 754b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 755b1b8bc3fSopenharmony_ci return netsysService_->IpfwdAddInterfaceForward(fromIface, toIface); 756b1b8bc3fSopenharmony_ci} 757b1b8bc3fSopenharmony_ci 758b1b8bc3fSopenharmony_ciint32_t NetsysController::IpfwdRemoveInterfaceForward(const std::string &fromIface, const std::string &toIface) 759b1b8bc3fSopenharmony_ci{ 760b1b8bc3fSopenharmony_ci NETMGR_LOG_I("IpfwdRemoveInterfaceForward: fromIface[%{public}s], toIface[%{public}s]", fromIface.c_str(), 761b1b8bc3fSopenharmony_ci toIface.c_str()); 762b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 763b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 764b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 765b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 766b1b8bc3fSopenharmony_ci } 767b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 768b1b8bc3fSopenharmony_ci return netsysService_->IpfwdRemoveInterfaceForward(fromIface, toIface); 769b1b8bc3fSopenharmony_ci} 770b1b8bc3fSopenharmony_ci 771b1b8bc3fSopenharmony_ciint32_t NetsysController::ShareDnsSet(uint16_t netId) 772b1b8bc3fSopenharmony_ci{ 773b1b8bc3fSopenharmony_ci NETMGR_LOG_I("ShareDnsSet: netId[%{public}d]", netId); 774b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 775b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 776b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 777b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 778b1b8bc3fSopenharmony_ci } 779b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 780b1b8bc3fSopenharmony_ci return netsysService_->ShareDnsSet(netId); 781b1b8bc3fSopenharmony_ci} 782b1b8bc3fSopenharmony_ci 783b1b8bc3fSopenharmony_ciint32_t NetsysController::StartDnsProxyListen() 784b1b8bc3fSopenharmony_ci{ 785b1b8bc3fSopenharmony_ci NETMGR_LOG_I("StartDnsProxyListen"); 786b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 787b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 788b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 789b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 790b1b8bc3fSopenharmony_ci } 791b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 792b1b8bc3fSopenharmony_ci return netsysService_->StartDnsProxyListen(); 793b1b8bc3fSopenharmony_ci} 794b1b8bc3fSopenharmony_ci 795b1b8bc3fSopenharmony_ciint32_t NetsysController::StopDnsProxyListen() 796b1b8bc3fSopenharmony_ci{ 797b1b8bc3fSopenharmony_ci NETMGR_LOG_I("StopDnsProxyListen"); 798b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 799b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 800b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 801b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 802b1b8bc3fSopenharmony_ci } 803b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 804b1b8bc3fSopenharmony_ci return netsysService_->StopDnsProxyListen(); 805b1b8bc3fSopenharmony_ci} 806b1b8bc3fSopenharmony_ci 807b1b8bc3fSopenharmony_ciint32_t NetsysController::RegisterNetsysNotifyCallback(const NetsysNotifyCallback &callback) 808b1b8bc3fSopenharmony_ci{ 809b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 810b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 811b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 812b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 813b1b8bc3fSopenharmony_ci } 814b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 815b1b8bc3fSopenharmony_ci return netsysService_->RegisterNetsysNotifyCallback(callback); 816b1b8bc3fSopenharmony_ci} 817b1b8bc3fSopenharmony_ci 818b1b8bc3fSopenharmony_ciint32_t NetsysController::BindNetworkServiceVpn(int32_t socketFd) 819b1b8bc3fSopenharmony_ci{ 820b1b8bc3fSopenharmony_ci NETMGR_LOG_I("BindNetworkServiceVpn: socketFd[%{public}d]", socketFd); 821b1b8bc3fSopenharmony_ci if (socketFd <= 0) { 822b1b8bc3fSopenharmony_ci NETMGR_LOG_E("socketFd is null"); 823b1b8bc3fSopenharmony_ci return NETSYS_ERR_VPN; 824b1b8bc3fSopenharmony_ci } 825b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 826b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 827b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 828b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 829b1b8bc3fSopenharmony_ci } 830b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 831b1b8bc3fSopenharmony_ci return netsysService_->BindNetworkServiceVpn(socketFd); 832b1b8bc3fSopenharmony_ci} 833b1b8bc3fSopenharmony_ci 834b1b8bc3fSopenharmony_ciint32_t NetsysController::EnableVirtualNetIfaceCard(int32_t socketFd, struct ifreq &ifRequest, int32_t &ifaceFd) 835b1b8bc3fSopenharmony_ci{ 836b1b8bc3fSopenharmony_ci NETMGR_LOG_I("EnableVirtualNetIfaceCard: socketFd[%{public}d]", socketFd); 837b1b8bc3fSopenharmony_ci if (socketFd <= 0) { 838b1b8bc3fSopenharmony_ci NETMGR_LOG_E("socketFd is null"); 839b1b8bc3fSopenharmony_ci return NETSYS_ERR_VPN; 840b1b8bc3fSopenharmony_ci } 841b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 842b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 843b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 844b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 845b1b8bc3fSopenharmony_ci } 846b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 847b1b8bc3fSopenharmony_ci return netsysService_->EnableVirtualNetIfaceCard(socketFd, ifRequest, ifaceFd); 848b1b8bc3fSopenharmony_ci} 849b1b8bc3fSopenharmony_ci 850b1b8bc3fSopenharmony_ciint32_t NetsysController::SetIpAddress(int32_t socketFd, const std::string &ipAddress, int32_t prefixLen, 851b1b8bc3fSopenharmony_ci struct ifreq &ifRequest) 852b1b8bc3fSopenharmony_ci{ 853b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::set addr"); 854b1b8bc3fSopenharmony_ci if ((socketFd <= 0) || (ipAddress.length() == 0) || (static_cast<uint32_t>(ipAddress.length()) > IPV4_MAX_LENGTH) || 855b1b8bc3fSopenharmony_ci (prefixLen <= 0) || (static_cast<uint32_t>(prefixLen) > IPV4_MAX_LENGTH)) { 856b1b8bc3fSopenharmony_ci NETMGR_LOG_E( 857b1b8bc3fSopenharmony_ci "The paramemters of SetIpAddress is failed, socketFd[%{public}d], " 858b1b8bc3fSopenharmony_ci "ipAddress[%{public}s], prefixLen[%{public}d].", 859b1b8bc3fSopenharmony_ci socketFd, ToAnonymousIp(ipAddress).c_str(), prefixLen); 860b1b8bc3fSopenharmony_ci return NETSYS_ERR_VPN; 861b1b8bc3fSopenharmony_ci } 862b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 863b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 864b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 865b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 866b1b8bc3fSopenharmony_ci } 867b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 868b1b8bc3fSopenharmony_ci return netsysService_->SetIpAddress(socketFd, ipAddress, prefixLen, ifRequest); 869b1b8bc3fSopenharmony_ci} 870b1b8bc3fSopenharmony_ci 871b1b8bc3fSopenharmony_ciint32_t NetsysController::SetBlocking(int32_t ifaceFd, bool isBlock) 872b1b8bc3fSopenharmony_ci{ 873b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::SetBlocking: ifaceFd[%{public}d], isBlock[%{public}d]", ifaceFd, isBlock); 874b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 875b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 876b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 877b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 878b1b8bc3fSopenharmony_ci } 879b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 880b1b8bc3fSopenharmony_ci return netsysService_->SetBlocking(ifaceFd, isBlock); 881b1b8bc3fSopenharmony_ci} 882b1b8bc3fSopenharmony_ci 883b1b8bc3fSopenharmony_ciint32_t NetsysController::StartDhcpClient(const std::string &iface, bool bIpv6) 884b1b8bc3fSopenharmony_ci{ 885b1b8bc3fSopenharmony_ci NETMGR_LOG_I("StartDhcpClient: iface[%{public}s], bIpv6[%{public}d]", iface.c_str(), bIpv6); 886b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 887b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 888b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 889b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 890b1b8bc3fSopenharmony_ci } 891b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 892b1b8bc3fSopenharmony_ci return netsysService_->StartDhcpClient(iface, bIpv6); 893b1b8bc3fSopenharmony_ci} 894b1b8bc3fSopenharmony_ci 895b1b8bc3fSopenharmony_ciint32_t NetsysController::StopDhcpClient(const std::string &iface, bool bIpv6) 896b1b8bc3fSopenharmony_ci{ 897b1b8bc3fSopenharmony_ci NETMGR_LOG_I("StopDhcpClient: iface[%{public}s], bIpv6[%{public}d]", iface.c_str(), bIpv6); 898b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 899b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 900b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 901b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 902b1b8bc3fSopenharmony_ci } 903b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 904b1b8bc3fSopenharmony_ci return netsysService_->StopDhcpClient(iface, bIpv6); 905b1b8bc3fSopenharmony_ci} 906b1b8bc3fSopenharmony_ci 907b1b8bc3fSopenharmony_ciint32_t NetsysController::RegisterCallback(sptr<NetsysControllerCallback> callback) 908b1b8bc3fSopenharmony_ci{ 909b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::RegisterCallback"); 910b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 911b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 912b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 913b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 914b1b8bc3fSopenharmony_ci } 915b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 916b1b8bc3fSopenharmony_ci return netsysService_->RegisterCallback(callback); 917b1b8bc3fSopenharmony_ci} 918b1b8bc3fSopenharmony_ci 919b1b8bc3fSopenharmony_ciint32_t NetsysController::StartDhcpService(const std::string &iface, const std::string &ipv4addr) 920b1b8bc3fSopenharmony_ci{ 921b1b8bc3fSopenharmony_ci NETMGR_LOG_I("StartDhcpService: iface[%{public}s], ipv4addr[%{public}s]", 922b1b8bc3fSopenharmony_ci iface.c_str(), ToAnonymousIp(ipv4addr).c_str()); 923b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 924b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 925b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 926b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 927b1b8bc3fSopenharmony_ci } 928b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 929b1b8bc3fSopenharmony_ci return netsysService_->StartDhcpService(iface, ipv4addr); 930b1b8bc3fSopenharmony_ci} 931b1b8bc3fSopenharmony_ci 932b1b8bc3fSopenharmony_ciint32_t NetsysController::StopDhcpService(const std::string &iface) 933b1b8bc3fSopenharmony_ci{ 934b1b8bc3fSopenharmony_ci NETMGR_LOG_I("StopDhcpService: ifaceFd[%{public}s]", iface.c_str()); 935b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 936b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 937b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 938b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 939b1b8bc3fSopenharmony_ci } 940b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 941b1b8bc3fSopenharmony_ci return netsysService_->StopDhcpService(iface); 942b1b8bc3fSopenharmony_ci} 943b1b8bc3fSopenharmony_ci 944b1b8bc3fSopenharmony_ciint32_t NetsysController::BandwidthEnableDataSaver(bool enable) 945b1b8bc3fSopenharmony_ci{ 946b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::BandwidthEnableDataSaver: enable=%{public}d", enable); 947b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 948b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 949b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 950b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 951b1b8bc3fSopenharmony_ci } 952b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 953b1b8bc3fSopenharmony_ci return netsysService_->BandwidthEnableDataSaver(enable); 954b1b8bc3fSopenharmony_ci} 955b1b8bc3fSopenharmony_ci 956b1b8bc3fSopenharmony_ciint32_t NetsysController::BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes) 957b1b8bc3fSopenharmony_ci{ 958b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::BandwidthSetIfaceQuota: ifName=%{public}s", ifName.c_str()); 959b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 960b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 961b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 962b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 963b1b8bc3fSopenharmony_ci } 964b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 965b1b8bc3fSopenharmony_ci return netsysService_->BandwidthSetIfaceQuota(ifName, bytes); 966b1b8bc3fSopenharmony_ci} 967b1b8bc3fSopenharmony_ci 968b1b8bc3fSopenharmony_ciint32_t NetsysController::BandwidthRemoveIfaceQuota(const std::string &ifName) 969b1b8bc3fSopenharmony_ci{ 970b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::BandwidthRemoveIfaceQuota: ifName=%{public}s", ifName.c_str()); 971b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 972b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 973b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 974b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 975b1b8bc3fSopenharmony_ci } 976b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 977b1b8bc3fSopenharmony_ci return netsysService_->BandwidthRemoveIfaceQuota(ifName); 978b1b8bc3fSopenharmony_ci} 979b1b8bc3fSopenharmony_ci 980b1b8bc3fSopenharmony_ciint32_t NetsysController::BandwidthAddDeniedList(uint32_t uid) 981b1b8bc3fSopenharmony_ci{ 982b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::BandwidthAddDeniedList: uid=%{public}d", uid); 983b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 984b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 985b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 986b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 987b1b8bc3fSopenharmony_ci } 988b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 989b1b8bc3fSopenharmony_ci return netsysService_->BandwidthAddDeniedList(uid); 990b1b8bc3fSopenharmony_ci} 991b1b8bc3fSopenharmony_ci 992b1b8bc3fSopenharmony_ciint32_t NetsysController::BandwidthRemoveDeniedList(uint32_t uid) 993b1b8bc3fSopenharmony_ci{ 994b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::BandwidthRemoveDeniedList: uid=%{public}d", uid); 995b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 996b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 997b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 998b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 999b1b8bc3fSopenharmony_ci } 1000b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1001b1b8bc3fSopenharmony_ci return netsysService_->BandwidthRemoveDeniedList(uid); 1002b1b8bc3fSopenharmony_ci} 1003b1b8bc3fSopenharmony_ci 1004b1b8bc3fSopenharmony_ciint32_t NetsysController::BandwidthAddAllowedList(uint32_t uid) 1005b1b8bc3fSopenharmony_ci{ 1006b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::BandwidthAddAllowedList: uid=%{public}d", uid); 1007b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1008b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1009b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1010b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1011b1b8bc3fSopenharmony_ci } 1012b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1013b1b8bc3fSopenharmony_ci return netsysService_->BandwidthAddAllowedList(uid); 1014b1b8bc3fSopenharmony_ci} 1015b1b8bc3fSopenharmony_ci 1016b1b8bc3fSopenharmony_ciint32_t NetsysController::BandwidthRemoveAllowedList(uint32_t uid) 1017b1b8bc3fSopenharmony_ci{ 1018b1b8bc3fSopenharmony_ci NETMGR_LOG_D("NetsysController::BandwidthRemoveAllowedList: uid=%{public}d", uid); 1019b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1020b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1021b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1022b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1023b1b8bc3fSopenharmony_ci } 1024b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1025b1b8bc3fSopenharmony_ci return netsysService_->BandwidthRemoveAllowedList(uid); 1026b1b8bc3fSopenharmony_ci} 1027b1b8bc3fSopenharmony_ci 1028b1b8bc3fSopenharmony_ciint32_t NetsysController::FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids) 1029b1b8bc3fSopenharmony_ci{ 1030b1b8bc3fSopenharmony_ci NETMGR_LOG_I("NetsysController::FirewallSetUidsAllowedListChain: chain=%{public}d", chain); 1031b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1032b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1033b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1034b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1035b1b8bc3fSopenharmony_ci } 1036b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1037b1b8bc3fSopenharmony_ci return netsysService_->FirewallSetUidsAllowedListChain(chain, uids); 1038b1b8bc3fSopenharmony_ci} 1039b1b8bc3fSopenharmony_ci 1040b1b8bc3fSopenharmony_ciint32_t NetsysController::FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids) 1041b1b8bc3fSopenharmony_ci{ 1042b1b8bc3fSopenharmony_ci NETMGR_LOG_I("NetsysController::FirewallSetUidsDeniedListChain: chain=%{public}d", chain); 1043b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1044b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1045b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1046b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1047b1b8bc3fSopenharmony_ci } 1048b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1049b1b8bc3fSopenharmony_ci return netsysService_->FirewallSetUidsDeniedListChain(chain, uids); 1050b1b8bc3fSopenharmony_ci} 1051b1b8bc3fSopenharmony_ci 1052b1b8bc3fSopenharmony_ciint32_t NetsysController::FirewallEnableChain(uint32_t chain, bool enable) 1053b1b8bc3fSopenharmony_ci{ 1054b1b8bc3fSopenharmony_ci NETMGR_LOG_I("NetsysController::FirewallEnableChain: chain=%{public}d, enable=%{public}d", chain, enable); 1055b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1056b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1057b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1058b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1059b1b8bc3fSopenharmony_ci } 1060b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1061b1b8bc3fSopenharmony_ci return netsysService_->FirewallEnableChain(chain, enable); 1062b1b8bc3fSopenharmony_ci} 1063b1b8bc3fSopenharmony_ci 1064b1b8bc3fSopenharmony_ciint32_t NetsysController::FirewallSetUidRule(uint32_t chain, const std::vector<uint32_t> &uids, uint32_t firewallRule) 1065b1b8bc3fSopenharmony_ci{ 1066b1b8bc3fSopenharmony_ci NETMGR_LOG_I("NetsysController::FirewallSetUidRule Start"); 1067b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1068b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1069b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1070b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1071b1b8bc3fSopenharmony_ci } 1072b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1073b1b8bc3fSopenharmony_ci return netsysService_->FirewallSetUidRule(chain, uids, firewallRule); 1074b1b8bc3fSopenharmony_ci} 1075b1b8bc3fSopenharmony_ci 1076b1b8bc3fSopenharmony_civoid NetsysController::FreeAddrInfo(addrinfo *aihead) 1077b1b8bc3fSopenharmony_ci{ 1078b1b8bc3fSopenharmony_ci addrinfo *tmpNext = nullptr; 1079b1b8bc3fSopenharmony_ci for (addrinfo *tmp = aihead; tmp != nullptr;) { 1080b1b8bc3fSopenharmony_ci if (tmp->ai_addr != nullptr) { 1081b1b8bc3fSopenharmony_ci free(tmp->ai_addr); 1082b1b8bc3fSopenharmony_ci } 1083b1b8bc3fSopenharmony_ci if (tmp->ai_canonname != nullptr) { 1084b1b8bc3fSopenharmony_ci free(tmp->ai_canonname); 1085b1b8bc3fSopenharmony_ci } 1086b1b8bc3fSopenharmony_ci tmpNext = tmp->ai_next; 1087b1b8bc3fSopenharmony_ci free(tmp); 1088b1b8bc3fSopenharmony_ci tmp = tmpNext; 1089b1b8bc3fSopenharmony_ci } 1090b1b8bc3fSopenharmony_ci} 1091b1b8bc3fSopenharmony_ci 1092b1b8bc3fSopenharmony_ciint32_t NetsysController::GetTotalStats(uint64_t &stats, uint32_t type) 1093b1b8bc3fSopenharmony_ci{ 1094b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1095b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1096b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1097b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1098b1b8bc3fSopenharmony_ci } 1099b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1100b1b8bc3fSopenharmony_ci return netsysService_->GetTotalStats(stats, static_cast<uint32_t>(type)); 1101b1b8bc3fSopenharmony_ci} 1102b1b8bc3fSopenharmony_ci 1103b1b8bc3fSopenharmony_ciint32_t NetsysController::GetUidStats(uint64_t &stats, uint32_t type, uint32_t uid) 1104b1b8bc3fSopenharmony_ci{ 1105b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1106b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1107b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1108b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1109b1b8bc3fSopenharmony_ci } 1110b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1111b1b8bc3fSopenharmony_ci return netsysService_->GetUidStats(stats, static_cast<uint32_t>(type), uid); 1112b1b8bc3fSopenharmony_ci} 1113b1b8bc3fSopenharmony_ci 1114b1b8bc3fSopenharmony_ciint32_t NetsysController::GetIfaceStats(uint64_t &stats, uint32_t type, const std::string &interfaceName) 1115b1b8bc3fSopenharmony_ci{ 1116b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1117b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1118b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1119b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1120b1b8bc3fSopenharmony_ci } 1121b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1122b1b8bc3fSopenharmony_ci return netsysService_->GetIfaceStats(stats, static_cast<uint32_t>(type), interfaceName); 1123b1b8bc3fSopenharmony_ci} 1124b1b8bc3fSopenharmony_ci 1125b1b8bc3fSopenharmony_ciint32_t NetsysController::GetAllSimStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats) 1126b1b8bc3fSopenharmony_ci{ 1127b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1128b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1129b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1130b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1131b1b8bc3fSopenharmony_ci } 1132b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1133b1b8bc3fSopenharmony_ci return netsysService_->GetAllSimStatsInfo(stats); 1134b1b8bc3fSopenharmony_ci} 1135b1b8bc3fSopenharmony_ci 1136b1b8bc3fSopenharmony_ciint32_t NetsysController::DeleteSimStatsInfo(uint32_t uid) 1137b1b8bc3fSopenharmony_ci{ 1138b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1139b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1140b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1141b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1142b1b8bc3fSopenharmony_ci } 1143b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1144b1b8bc3fSopenharmony_ci return netsysService_->DeleteSimStatsInfo(uid); 1145b1b8bc3fSopenharmony_ci} 1146b1b8bc3fSopenharmony_ci 1147b1b8bc3fSopenharmony_ciint32_t NetsysController::GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats) 1148b1b8bc3fSopenharmony_ci{ 1149b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1150b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1151b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1152b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1153b1b8bc3fSopenharmony_ci } 1154b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1155b1b8bc3fSopenharmony_ci return netsysService_->GetAllStatsInfo(stats); 1156b1b8bc3fSopenharmony_ci} 1157b1b8bc3fSopenharmony_ci 1158b1b8bc3fSopenharmony_ciint32_t NetsysController::DeleteStatsInfo(uint32_t uid) 1159b1b8bc3fSopenharmony_ci{ 1160b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1161b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1162b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1163b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1164b1b8bc3fSopenharmony_ci } 1165b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1166b1b8bc3fSopenharmony_ci return netsysService_->DeleteStatsInfo(uid); 1167b1b8bc3fSopenharmony_ci} 1168b1b8bc3fSopenharmony_ci 1169b1b8bc3fSopenharmony_ciint32_t NetsysController::SetIptablesCommandForRes(const std::string &cmd, std::string &respond, 1170b1b8bc3fSopenharmony_ci NetsysNative::IptablesType ipType) 1171b1b8bc3fSopenharmony_ci{ 1172b1b8bc3fSopenharmony_ci if (cmd.empty()) { 1173b1b8bc3fSopenharmony_ci NETMGR_LOG_E("SetIptablesCommandForRes cmd is empty"); 1174b1b8bc3fSopenharmony_ci return ERR_INVALID_DATA; 1175b1b8bc3fSopenharmony_ci } 1176b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1177b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1178b1b8bc3fSopenharmony_ci NETMGR_LOG_E("SetIptablesCommandForRes netsysService is null"); 1179b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1180b1b8bc3fSopenharmony_ci } 1181b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1182b1b8bc3fSopenharmony_ci NETMGR_LOG_I("SetIptablesCommandForRes, iptables is %{public}d.", ipType); 1183b1b8bc3fSopenharmony_ci return netsysService_->SetIptablesCommandForRes(cmd, respond, ipType); 1184b1b8bc3fSopenharmony_ci} 1185b1b8bc3fSopenharmony_ci 1186b1b8bc3fSopenharmony_ciint32_t NetsysController::NetDiagPingHost(const OHOS::NetsysNative::NetDiagPingOption &pingOption, 1187b1b8bc3fSopenharmony_ci const sptr<OHOS::NetsysNative::INetDiagCallback> &callback) 1188b1b8bc3fSopenharmony_ci{ 1189b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1190b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1191b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1192b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1193b1b8bc3fSopenharmony_ci } 1194b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1195b1b8bc3fSopenharmony_ci return netsysService_->NetDiagPingHost(pingOption, callback); 1196b1b8bc3fSopenharmony_ci} 1197b1b8bc3fSopenharmony_ci 1198b1b8bc3fSopenharmony_ciint32_t NetsysController::NetDiagGetRouteTable(std::list<OHOS::NetsysNative::NetDiagRouteTable> &routeTables) 1199b1b8bc3fSopenharmony_ci{ 1200b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1201b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1202b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1203b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1204b1b8bc3fSopenharmony_ci } 1205b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1206b1b8bc3fSopenharmony_ci return netsysService_->NetDiagGetRouteTable(routeTables); 1207b1b8bc3fSopenharmony_ci} 1208b1b8bc3fSopenharmony_ci 1209b1b8bc3fSopenharmony_ciint32_t NetsysController::NetDiagGetSocketsInfo(OHOS::NetsysNative::NetDiagProtocolType socketType, 1210b1b8bc3fSopenharmony_ci OHOS::NetsysNative::NetDiagSocketsInfo &socketsInfo) 1211b1b8bc3fSopenharmony_ci{ 1212b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1213b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1214b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1215b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1216b1b8bc3fSopenharmony_ci } 1217b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1218b1b8bc3fSopenharmony_ci return netsysService_->NetDiagGetSocketsInfo(socketType, socketsInfo); 1219b1b8bc3fSopenharmony_ci} 1220b1b8bc3fSopenharmony_ci 1221b1b8bc3fSopenharmony_ciint32_t NetsysController::NetDiagGetInterfaceConfig(std::list<OHOS::NetsysNative::NetDiagIfaceConfig> &configs, 1222b1b8bc3fSopenharmony_ci const std::string &ifaceName) 1223b1b8bc3fSopenharmony_ci{ 1224b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1225b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1226b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1227b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1228b1b8bc3fSopenharmony_ci } 1229b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1230b1b8bc3fSopenharmony_ci return netsysService_->NetDiagGetInterfaceConfig(configs, ifaceName); 1231b1b8bc3fSopenharmony_ci} 1232b1b8bc3fSopenharmony_ci 1233b1b8bc3fSopenharmony_ciint32_t NetsysController::NetDiagUpdateInterfaceConfig(const OHOS::NetsysNative::NetDiagIfaceConfig &config, 1234b1b8bc3fSopenharmony_ci const std::string &ifaceName, bool add) 1235b1b8bc3fSopenharmony_ci{ 1236b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1237b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1238b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1239b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1240b1b8bc3fSopenharmony_ci } 1241b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1242b1b8bc3fSopenharmony_ci return netsysService_->NetDiagUpdateInterfaceConfig(config, ifaceName, add); 1243b1b8bc3fSopenharmony_ci} 1244b1b8bc3fSopenharmony_ci 1245b1b8bc3fSopenharmony_ciint32_t NetsysController::NetDiagSetInterfaceActiveState(const std::string &ifaceName, bool up) 1246b1b8bc3fSopenharmony_ci{ 1247b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1248b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1249b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1250b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1251b1b8bc3fSopenharmony_ci } 1252b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1253b1b8bc3fSopenharmony_ci return netsysService_->NetDiagSetInterfaceActiveState(ifaceName, up); 1254b1b8bc3fSopenharmony_ci} 1255b1b8bc3fSopenharmony_ci 1256b1b8bc3fSopenharmony_ciint32_t NetsysController::AddStaticArp(const std::string &ipAddr, const std::string &macAddr, 1257b1b8bc3fSopenharmony_ci const std::string &ifName) 1258b1b8bc3fSopenharmony_ci{ 1259b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1260b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1261b1b8bc3fSopenharmony_ci NETMGR_LOG_E("AddStaticArp netsysService is null"); 1262b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1263b1b8bc3fSopenharmony_ci } 1264b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1265b1b8bc3fSopenharmony_ci return netsysService_->AddStaticArp(ipAddr, macAddr, ifName); 1266b1b8bc3fSopenharmony_ci} 1267b1b8bc3fSopenharmony_ci 1268b1b8bc3fSopenharmony_ciint32_t NetsysController::DelStaticArp(const std::string &ipAddr, const std::string &macAddr, 1269b1b8bc3fSopenharmony_ci const std::string &ifName) 1270b1b8bc3fSopenharmony_ci{ 1271b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1272b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1273b1b8bc3fSopenharmony_ci NETMGR_LOG_E("DelStaticArp netsysService is null"); 1274b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1275b1b8bc3fSopenharmony_ci } 1276b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1277b1b8bc3fSopenharmony_ci return netsysService_->DelStaticArp(ipAddr, macAddr, ifName); 1278b1b8bc3fSopenharmony_ci} 1279b1b8bc3fSopenharmony_ci 1280b1b8bc3fSopenharmony_ciint32_t NetsysController::RegisterDnsResultCallback( 1281b1b8bc3fSopenharmony_ci const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback, uint32_t timeStep) 1282b1b8bc3fSopenharmony_ci{ 1283b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1284b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1285b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1286b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1287b1b8bc3fSopenharmony_ci } 1288b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1289b1b8bc3fSopenharmony_ci return netsysService_->RegisterDnsResultCallback(callback, timeStep); 1290b1b8bc3fSopenharmony_ci} 1291b1b8bc3fSopenharmony_ci 1292b1b8bc3fSopenharmony_ciint32_t NetsysController::UnregisterDnsResultCallback( 1293b1b8bc3fSopenharmony_ci const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback) 1294b1b8bc3fSopenharmony_ci{ 1295b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1296b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1297b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1298b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1299b1b8bc3fSopenharmony_ci } 1300b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1301b1b8bc3fSopenharmony_ci return netsysService_->UnregisterDnsResultCallback(callback); 1302b1b8bc3fSopenharmony_ci} 1303b1b8bc3fSopenharmony_ci 1304b1b8bc3fSopenharmony_ciint32_t NetsysController::RegisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> &callback) 1305b1b8bc3fSopenharmony_ci{ 1306b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1307b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1308b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1309b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1310b1b8bc3fSopenharmony_ci } 1311b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1312b1b8bc3fSopenharmony_ci return netsysService_->RegisterDnsHealthCallback(callback); 1313b1b8bc3fSopenharmony_ci} 1314b1b8bc3fSopenharmony_ci 1315b1b8bc3fSopenharmony_ciint32_t NetsysController::UnregisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> &callback) 1316b1b8bc3fSopenharmony_ci{ 1317b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1318b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1319b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1320b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1321b1b8bc3fSopenharmony_ci } 1322b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1323b1b8bc3fSopenharmony_ci return netsysService_->UnregisterDnsHealthCallback(callback); 1324b1b8bc3fSopenharmony_ci} 1325b1b8bc3fSopenharmony_ci 1326b1b8bc3fSopenharmony_ciint32_t NetsysController::GetCookieStats(uint64_t &stats, uint32_t type, uint64_t cookie) 1327b1b8bc3fSopenharmony_ci{ 1328b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1329b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1330b1b8bc3fSopenharmony_ci NETMGR_LOG_E("GetCookieStats netsysService is null"); 1331b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1332b1b8bc3fSopenharmony_ci } 1333b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1334b1b8bc3fSopenharmony_ci return netsysService_->GetCookieStats(stats, type, cookie); 1335b1b8bc3fSopenharmony_ci} 1336b1b8bc3fSopenharmony_ci 1337b1b8bc3fSopenharmony_ciint32_t NetsysController::GetNetworkSharingType(std::set<uint32_t>& sharingTypeIsOn) 1338b1b8bc3fSopenharmony_ci{ 1339b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1340b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1341b1b8bc3fSopenharmony_ci NETMGR_LOG_E("GetNetworkSharingType netsysService is null"); 1342b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1343b1b8bc3fSopenharmony_ci } 1344b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1345b1b8bc3fSopenharmony_ci return netsysService_->GetNetworkSharingType(sharingTypeIsOn); 1346b1b8bc3fSopenharmony_ci} 1347b1b8bc3fSopenharmony_ci 1348b1b8bc3fSopenharmony_ciint32_t NetsysController::UpdateNetworkSharingType(uint32_t type, bool isOpen) 1349b1b8bc3fSopenharmony_ci{ 1350b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1351b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1352b1b8bc3fSopenharmony_ci NETMGR_LOG_E("UpdateNetworkSharingType netsysService is null"); 1353b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1354b1b8bc3fSopenharmony_ci } 1355b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1356b1b8bc3fSopenharmony_ci return netsysService_->UpdateNetworkSharingType(type, isOpen); 1357b1b8bc3fSopenharmony_ci} 1358b1b8bc3fSopenharmony_ci 1359b1b8bc3fSopenharmony_ci#ifdef FEATURE_NET_FIREWALL_ENABLE 1360b1b8bc3fSopenharmony_ciint32_t NetsysController::SetFirewallRules(NetFirewallRuleType type, 1361b1b8bc3fSopenharmony_ci const std::vector<sptr<NetFirewallBaseRule>> &ruleList, bool isFinish) 1362b1b8bc3fSopenharmony_ci{ 1363b1b8bc3fSopenharmony_ci NETMGR_LOG_I("NetsysController::SetFirewallRules"); 1364b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1365b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1366b1b8bc3fSopenharmony_ci NETMGR_LOG_E("SetFirewallRules netsysService is null"); 1367b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1368b1b8bc3fSopenharmony_ci } 1369b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1370b1b8bc3fSopenharmony_ci return netsysService_->SetFirewallRules(type, ruleList, isFinish); 1371b1b8bc3fSopenharmony_ci} 1372b1b8bc3fSopenharmony_ci 1373b1b8bc3fSopenharmony_ciint32_t NetsysController::SetFirewallDefaultAction(FirewallRuleAction inDefault, FirewallRuleAction outDefault) 1374b1b8bc3fSopenharmony_ci{ 1375b1b8bc3fSopenharmony_ci NETMGR_LOG_I("NetsysController::SetFirewallDefaultAction"); 1376b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1377b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1378b1b8bc3fSopenharmony_ci NETMGR_LOG_E("SetFirewallDefaultAction netsysService is null"); 1379b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1380b1b8bc3fSopenharmony_ci } 1381b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1382b1b8bc3fSopenharmony_ci return netsysService_->SetFirewallDefaultAction(inDefault, outDefault); 1383b1b8bc3fSopenharmony_ci} 1384b1b8bc3fSopenharmony_ci 1385b1b8bc3fSopenharmony_ciint32_t NetsysController::SetFirewallCurrentUserId(int32_t userId) 1386b1b8bc3fSopenharmony_ci{ 1387b1b8bc3fSopenharmony_ci NETMGR_LOG_I("NetsysController::SetFirewallCurrentUserId"); 1388b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1389b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1390b1b8bc3fSopenharmony_ci NETMGR_LOG_E("SetFirewallCurrentUserId netsysService is null"); 1391b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1392b1b8bc3fSopenharmony_ci } 1393b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1394b1b8bc3fSopenharmony_ci return netsysService_->SetFirewallCurrentUserId(userId); 1395b1b8bc3fSopenharmony_ci} 1396b1b8bc3fSopenharmony_ci 1397b1b8bc3fSopenharmony_ciint32_t NetsysController::ClearFirewallRules(NetFirewallRuleType type) 1398b1b8bc3fSopenharmony_ci{ 1399b1b8bc3fSopenharmony_ci NETMGR_LOG_I("NetsysController::ClearFirewallRules"); 1400b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1401b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1402b1b8bc3fSopenharmony_ci NETMGR_LOG_E("ClearFirewallRules netsysService is null"); 1403b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1404b1b8bc3fSopenharmony_ci } 1405b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1406b1b8bc3fSopenharmony_ci return netsysService_->ClearFirewallRules(type); 1407b1b8bc3fSopenharmony_ci} 1408b1b8bc3fSopenharmony_ci 1409b1b8bc3fSopenharmony_ciint32_t NetsysController::RegisterNetFirewallCallback(const sptr<NetsysNative::INetFirewallCallback> &callback) 1410b1b8bc3fSopenharmony_ci{ 1411b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1412b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1413b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1414b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1415b1b8bc3fSopenharmony_ci } 1416b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1417b1b8bc3fSopenharmony_ci return netsysService_->RegisterNetFirewallCallback(callback); 1418b1b8bc3fSopenharmony_ci} 1419b1b8bc3fSopenharmony_ci 1420b1b8bc3fSopenharmony_ciint32_t NetsysController::UnRegisterNetFirewallCallback(const sptr<NetsysNative::INetFirewallCallback> &callback) 1421b1b8bc3fSopenharmony_ci{ 1422b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1423b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1424b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService is null"); 1425b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1426b1b8bc3fSopenharmony_ci } 1427b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1428b1b8bc3fSopenharmony_ci return netsysService_->UnRegisterNetFirewallCallback(callback); 1429b1b8bc3fSopenharmony_ci} 1430b1b8bc3fSopenharmony_ci#endif 1431b1b8bc3fSopenharmony_ci 1432b1b8bc3fSopenharmony_ci#ifdef FEATURE_WEARABLE_DISTRIBUTED_NET_ENABLE 1433b1b8bc3fSopenharmony_ciint32_t NetsysController::EnableWearableDistributedNetForward(const int32_t tcpPortId, const int32_t udpPortId) 1434b1b8bc3fSopenharmony_ci{ 1435b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1436b1b8bc3fSopenharmony_ci NETMGR_LOG_E("NetsysService is null in EnableWearableDistributedNetForward"); 1437b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1438b1b8bc3fSopenharmony_ci } 1439b1b8bc3fSopenharmony_ci return netsysService_->EnableWearableDistributedNetForward(tcpPortId, udpPortId); 1440b1b8bc3fSopenharmony_ci} 1441b1b8bc3fSopenharmony_ci 1442b1b8bc3fSopenharmony_ciint32_t NetsysController::DisableWearableDistributedNetForward() 1443b1b8bc3fSopenharmony_ci{ 1444b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1445b1b8bc3fSopenharmony_ci NETMGR_LOG_E("NetsysService is null in DisableWearableDistributedNetForward"); 1446b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1447b1b8bc3fSopenharmony_ci } 1448b1b8bc3fSopenharmony_ci return netsysService_->DisableWearableDistributedNetForward(); 1449b1b8bc3fSopenharmony_ci} 1450b1b8bc3fSopenharmony_ci#endif 1451b1b8bc3fSopenharmony_ci 1452b1b8bc3fSopenharmony_ciint32_t NetsysController::SetIpv6PrivacyExtensions(const std::string &interfaceName, const uint32_t on) 1453b1b8bc3fSopenharmony_ci{ 1454b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1455b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1456b1b8bc3fSopenharmony_ci NETMGR_LOG_E("SetIpv6PrivacyExtensions netsysService is null"); 1457b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1458b1b8bc3fSopenharmony_ci } 1459b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1460b1b8bc3fSopenharmony_ci return netsysService_->SetIpv6PrivacyExtensions(interfaceName, on); 1461b1b8bc3fSopenharmony_ci} 1462b1b8bc3fSopenharmony_ci 1463b1b8bc3fSopenharmony_ciint32_t NetsysController::SetEnableIpv6(const std::string &interfaceName, const uint32_t on) 1464b1b8bc3fSopenharmony_ci{ 1465b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1466b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1467b1b8bc3fSopenharmony_ci NETMGR_LOG_E("SetEnableIpv6 netsysService is null"); 1468b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1469b1b8bc3fSopenharmony_ci } 1470b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1471b1b8bc3fSopenharmony_ci return netsysService_->SetEnableIpv6(interfaceName, on); 1472b1b8bc3fSopenharmony_ci} 1473b1b8bc3fSopenharmony_ci 1474b1b8bc3fSopenharmony_ciint32_t NetsysController::SetNetworkAccessPolicy(uint32_t uid, NetworkAccessPolicy policy, bool reconfirmFlag, 1475b1b8bc3fSopenharmony_ci bool isBroker) 1476b1b8bc3fSopenharmony_ci{ 1477b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1478b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1479b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1480b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1481b1b8bc3fSopenharmony_ci } 1482b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1483b1b8bc3fSopenharmony_ci return netsysService_->SetNetworkAccessPolicy(uid, policy, reconfirmFlag, isBroker); 1484b1b8bc3fSopenharmony_ci} 1485b1b8bc3fSopenharmony_ci 1486b1b8bc3fSopenharmony_ciint32_t NetsysController::NotifyNetBearerTypeChange(std::set<NetBearType> bearerTypes) 1487b1b8bc3fSopenharmony_ci{ 1488b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1489b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1490b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1491b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1492b1b8bc3fSopenharmony_ci } 1493b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1494b1b8bc3fSopenharmony_ci return netsysService_->NotifyNetBearerTypeChange(bearerTypes); 1495b1b8bc3fSopenharmony_ci} 1496b1b8bc3fSopenharmony_ci 1497b1b8bc3fSopenharmony_ciint32_t NetsysController::DeleteNetworkAccessPolicy(uint32_t uid) 1498b1b8bc3fSopenharmony_ci{ 1499b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1500b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1501b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1502b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1503b1b8bc3fSopenharmony_ci } 1504b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1505b1b8bc3fSopenharmony_ci return netsysService_->DeleteNetworkAccessPolicy(uid); 1506b1b8bc3fSopenharmony_ci} 1507b1b8bc3fSopenharmony_ci 1508b1b8bc3fSopenharmony_ciint32_t NetsysController::ClearFirewallAllRules() 1509b1b8bc3fSopenharmony_ci{ 1510b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1511b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1512b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1513b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1514b1b8bc3fSopenharmony_ci } 1515b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1516b1b8bc3fSopenharmony_ci return netsysService_->ClearFirewallAllRules(); 1517b1b8bc3fSopenharmony_ci} 1518b1b8bc3fSopenharmony_ci 1519b1b8bc3fSopenharmony_ciint32_t NetsysController::StartClat(const std::string &interfaceName, int32_t netId, const std::string &nat64PrefixStr) 1520b1b8bc3fSopenharmony_ci{ 1521b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1522b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1523b1b8bc3fSopenharmony_ci NETMGR_LOG_E("StartClat netsysService is null"); 1524b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1525b1b8bc3fSopenharmony_ci } 1526b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1527b1b8bc3fSopenharmony_ci return netsysService_->StartClat(interfaceName, netId, nat64PrefixStr); 1528b1b8bc3fSopenharmony_ci} 1529b1b8bc3fSopenharmony_ci 1530b1b8bc3fSopenharmony_ciint32_t NetsysController::StopClat(const std::string &interfaceName) 1531b1b8bc3fSopenharmony_ci{ 1532b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1533b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1534b1b8bc3fSopenharmony_ci NETMGR_LOG_E("StopClat netsysService is null"); 1535b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1536b1b8bc3fSopenharmony_ci } 1537b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1538b1b8bc3fSopenharmony_ci return netsysService_->StopClat(interfaceName); 1539b1b8bc3fSopenharmony_ci} 1540b1b8bc3fSopenharmony_ci 1541b1b8bc3fSopenharmony_ciint32_t NetsysController::SetNicTrafficAllowed(const std::vector<std::string> &ifaceNames, bool status) 1542b1b8bc3fSopenharmony_ci{ 1543b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1544b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1545b1b8bc3fSopenharmony_ci NETMGR_LOG_E("SetNicTrafficAllowed netsysService is null"); 1546b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1547b1b8bc3fSopenharmony_ci } 1548b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1549b1b8bc3fSopenharmony_ci return netsysService_->SetNicTrafficAllowed(ifaceNames, status); 1550b1b8bc3fSopenharmony_ci} 1551b1b8bc3fSopenharmony_ci 1552b1b8bc3fSopenharmony_ci#ifdef SUPPORT_SYSVPN 1553b1b8bc3fSopenharmony_ciint32_t NetsysController::ProcessVpnStage(NetsysNative::SysVpnStageCode stage) 1554b1b8bc3fSopenharmony_ci{ 1555b1b8bc3fSopenharmony_ci // LCOV_EXCL_START This will never happen. 1556b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1557b1b8bc3fSopenharmony_ci NETMGR_LOG_E("ProcessVpnStage netsysService is null"); 1558b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1559b1b8bc3fSopenharmony_ci } 1560b1b8bc3fSopenharmony_ci // LCOV_EXCL_STOP 1561b1b8bc3fSopenharmony_ci return netsysService_->ProcessVpnStage(stage); 1562b1b8bc3fSopenharmony_ci} 1563b1b8bc3fSopenharmony_ci#endif // SUPPORT_SYSVPN 1564b1b8bc3fSopenharmony_ci 1565b1b8bc3fSopenharmony_ciint32_t NetsysController::CloseSocketsUid(const std::string &ipAddr, uint32_t uid) 1566b1b8bc3fSopenharmony_ci{ 1567b1b8bc3fSopenharmony_ci NETMGR_LOG_D("Set CloseSocketsUid: uid[%{public}d]", uid); 1568b1b8bc3fSopenharmony_ci if (netsysService_ == nullptr) { 1569b1b8bc3fSopenharmony_ci NETMGR_LOG_E("netsysService_ is null"); 1570b1b8bc3fSopenharmony_ci return NETSYS_NETSYSSERVICE_NULL; 1571b1b8bc3fSopenharmony_ci } 1572b1b8bc3fSopenharmony_ci return netsysService_->CloseSocketsUid(ipAddr, uid); 1573b1b8bc3fSopenharmony_ci} 1574b1b8bc3fSopenharmony_ci} // namespace NetManagerStandard 1575b1b8bc3fSopenharmony_ci} // namespace OHOS 1576