]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4258] Experiment with relocate
authorFrancis Dupont <fdupont@isc.org>
Sat, 13 Dec 2025 00:19:09 +0000 (01:19 +0100)
committerRazvan Becheriu <razvan@isc.org>
Tue, 14 Apr 2026 12:35:24 +0000 (15:35 +0300)
src/lib/dhcp/iface_mgr.cc
src/lib/dhcp/iface_mgr.h

index 5a1298603d8ccb96f2bd3b5414358dbab388ee01..983efb859f7e353cb01bf95dffac89105d3ea407 100644 (file)
@@ -414,6 +414,16 @@ IfaceMgr::deleteAllExternalSockets() {
     callbacks_.clear();
 }
 
+std::list<int>
+IfaceMgr::getAllExternalSockets() {
+    std::list<int> result;
+    std::lock_guard<std::mutex> lock(callbacks_mutex_);
+    for (SocketCallbackInfo const& s : callbacks_) {
+        result.push_back(s.socket_);
+    }
+    return (result);
+}
+
 void
 IfaceMgr::setPacketFilter(const PktFilterPtr& packet_filter) {
     // Do not allow null pointer.
@@ -1269,6 +1279,7 @@ Pkt4Ptr IfaceMgr::receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec /
         boost::scoped_ptr<SocketCallbackInfo> ex_sock;
         bool found = false;
         {
+            std::list<SocketCallbackInfoIterator> to_reloc;
             std::lock_guard<std::mutex> lock(callbacks_mutex_);
             for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
                 if (it->unusable_) {
@@ -1278,6 +1289,7 @@ Pkt4Ptr IfaceMgr::receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec /
                 if (fd_event_handler_->readReady(it->socket_) ||
                     fd_event_handler_->hasError(it->socket_)) {
                     found = true;
+                    to_reloc.push_back(it);
 
                     // something received over external socket
                     if (it->callback_) {
@@ -1288,6 +1300,11 @@ Pkt4Ptr IfaceMgr::receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec /
                     }
                 }
             }
+            if (found) {
+                for (auto it : to_reloc) {
+                    callbacks_.relocate(callbacks_.end(), it);
+                }
+            }
         }
 
         if (ex_sock && ex_sock->callback_) {
@@ -1379,6 +1396,7 @@ Pkt4Ptr IfaceMgr::receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec /*
     boost::scoped_ptr<SocketCallbackInfo> ex_sock;
     bool found = false;
     {
+        std::list<SocketCallbackInfoIterator> to_reloc;
         std::lock_guard<std::mutex> lock(callbacks_mutex_);
         for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
             if (it->unusable_) {
@@ -1388,6 +1406,7 @@ Pkt4Ptr IfaceMgr::receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec /*
             if (fd_event_handler_->readReady(it->socket_) ||
                 fd_event_handler_->hasError(it->socket_)) {
                 found = true;
+                to_reloc.push_back(it);
 
                 // something received over external socket
                 if (it->callback_) {
@@ -1398,6 +1417,11 @@ Pkt4Ptr IfaceMgr::receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec /*
                 }
             }
         }
+        if (found) {
+            for (auto it : to_reloc) {
+                callbacks_.relocate(callbacks_.end(), it);
+            }
+        }
     }
 
     if (ex_sock && ex_sock->callback_) {
@@ -1529,6 +1553,7 @@ IfaceMgr::receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ )
     boost::scoped_ptr<SocketCallbackInfo> ex_sock;
     bool found = false;
     {
+        std::list<SocketCallbackInfoIterator> to_reloc;
         std::lock_guard<std::mutex> lock(callbacks_mutex_);
         for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
             if (it->unusable_) {
@@ -1538,6 +1563,7 @@ IfaceMgr::receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ )
             if (fd_event_handler_->readReady(it->socket_) ||
                 fd_event_handler_->hasError(it->socket_)) {
                 found = true;
+                to_reloc.push_back(it);
 
                 // something received over external socket
                 if (it->callback_) {
@@ -1548,6 +1574,11 @@ IfaceMgr::receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ )
                 }
             }
         }
+        if (found) {
+            for (auto it : to_reloc) {
+                callbacks_.relocate(callbacks_.end(), it);
+            }
+        }
     }
 
     if (ex_sock && ex_sock->callback_) {
@@ -1682,6 +1713,7 @@ IfaceMgr::receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
         boost::scoped_ptr<SocketCallbackInfo> ex_sock;
         bool found = false;
         {
+            std::list<SocketCallbackInfoIterator> to_reloc;
             std::lock_guard<std::mutex> lock(callbacks_mutex_);
             for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
                 if (it->unusable_) {
@@ -1691,6 +1723,7 @@ IfaceMgr::receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
                 if (fd_event_handler_->readReady(it->socket_) ||
                     fd_event_handler_->hasError(it->socket_)) {
                     found = true;
+                    to_reloc.push_back(it);
 
                     // something received over external socket
                     if (it->callback_) {
@@ -1701,6 +1734,11 @@ IfaceMgr::receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
                     }
                 }
             }
+            if (found) {
+                for (auto it : to_reloc) {
+                    callbacks_.relocate(callbacks_.end(), it);
+                }
+            }
         }
 
         if (ex_sock && ex_sock->callback_) {
index f28be0c628edd49fe60e43de04847afb72802ee4..f66715e2bde0454b5354fff20c20ea5bca22287c 100644 (file)
@@ -1275,6 +1275,11 @@ public:
     /// by the external API.
     void deleteAllExternalSockets();
 
+    /// @brief Get the list of external sockets.
+    ///
+    /// @return The list of external sockets.
+    std::list<int> getAllExternalSockets();
+
     /// @brief Set packet filter object to handle sending and receiving DHCPv4
     /// messages.
     ///