From 22e98178c6e04fdd57a45baaece699c4f151c0e0 Mon Sep 17 00:00:00 2001 From: weiyingjie <1283462359@qq.com> Date: Mon, 27 Mar 2023 18:21:06 +0800 Subject: [PATCH] 1. Fix the issue where there is a chance of assigning the same IP when allocating IPs for simultaneous requests. 2. Optimizing the calculation method for converting IP ranges into the actual number of IP addresses. --- controller/EmbeddedNetworkController.cpp | 3 ++- controller/EmbeddedNetworkController.hpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index 2ccc16b8c..8826dde57 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -1235,6 +1235,7 @@ void EmbeddedNetworkController::_request( const Identity &identity, const Dictionary &metaData) { + std::lock_guard l(_request_l); char nwids[24]; DB::NetworkSummaryInfo ns; json network,member; @@ -1736,7 +1737,7 @@ void EmbeddedNetworkController::_request( if ((ipRangeEnd < ipRangeStart)||(ipRangeStart == 0)) continue; - uint32_t ipRangeLen = ipRangeEnd - ipRangeStart; + uint32_t ipRangeLen = ipRangeEnd - ipRangeStart + 1; // Start with the LSB of the member's address uint32_t ipTrialCounter = (uint32_t)(identity.address().toInt() & 0xffffffff); diff --git a/controller/EmbeddedNetworkController.hpp b/controller/EmbeddedNetworkController.hpp index bc95acb58..930eef511 100644 --- a/controller/EmbeddedNetworkController.hpp +++ b/controller/EmbeddedNetworkController.hpp @@ -160,6 +160,8 @@ private: RedisConfig *_rc; std::string _ssoRedirectURL; + + std::mutex _request_l; }; } // namespace ZeroTier