[Kea-users] lease4_select hook

Tomek Mrugalski tomasz at isc.org
Fri Apr 19 14:29:24 UTC 2019


On 18.04.2019 10:30, raj wrote:
> I want to add lease4_select hook for following step.
This is definitely a question for kea-dev. kea-users is a list intended
for users.

If you have any follow-up questions, please send them to kea-dev.

> 1) On dhcp lease request, the hook should check whether selected ipaddress
> by Kea is not in Mac Address Table
Not sure if you have a separate list of MAC addresses outside of Kea or
perhaps the leases being currently assigned. If you mean the latter, see
one of getLease4 methods in LeaseMgr.

> 2) If it is not inside Mac Table, don't do any changes.
> 3) If it is already in Mac Table, 
>   3.1) Select new ipaddress 
>   3.2) Validate whether new selected ipaddress is not present in Kea
> database or Mac address
>   3.3) Assign address if 3.2) is good
>   3.4) If new address is already present, start from 3.1)
There's allocateLease4 in AllocationEngine that does all of the above +
much more (such as checking if there's an address reserved for this
paritcular host, whether the address that's being considered is used by
someone else, if it's used if it's expired, if it's reserved for someone
else, whether the address was declined etc).

Please be very careful if you go that route. Your algorithm seems like
oversimplified version of allocation engine. It work most of the time,
except cases when address is used by someone else, the configuration has
changed, there's a reservation for someone else or several other cases.

> Can someone please help me to how to perform steps for 3.1) and 3.2) ?
> 
> I don't know how to access Kea's main AllocatorEngine functions to get new
> ipaddress as well as current lease database states.
In principle you pass ClientContext4 with some fields set up (such as
client details) and the method will find existing lease or allocate a
new one for you. Please see extensive description of
AllocationEngine::allocateLease4.

Hope that helps.

Tomek


More information about the Kea-users mailing list