logging lease expiration time
Jason Alderfer 1
jha2 at emu.edu
Tue Oct 1 21:02:36 UTC 2013
I wrote a Python script which parses dhcpd.leases and uses the lease info
to update DNS for MS Active Directory. In my experience it hasn't been as
hard as it looked at first, even with aggregating lease data from
redundant servers and servers at remote locations. You need logic to
detect when you are within a lease declaration, and then the values for
"binding state", "ends", and "cltt" (if you are using redundant servers)
contain all the information you need to determine which lease record in
the file is active and the most current for a given client (later dates
for "ends" and "cltt".)
A trick you can use to save considerable computation time is that since
the default formatting for dates is "yyyy/mm/dd hh:mm:ss" you never need
to do date conversion; just strip the formatting from the string and
convert it to a long int. Later dates will always be bigger numbers. For
comparison purposes at least -- it sounds like you may be interested in
actual dates for your output.
>> Unable to test it myself right now, but could you try "config-option
>> default-lease-time", cf. man dhcp-eval?
> Oh, I didn't see this when reading the man but sadly it is still a no
> go: "[..] no option named default-lease-time in space dhcp"
> I wonder what is "space dhcp" though.
>> [..] dhcp.leases is probably the best bet even though it's a pain.
> Yes, sadly it's pobably the only solution.
> But it's sad especially when you realise that you can have many leases
> for the same IP. I wonder how and when the garbage collector kicks in
> (man dhcpd.leases does not explain it). As an experiment, I tried a
> max-lease-time of 60sec. It does not go over 90 to 100 entries for the
> same IP in dhcpd.leases. If only dhcpd.leases could immediately remove
> duplicates. Obviously in my production environment I won't have a such
> lease time but still. I guess the authors had their reasons to do it
> that way. I cannot read ISC dhcpd code, it's too complex for me, far too
> many structures for my brain.
> man dhcpd.leases
> In order to prevent the lease database from growing without bound, the
> file is rewritten from time to time. First, a temporary lease
> database is created and all known leases are dumped to it. Then, the
> old lease database is renamed /var/lib/dhcpd/dhcpd.leases~. Finally,
> the newly written lease database is moved into place.
> The lease file is a log-structured file - whenever a lease changes, the
> contents of that lease are written to the end of the file. This means
> that it is entirely possible and quite reasonable for there to be two
> or more declarations of the same lease in the lease file at the same
> time. In that case, the instance of that particular lease that
> appears last in the file is the one that is in effect.
> dhcp-users mailing list
> dhcp-users at lists.isc.org
More information about the dhcp-users