From aaababbd722aee958e6251c14c8f80621dcd6d20 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Tue, 13 Jan 2015 15:21:59 +0100 Subject: [PATCH] [3668] Install LFC timer for the DHCPv4 and DHCPv6 server. --- src/bin/dhcp4/dhcp4_messages.mes | 7 ++++++ src/bin/dhcp4/dhcp4_srv.cc | 27 ++++++++++++++++++++--- src/bin/dhcp6/dhcp6_messages.mes | 7 ++++++ src/bin/dhcp6/dhcp6_srv.cc | 33 +++++++++++++++++++++------- src/lib/dhcpsrv/dhcpsrv_messages.mes | 5 +++++ src/lib/dhcpsrv/memfile_lease_mgr.cc | 1 + 6 files changed, 69 insertions(+), 11 deletions(-) diff --git a/src/bin/dhcp4/dhcp4_messages.mes b/src/bin/dhcp4/dhcp4_messages.mes index e72c2631bc..4d16ba913e 100644 --- a/src/bin/dhcp4/dhcp4_messages.mes +++ b/src/bin/dhcp4/dhcp4_messages.mes @@ -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 diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index eddb22ead5..67b9a09d76 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -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 #include +#include #include #include @@ -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) { diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index da077ac7e1..9caa7338d6 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -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, diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index fc44347866..5b6f51da2d 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -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 #include +#include + #include #include #include @@ -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) { diff --git a/src/lib/dhcpsrv/dhcpsrv_messages.mes b/src/lib/dhcpsrv/dhcpsrv_messages.mes index c8c1256394..5118807e8b 100644 --- a/src/lib/dhcpsrv/dhcpsrv_messages.mes +++ b/src/lib/dhcpsrv/dhcpsrv_messages.mes @@ -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. diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index b39e3edcd5..0b08fca94a 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -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); } } -- 2.47.3