core: KEA-DHCP: Valid leases missing in leases status

Important notices

Before you add a new report, we ask you kindly to acknowledge the following:

Describe the bug

Yesterday I have switched to KEA DHCP and it is working fine. I am facing one issue with the leases status page/log file: I am having around 35 devices connected to my network and all are using DHCP. I was surprised that under SERVICES: KEA DHCP [NEW]: LEASES DHCPV4 I am only seeing around 15 entries.

I found out that every hour the leases file gets cleaned (Informational kea-dhcp4 INFO [kea-dhcp4.dhcpsrv.0x83530e000] DHCPSRV_MEMFILE_LFC_START starting Lease File Cleanup) and then the list of leases is completely empty, until the devices renew their lease. So even the leases that were handed out and are still valid get removed and are no longer visible.

With ISC DHCP this did not happen and I had a reliable list of leases that were handed out.

To Reproduce

Steps to reproduce the behavior:

  1. Install 24.1.1
  2. Activate KEA DHCP
  3. Connect a device to the network and verify that it got a lease from KEA
  4. Find this lease in the “Leases” status under SERVICES: KEA DHCP [NEW]: LEASES DHCPV4
  5. Wait some time until leases file gets cleaned up (happens every hour)
  6. See that the lease is no longer visible even if it is still valid (I verified that)

Expected behavior

Leases should stay in history as long as they are valid.

Describe alternatives you considered

No workaround. I am currently using ARP-Table to verify which clients are connected, as the lease status with KEA is not accurate.

Screenshots

Here are some screenshots that show the behavior:

Device with ip 192.168.218.101 got its lease at 2024-02-0509:55:24: 02

Cleanup of leases file happened at 2024-02-05T09:59:53: 03

Device with ip 192.168.218.101 is not visible in Leases status at around 2024-02-05T10:30, even if the lease received at 09:55:24 is still valid (lifetime 7200s): 01

Relevant log files

Informational kea-dhcp4 INFO [kea-dhcp4.dhcpsrv.0x83530e000] DHCPSRV_MEMFILE_LFC_START starting Lease File

Environment

Software version used and hardware type if relevant, e.g.:

OPNsense 24.1.1 (amd64). Intel® Celeron® J6412 @ 2.00GHz (4 cores, 4 threads)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (11 by maintainers)

Commits related to this issue

Most upvoted comments

To test, use:

opnsense-patch 20e9bdc459b31dd9f60111d1ae5d16181c868f7d

Thank you! It is working fine now and showing all 21 leases in Web GUI…

ok, this literally took me ages to track.

The lfc process is responsible for lease cleanup, which should be described at https://kea.readthedocs.io/en/latest/arm/lfc.html pointed to by https://kea.readthedocs.io/en/kea-2.0.2/arm/dhcp4-srv.html#memfile-basic-storage-for-leases . Which states the following:

… the server stores lease information in a CSV file rather than a database.

Which suggests a (one) file.

Diving deeper into the development documentation, there’s a list of files being used by the process in https://gitlab.isc.org/isc-projects/kea/-/wikis/designs/Lease-File-Cleanup-design#file-names . Which, in my humble opinion, still isn’t very clear about the contents of the “lease” file.

Deep diving into the source, eventually points to:

https://github.com/isc-projects/kea/blob/ef1f878f5272d2f9c9d27b2dd592055e330ac887/src/lib/dhcpsrv/memfile_lease_mgr.h#L1039-L1051

Which states:

/// This method loads DHCPv4 or DHCPv6 leases from lease files in the
/// following order:
/// - If the <filename>.completed doesn't exist:
///   - leases from the <filename>.2
///   - leases from the <filename>.1
///   - leases from the <filename>
/// - else
///   - leases from the <filename>.completed
///   - leases from the <filename>
///
/// If any of the files doesn't exist the method proceeds to reading
/// leases from the subsequent file. If the <filename> doesn't exist
/// it is created.

I know people have been asking for KEA for a long time, googling a bit for these type of issues makes you wonder if anybody is actually using this stuff…

Let’s implement the processing order from their source and be done with this…