]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4248] add log messages
authorRazvan Becheriu <razvan@isc.org>
Mon, 8 Dec 2025 16:36:38 +0000 (18:36 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 9 Dec 2025 22:15:38 +0000 (23:15 +0100)
config-report.sh.in
src/lib/dhcp/dhcp_log.h
src/lib/dhcp/dhcp_messages.cc
src/lib/dhcp/dhcp_messages.h
src/lib/dhcp/dhcp_messages.mes
src/lib/dhcp/iface_mgr.cc

index 9b13c6f57874a066fd7d822c703685e73f4be9f5..a7ead344ec4625e9efd7652a26c2afd64f72b2ca 100755 (executable)
@@ -57,8 +57,8 @@ HERE_DOCUMENT
 
 add_to_report <<HERE_DOCUMENT
 IO Event Handling:
-  select            yes
-  poll              yes
+  select              yes
+  poll                yes
 
 HERE_DOCUMENT
 
index b4f9032ba8fda877a16081cc8266031284852084..948f01a6917cfafc17f0d747258af1819be35d2c 100644 (file)
@@ -13,7 +13,7 @@
 namespace isc {
 namespace dhcp {
 
-/// \brief DHCP library Logger
+/// @brief DHCP library Logger
 ///
 /// Define the logger used to log messages.  We could define it in multiple
 /// modules, but defining in a single module and linking to it saves time and
index 3180325449d7ed6d4fa4598d402492290507fbb0..7f6014e4e6a2e1c92222061d207016d83c1eb588 100644 (file)
@@ -7,6 +7,9 @@
 namespace isc {
 namespace dhcp {
 
+extern const isc::log::MessageID DHCP_ADD_EXTERNAL_SOCKET = "DHCP_ADD_EXTERNAL_SOCKET";
+extern const isc::log::MessageID DHCP_DELETE_ALL_EXTERNAL_SOCKETS = "DHCP_DELETE_ALL_EXTERNAL_SOCKETS";
+extern const isc::log::MessageID DHCP_DELETE_EXTERNAL_SOCKET = "DHCP_DELETE_EXTERNAL_SOCKET";
 
 } // namespace dhcp
 } // namespace isc
@@ -14,6 +17,9 @@ namespace dhcp {
 namespace {
 
 const char* values[] = {
+    "DHCP_ADD_EXTERNAL_SOCKET", "Attempted to register external socket %1 from different thread %2",
+    "DHCP_DELETE_ALL_EXTERNAL_SOCKETS", "Attempted to unregister external sockets from different thread %1",
+    "DHCP_DELETE_EXTERNAL_SOCKET", "Attempted to unregister external socket %1 from different thread %2",
     NULL
 };
 
index a320114820d87d96cec553c128945497ec2af333..931a2c28c3083f7be1158a50cf0cbc5d059df427 100644 (file)
@@ -8,6 +8,9 @@
 namespace isc {
 namespace dhcp {
 
+extern const isc::log::MessageID DHCP_ADD_EXTERNAL_SOCKET;
+extern const isc::log::MessageID DHCP_DELETE_ALL_EXTERNAL_SOCKETS;
+extern const isc::log::MessageID DHCP_DELETE_EXTERNAL_SOCKET;
 
 } // namespace dhcp
 } // namespace isc
index 19b6e6bd8f0dc071cf354d3159f4478e7b9bedc8..44c90424cfce1ccefc9f979988f15a85f415690d 100644 (file)
@@ -6,3 +6,20 @@
 
 $NAMESPACE isc::dhcp
 
+% DHCP_ADD_EXTERNAL_SOCKET Attempted to register external socket %1 from different thread %2
+This error message indicates that a different thread than the main thread has
+registered an external socket. This is a programming error and should be fixed.
+Only the main thread is allowed to perform operations on the external sockets.
+The file descritptor and the respective thread id are included in the message.
+
+% DHCP_DELETE_ALL_EXTERNAL_SOCKETS Attempted to unregister external sockets from different thread %1
+This error message indicates that a different thread than the main thread has
+deleted all external sockets. This is a programming error and should be fixed.
+Only the main thread is allowed to perform operations on the external sockets.
+The respective thread id is included in the message.
+
+% DHCP_DELETE_EXTERNAL_SOCKET Attempted to unregister external socket %1 from different thread %2
+This error message indicates that a different thread than the main thread has
+unregistered an external socket. This is a programming error and should be fixed.
+Only the main thread is allowed to perform operations on the external sockets.
+The file descritptor and the respective thread id are included in the message.
index 0e6b52c4c6bbbfec0c7084ce68a839fc3e6322dd..3e6b6856bf316a8c7d1775433f9af43ac6250690 100644 (file)
@@ -10,6 +10,8 @@
 #include <asiolink/udp_endpoint.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp/dhcp6.h>
+#include <dhcp/dhcp_log.h>
+#include <dhcp/dhcp_messages.h>
 #include <dhcp/iface_mgr.h>
 #include <dhcp/iface_mgr_error_handler.h>
 #include <dhcp/pkt_filter_inet.h>
@@ -332,11 +334,11 @@ IfaceMgr::addExternalSocket(int socketfd, SocketCallback callback) {
         isc_throw(BadValue, "Attempted to install callback for invalid socket "
                   << socketfd);
     }
-    // @todo: remove comment when exclusively allow external sockets actions on main thread.
-    //if (std::this_thread::get_id() != id_) {
-    //    isc_throw(InvalidOperation, "Attempted to register external socket from different thread "
-    //              << std::this_thread::get_id());
-    //}
+    if (std::this_thread::get_id() != id_) {
+        LOG_ERROR(dhcp_logger, DHCP_ADD_EXTERNAL_SOCKET)
+                .arg(socketfd)
+                .arg(std::this_thread::get_id());
+    }
     std::lock_guard<std::mutex> lock(callbacks_mutex_);
     for (SocketCallbackInfo& s : callbacks_) {
         // There's such a socket description there already.
@@ -363,11 +365,11 @@ IfaceMgr::deleteExternalSocket(int socketfd) {
 
 void
 IfaceMgr::deleteExternalSocketInternal(int socketfd) {
-    // @todo: remove comment when exclusively allow external sockets actions on main thread.
-    //if (std::this_thread::get_id() != id_) {
-    //    isc_throw(InvalidOperation, "Attempted to unregister external socket from different thread "
-    //              << std::this_thread::get_id());
-    //}
+    if (std::this_thread::get_id() != id_) {
+        LOG_ERROR(dhcp_logger, DHCP_DELETE_EXTERNAL_SOCKET)
+                .arg(socketfd)
+                .arg(std::this_thread::get_id());
+    }
     for (SocketCallbackInfoContainer::iterator s = callbacks_.begin();
          s != callbacks_.end(); ++s) {
         if (s->socket_ == socketfd) {
@@ -403,11 +405,10 @@ IfaceMgr::isExternalSocketUnusable(int fd) {
 
 void
 IfaceMgr::deleteAllExternalSockets() {
-    // @todo: remove comment when exclusively allow external sockets actions on main thread.
-    //if (std::this_thread::get_id() != id_) {
-    //    isc_throw(InvalidOperation, "Attempted to unregister external sockets from different thread "
-    //              << std::this_thread::get_id());
-    //}
+    if (std::this_thread::get_id() != id_) {
+        LOG_ERROR(dhcp_logger, DHCP_DELETE_ALL_EXTERNAL_SOCKETS)
+                .arg(std::this_thread::get_id());
+    }
     std::lock_guard<std::mutex> lock(callbacks_mutex_);
     callbacks_.clear();
 }