From: Thomas Markwalder Date: Fri, 28 Oct 2016 19:23:47 +0000 (-0400) Subject: [5058] CSV lease file loading now emits error log for each invalid row X-Git-Tag: trac5057_base~11^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=939e65e30608e72b466753aef7ba0deef5a4a742;p=thirdparty%2Fkea.git [5058] CSV lease file loading now emits error log for each invalid row src/bin/lfc/tests/lfc_controller_unittests.cc Fixed test data src/lib/dhcpsrv/dhcpsrv_messages.mes added new error log message DHCPSRV_MEMFILE_LEASE_LOAD_ROW_ERROR src/lib/dhcpsrv/lease_file_loader.h LeaseFileLoader::load() - new emits a error log for each row that fails to load --- diff --git a/src/bin/lfc/tests/lfc_controller_unittests.cc b/src/bin/lfc/tests/lfc_controller_unittests.cc index f53248aff6..76a80ddb38 100644 --- a/src/bin/lfc/tests/lfc_controller_unittests.cc +++ b/src/bin/lfc/tests/lfc_controller_unittests.cc @@ -407,8 +407,9 @@ TEST_F(LFCControllerTest, launch4) { string b_3 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04," "100,150,7,0,0,,1\n"; + // This one should be invalid, no hardware address and state is not declined string c_1 = "192.0.2.3,,a:11:01:04," - "200,200,8,1,1,host.example.com,1\n"; + "200,200,8,1,1,host.example.com,0\n"; string d_1 = "192.0.2.5,16:17:18:19:1a:bc,," "200,200,8,1,1,host.example.com,1\n"; diff --git a/src/lib/dhcpsrv/dhcpsrv_messages.mes b/src/lib/dhcpsrv/dhcpsrv_messages.mes index 69dec51702..9fa51bd16d 100644 --- a/src/lib/dhcpsrv/dhcpsrv_messages.mes +++ b/src/lib/dhcpsrv/dhcpsrv_messages.mes @@ -459,6 +459,12 @@ replaced by those read from the file. % DHCPSRV_MEMFILE_LEASE_LOAD loading lease %1 A debug message issued when DHCP lease is being loaded from the file to memory. +% DHCPSRV_MEMFILE_LEASE_LOAD_ROW_ERROR discarding row %1, error: %2 +An error message issued the the DHCP lease being loaded from the given row of +the lease file fails. The log message should contain the specific reason the +row was discarded. The server will continue loading the remaining data. +This may indicate a corrupt lease file. + % DHCPSRV_MEMFILE_LFC_EXECUTE executing Lease File Cleanup using: %1 An informational message issued when the Memfile lease database backend starts a new process to perform Lease File Cleanup. diff --git a/src/lib/dhcpsrv/lease_file_loader.h b/src/lib/dhcpsrv/lease_file_loader.h index 0eb5c54280..77add53311 100644 --- a/src/lib/dhcpsrv/lease_file_loader.h +++ b/src/lib/dhcpsrv/lease_file_loader.h @@ -91,6 +91,10 @@ public: while (true) { // Unable to parse the lease. if (!lease_file.next(lease)) { + LOG_ERROR(dhcpsrv_logger, DHCPSRV_MEMFILE_LEASE_LOAD_ROW_ERROR) + .arg(lease_file.getReads()) + .arg(lease_file.getReadMsg()); + // A value of 0xFFFFFFFF indicates that we don't return // until the whole file is parsed, even if errors occur. // Otherwise, check if we have exceeded the maximum number