[Kea-users] lease4 table additional connection to mysql

Tomek Mrugalski tomasz at isc.org
Tue Dec 4 19:39:40 UTC 2018

On 04.12.2018 13:06, sven.roehrig at web.de wrote:
> currently I'm working on a hook for kea dhcpv4 to differentiate between
> privileged/unprivileged leases.
> I'm reading the hardware address and relay agent id (dhcp option 82) out in
> the pkt4_send hook and save it for use in the pkt4_receive hook.
> In the latter I want to check if the hardware address exists in the lease4
> table or in case it doesn't, check for the relay agent id. Next step would
> be to set an privileged/unknown class depending on the existance of the
> check.
> My question is, is there a more elegant way to check if a lease exists than
> using an additional connection to the mysql server and querying the table?
> E.g. using the kea engine to check?
It depends on the query. You may use existing leasemgr:

#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>

auto a =  LeaseMgrFactory::instance().getLease4(hwaddr);
auto b =  LeaseMgrFactory::instance().getLease4(hwaddr, subnet_id);

Take a look at the LeaseMgr class interface in lease_mgr.h. There are
several different queries exposed. If they cover what you want to do -

Also, if you need to store anything with existing leases, you may want
to take a look at user-context. 1.5.0beta1 introduced support for this
in leases. The concept is simple: you're able to store any data (within
reason, IIRC there's 8KB limit) with leases as long as it is in JSON format.

Hope that helps,

More information about the Kea-users mailing list