From c0c1b8f7c668076f80fb87781ed9a649d1495734 Mon Sep 17 00:00:00 2001 From: l00635678 Date: Wed, 9 Oct 2024 09:12:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E6=9C=BA=E6=8F=92=E5=85=A5sim?= =?UTF-8?q?=E5=8D=A1=E8=BF=9E=E6=8E=A5=E8=9C=82=E7=AA=9D=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=EF=BC=8Ckill=E6=8E=89netsysnative=E8=BF=9B=E7=A8=8B=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E8=83=BD=E8=AE=BF=E9=97=AEipv6=E7=BD=91?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l00635678 --- .../netconnmanager/include/net_conn_service.h | 1 - .../include/net_conn_service_iface.h | 1 - services/netconnmanager/include/network.h | 2 +- .../netconnmanager/src/net_conn_service.cpp | 17 ------------- .../src/net_conn_service_iface.cpp | 4 --- services/netconnmanager/src/network.cpp | 25 ++++++++----------- .../net_conn_service_test.cpp | 5 ---- 7 files changed, 11 insertions(+), 44 deletions(-) diff --git a/services/netconnmanager/include/net_conn_service.h b/services/netconnmanager/include/net_conn_service.h index 24d8b98f5..1d67d1ab5 100644 --- a/services/netconnmanager/include/net_conn_service.h +++ b/services/netconnmanager/include/net_conn_service.h @@ -356,7 +356,6 @@ public: int32_t IsPreferCellularUrl(const std::string& url, bool& preferCellular) override; int32_t RegisterPreAirplaneCallback(const sptr callback) override; int32_t UnregisterPreAirplaneCallback(const sptr callback) override; - bool IsAddrInOtherNetwork(const std::string &ifaceName, int32_t netId, const INetAddr &netAddr); bool IsIfaceNameInUse(const std::string &ifaceName, int32_t netId); int32_t UpdateSupplierScore(NetBearType bearerType, uint32_t detectionStatus, uint32_t& supplierId) override; std::string GetNetCapabilitiesAsString(const uint32_t supplierId); diff --git a/services/netconnmanager/include/net_conn_service_iface.h b/services/netconnmanager/include/net_conn_service_iface.h index 03f5ebb38..bc6133aad 100644 --- a/services/netconnmanager/include/net_conn_service_iface.h +++ b/services/netconnmanager/include/net_conn_service_iface.h @@ -42,7 +42,6 @@ public: int32_t RestrictBackgroundChanged(bool isRestrictBackground) override; int32_t RegisterNetConnCallback(const sptr &callback) override; int32_t RegisterNetFactoryResetCallback(const sptr &callback) override; - bool IsAddrInOtherNetwork(const std::string &ifaceName, int32_t netId, const INetAddr &netAddr); bool IsIfaceNameInUse(const std::string &ifaceName, int32_t netId); std::string GetNetCapabilitiesAsString(const uint32_t supplierId) const; }; diff --git a/services/netconnmanager/include/network.h b/services/netconnmanager/include/network.h index 6df3bbd78..d4d3e7324 100644 --- a/services/netconnmanager/include/network.h +++ b/services/netconnmanager/include/network.h @@ -88,7 +88,6 @@ private: void ResetNetlinkInfo(); bool IsDetectionForDnsSuccess(NetDetectionStatus netDetectionState, bool dnsHealthSuccess); bool IsDetectionForDnsFail(NetDetectionStatus netDetectionState, bool dnsHealthSuccess); - bool IsAddrInOtherNetwork(const INetAddr &netAddr); bool IsIfaceNameInUse(); bool IsNat464Prefered(); std::string GetNetCapabilitiesAsString(const uint32_t supplierId) const; @@ -112,6 +111,7 @@ private: #ifdef FEATURE_SUPPORT_POWERMANAGER bool forbidDetectionFlag_ = false; #endif + bool isNeedResume_ = false; }; } // namespace NetManagerStandard } // namespace OHOS diff --git a/services/netconnmanager/src/net_conn_service.cpp b/services/netconnmanager/src/net_conn_service.cpp index 6ee1bd2b9..7d6c418d2 100644 --- a/services/netconnmanager/src/net_conn_service.cpp +++ b/services/netconnmanager/src/net_conn_service.cpp @@ -2531,23 +2531,6 @@ int32_t NetConnService::IsPreferCellularUrl(const std::string& url, bool& prefer return 0; } -bool NetConnService::IsAddrInOtherNetwork(const std::string &ifaceName, int32_t netId, const INetAddr &netAddr) -{ - std::lock_guard locker(netManagerMutex_); - for (const auto &network : networks_) { - if (network.second->GetNetId() == netId) { - continue; - } - if (network.second->GetIfaceName() != ifaceName) { - continue; - } - if (network.second->GetNetLinkInfo().HasNetAddr(netAddr)) { - return true; - } - } - return false; -} - bool NetConnService::IsIfaceNameInUse(const std::string &ifaceName, int32_t netId) { std::lock_guard locker(netManagerMutex_); diff --git a/services/netconnmanager/src/net_conn_service_iface.cpp b/services/netconnmanager/src/net_conn_service_iface.cpp index df5fe7c7f..4623768e7 100644 --- a/services/netconnmanager/src/net_conn_service_iface.cpp +++ b/services/netconnmanager/src/net_conn_service_iface.cpp @@ -92,10 +92,6 @@ int32_t NetConnServiceIface::RegisterNetFactoryResetCallback(const sptrRegisterNetFactoryResetCallback(callback); } -bool NetConnServiceIface::IsAddrInOtherNetwork(const std::string &ifaceName, int32_t netId, const INetAddr &netAddr) -{ - return NetConnService::GetInstance()->IsAddrInOtherNetwork(ifaceName, netId, netAddr); -} bool NetConnServiceIface::IsIfaceNameInUse(const std::string &ifaceName, int32_t netId) { return NetConnService::GetInstance()->IsIfaceNameInUse(ifaceName, netId); diff --git a/services/netconnmanager/src/network.cpp b/services/netconnmanager/src/network.cpp index 06fba5089..ffaa6933f 100644 --- a/services/netconnmanager/src/network.cpp +++ b/services/netconnmanager/src/network.cpp @@ -130,11 +130,6 @@ bool Network::CreateVirtualNetwork() return true; } -bool Network::IsAddrInOtherNetwork(const INetAddr &netAddr) -{ - return NetConnServiceIface().IsAddrInOtherNetwork(netLinkInfo_.ifaceName_, netId_, netAddr); -} - bool Network::IsIfaceNameInUse() { return NetConnServiceIface().IsIfaceNameInUse(netLinkInfo_.ifaceName_, netId_); @@ -156,7 +151,7 @@ bool Network::ReleaseBasicNetwork() std::string netCapabilities = GetNetCapabilitiesAsString(supplierId_); NETMGR_LOG_D("ReleaseBasicNetwork supplierId %{public}u, netId %{public}d, netCapabilities %{public}s", supplierId_, netId_, netCapabilities.c_str()); - if (!IsIfaceNameInUse()) { + if (!IsIfaceNameInUse() || isNeedResume_) { for (const auto &inetAddr : netLinkInfo_.netAddrList_) { int32_t prefixLen = inetAddr.prefixlen_ == 0 ? Ipv4PrefixLen(inetAddr.netMask_) : inetAddr.prefixlen_; NetsysController::GetInstance().DelInterfaceAddress(netLinkInfo_.ifaceName_, inetAddr.address_, @@ -173,6 +168,7 @@ bool Network::ReleaseBasicNetwork() NetsysController::GetInstance().NetworkRemoveRoute(LOCAL_NET_ID, route.iface_, destAddress, nextHop); } } + isNeedResume_ = false; } else { for (const auto &inetAddr : netLinkInfo_.netAddrList_) { int32_t prefixLen = inetAddr.prefixlen_ == 0 ? Ipv4PrefixLen(inetAddr.netMask_) : inetAddr.prefixlen_; @@ -213,8 +209,11 @@ bool Network::UpdateNetLinkInfo(const NetLinkInfo &netLinkInfo) NETMGR_LOG_D("update net link information process"); UpdateStatsCached(netLinkInfo); UpdateInterfaces(netLinkInfo); - UpdateIpAddrs(netLinkInfo); - UpdateRoutes(netLinkInfo); + bool isIfaceNameInUse = NetConnServiceIface().IsIfaceNameInUse(netLinkInfo.ifaceName_, netId_); + if (!isIfaceNameInUse || netCaps_.find(NetCap::NET_CAPABILITY_INTERNET) != netCaps_.end()) { + UpdateIpAddrs(netLinkInfo); + UpdateRoutes(netLinkInfo); + } UpdateDns(netLinkInfo); UpdateMtu(netLinkInfo); UpdateTcpBufferSize(netLinkInfo); @@ -292,9 +291,6 @@ void Network::UpdateIpAddrs(const NetLinkInfo &newNetLinkInfo) // Update: remove old Ips first, then add the new Ips NETMGR_LOG_I("UpdateIpAddrs, old ip addrs size: [%{public}zu]", netLinkInfo_.netAddrList_.size()); for (const auto &inetAddr : netLinkInfo_.netAddrList_) { - if (IsAddrInOtherNetwork(inetAddr)) { - continue; - } if (newNetLinkInfo.HasNetAddr(inetAddr)) { NETMGR_LOG_W("Same ip address:[%{public}s], there is not need to be deleted", CommonUtils::ToAnonymousIp(inetAddr.address_).c_str()); @@ -332,9 +328,6 @@ void Network::HandleUpdateIpAddrs(const NetLinkInfo &newNetLinkInfo) { NETMGR_LOG_I("HandleUpdateIpAddrs, new ip addrs size: [%{public}zu]", newNetLinkInfo.netAddrList_.size()); for (const auto &inetAddr : newNetLinkInfo.netAddrList_) { - if (IsAddrInOtherNetwork(inetAddr)) { - continue; - } if (netLinkInfo_.HasNetAddr(inetAddr)) { NETMGR_LOG_W("Same ip address:[%{public}s], there is no need to add it again", CommonUtils::ToAnonymousIp(inetAddr.address_).c_str()); @@ -736,7 +729,9 @@ void Network::OnHandleNetMonitorResult(NetDetectionStatus netDetectionState, con bool Network::ResumeNetworkInfo() { NetLinkInfo nli = netLinkInfo_; - + if (netCaps_.find(NetCap::NET_CAPABILITY_INTERNET) != netCaps_.end()) { + isNeedResume_ = true; + } NETMGR_LOG_D("ResumeNetworkInfo UpdateBasicNetwork false"); if (!UpdateBasicNetwork(false)) { NETMGR_LOG_E("%s release existed basic network failed", __FUNCTION__); diff --git a/test/netconnmanager/unittest/net_conn_manager_test/net_conn_service_test.cpp b/test/netconnmanager/unittest/net_conn_manager_test/net_conn_service_test.cpp index 5fe82f594..f4355b3d9 100644 --- a/test/netconnmanager/unittest/net_conn_manager_test/net_conn_service_test.cpp +++ b/test/netconnmanager/unittest/net_conn_manager_test/net_conn_service_test.cpp @@ -273,11 +273,6 @@ HWTEST_F(NetConnServiceTest, UpdateNetLinkInfoTest002, TestSize.Level1) EXPECT_FALSE(ret); ret = NetConnService::GetInstance()->IsIfaceNameInUse("rmnet0", 100); EXPECT_FALSE(ret); - - ret = NetConnService::GetInstance()->IsAddrInOtherNetwork("rmnet0", 1, netAddr); - EXPECT_FALSE(ret); - ret = NetConnService::GetInstance()->IsAddrInOtherNetwork("rmnet0", 100, netAddr); - EXPECT_TRUE(ret); } HWTEST_F(NetConnServiceTest, RequestNetConnectionTest001, TestSize.Level1) -- Gitee