]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3668] Install LFC timer for the DHCPv4 and DHCPv6 server.
authorMarcin Siodelski <marcin@isc.org>
Tue, 13 Jan 2015 14:21:59 +0000 (15:21 +0100)
committerMarcin Siodelski <marcin@isc.org>
Tue, 13 Jan 2015 14:21:59 +0000 (15:21 +0100)
src/bin/dhcp4/dhcp4_messages.mes
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp6/dhcp6_messages.mes
src/bin/dhcp6/dhcp6_srv.cc
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/memfile_lease_mgr.cc

index e72c2631bc843dbe9e41ba9f9cc64bd83cad5502..4d16ba913e6112aa0df75d2f5ee017724e9837b9 100644 (file)
@@ -187,6 +187,13 @@ specified client after receiving a REQUEST message from it.  There are many
 possible reasons for such a failure. Additional messages will indicate the
 reason.
 
+% DHCP4_LEASE_DATABASE_TIMERS_EXEC_FAIL failed to execute the timers for lease database: %1
+A warning message executed when a server process is unable to execute
+the periodic actions for the lease database. An example of the periodic
+action is a Lease File Cleanup. One of the reasons for the failure is
+a misconfiguration of the lease database, whereby the lease database
+hasn't been selected.
+
 % DHCP4_NAME_GEN_UPDATE_FAIL failed to update the lease after generating name for a client: %1
 This message indicates the failure when trying to update the lease and/or
 options in the server's response with the hostname generated by the server
index eddb22ead55c87ea547ff3d210899da385c0f1fe..67b9a09d7654af367a60823470dc5d227b4c3fe1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -40,6 +40,7 @@
 #include <hooks/hooks_manager.h>
 #include <util/strutil.h>
 
+#include <asio.hpp>
 #include <boost/bind.hpp>
 #include <boost/foreach.hpp>
 
@@ -149,9 +150,20 @@ Dhcpv4Srv::sendPacket(const Pkt4Ptr& packet) {
 bool
 Dhcpv4Srv::run() {
     while (!shutdown_) {
-        /// @todo: calculate actual timeout once we have lease database
+        /// @todo Currently we're using the fixed value of the timeout for
+        /// select. This value shouldn't be changed. Keeping it at 1s
+        /// guarantees that the main loop will be executed at least once
+        /// a seconds allowing for executing the interval timers associated
+        /// with the lease database backend in use. The intervals for these
+        /// timers are configured using the unit of 1 second. Bumping up
+        /// the select timeout would cause the timers to go out of sync
+        /// with the configured value.
+        /// Probing for the packets at this pace should not cause a
+        /// significant rise of the CPU usage. However, in the future we
+        /// should adjust the select timeout to the value reported by the
+        /// lease database backend as a minimal poll interval.
         //cppcheck-suppress variableScope This is temporary anyway
-        const int timeout = 1000;
+        const int timeout = 1;
 
         // client's message and server's response
         Pkt4Ptr query;
@@ -183,6 +195,15 @@ Dhcpv4Srv::run() {
         // terminate.
         handleSignal();
 
+        // Execute ready timers for the lease database, e.g. Lease File Cleanup.
+        try {
+            LeaseMgrFactory::instance().getIOService()->get_io_service().poll();
+
+        } catch (const std::exception& ex) {
+            LOG_WARN(dhcp4_logger, DHCP4_LEASE_DATABASE_TIMERS_EXEC_FAIL)
+                .arg(ex.what());
+        }
+
         // Timeout may be reached or signal received, which breaks select()
         // with no reception ocurred
         if (!query) {
index da077ac7e1e30ff03eeb2f65f73d2328b29f4226..9caa7338d62285bf5ac2634cf57d4724597270d5 100644 (file)
@@ -275,6 +275,13 @@ failed to grant a non-temporary address lease for the client. There may
 be many reasons for such failure. Each failure is logged in a separate
 log entry.
 
+% DHCP6_LEASE_DATABASE_TIMERS_EXEC_FAIL failed to execute the timers for lease database: %1
+A warning message executed when a server process is unable to execute
+the periodic actions for the lease database. An example of the periodic
+action is a Lease File Cleanup. One of the reasons for the failure is
+a misconfiguration of the lease database, whereby the lease database
+hasn't been selected.
+
 % DHCP6_LEASE_NA_WITHOUT_DUID address lease for address %1 does not have a DUID
 This error message indicates a database consistency problem. The lease
 database has an entry indicating that the given address is in use,
index fc44347866260bbbc0f1fbe1f81e1493cbe07655..5b6f51da2d0c98d73e83a748e686601847621f83 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -47,6 +47,8 @@
 #include <util/io_utilities.h>
 #include <util/range_utilities.h>
 
+#include <asio.hpp>
+
 #include <boost/bind.hpp>
 #include <boost/foreach.hpp>
 #include <boost/tokenizer.hpp>
@@ -228,14 +230,20 @@ Dhcpv6Srv::testUnicast(const Pkt6Ptr& pkt) const {
 
 bool Dhcpv6Srv::run() {
     while (!shutdown_) {
-        /// @todo Calculate actual timeout to the next event (e.g. lease
-        /// expiration) once we have lease database. The idea here is that
-        /// it is possible to do everything in a single process/thread.
-        /// For now, we are just calling select for 1000 seconds. There
-        /// were some issues reported on some systems when calling select()
-        /// with too large values. Unfortunately, I don't recall the details.
+        /// @todo Currently we're using the fixed value of the timeout for
+        /// select. This value shouldn't be changed. Keeping it at 1s
+        /// guarantees that the main loop will be executed at least once
+        /// a seconds allowing for executing the interval timers associated
+        /// with the lease database backend in use. The intervals for these
+        /// timers are configured using the unit of 1 second. Bumping up
+        /// the select timeout would cause the timers to go out of sync
+        /// with the configured value.
+        /// Probing for the packets at this pace should not cause a
+        /// significant rise of the CPU usage. However, in the future we
+        /// should adjust the select timeout to the value reported by the
+        /// lease database backend as a minimal poll interval.
         //cppcheck-suppress variableScope This is temporary anyway
-        const int timeout = 1000;
+        const int timeout = 1;
 
         // client's message and server's response
         Pkt6Ptr query;
@@ -266,6 +274,15 @@ bool Dhcpv6Srv::run() {
         // terminate.
         handleSignal();
 
+        // Execute ready timers for the lease database, e.g. Lease File Cleanup.
+        try {
+            LeaseMgrFactory::instance().getIOService()->get_io_service().poll();
+
+        } catch (const std::exception& ex) {
+            LOG_WARN(dhcp6_logger, DHCP6_LEASE_DATABASE_TIMERS_EXEC_FAIL)
+                .arg(ex.what());
+        }
+
         // Timeout may be reached or signal received, which breaks select()
         // with no packet received
         if (!query) {
index c8c1256394fe87f5ceddaa4826b00a1d86042a5a..5118807e8bf08f437da1437b1b967f03d7fbdc29 100644 (file)
@@ -302,6 +302,11 @@ memory.
 A debug message issued when DHCPv6 lease is being loaded from the file to
 memory.
 
+% DHCPSRV_MEMFILE_LFC_SETUP setting up the Lease File Cleanup interval to %1 sec
+An info message logged when the Memfile lease database backend configures
+the LFC to be executed periodically. An argument holds the interval in seconds
+in which the LFC will be executed.
+
 % DHCPSRV_MEMFILE_LFC_START starting Lease File Cleanup
 An info message issued when the Memfile lease database backend starts the
 periodic Lease File Cleanup.
index b39e3edcd5cd415943f03df802097a54815ed077..0b08fca94acf4727b0c67695df17b4f2b6baeb01 100644 (file)
@@ -491,6 +491,7 @@ Memfile_LeaseMgr::initTimers(const Universe& universe) {
     if (lfc_interval > 0) {
         asiolink::IntervalTimer::Callback cb =
             boost::bind(&Memfile_LeaseMgr::lfcCallback, this);
+        LOG_INFO(dhcpsrv_logger, DHCPSRV_MEMFILE_LFC_SETUP).arg(lfc_interval);
         lfc_timer_.setup(cb, lfc_interval * 1000);
     }
 }