[Kea-users] reading user-context from lease4_select hook

Francis Dupont fdupont at isc.org
Fri Dec 18 11:29:54 UTC 2020


> itay cohen writes:
> Im trying to read user-context with a hook
>
> lease4_select(CalloutHandle& handle) {
>      Subnet4Ptr subnet4_ptr;
>      handle.getArgument("subnet4", subnet4_ptr); // <-- getting selected
> subnet
>      ConstElementPtr subnet_ctx;
>      subnet_ctx = subnet4_ptr->getContext(); // <-- this is working !
>
>     Pool4Ptr pool_ptr;
>     handle.getArgument("pool", pool_ptr);  // <-- getting selected pool ??

=> There is no pool passed to the lease4_select callout (arguments
are the query4, subnet4, fake_allocation and lease4).
The documentation is in the developer guide at
https://jenkins.isc.org/job/Kea_doc/doxygen/de/df3/dhcpv4Hooks.html

>     ConstElementPtr pool4_ctx;
>     pool4_ctx = pool4_ptr->getContext(); // <-- this NOT working
>
> }

=> either you check pool4_ptr before and it returns null or you
do not check and it crashes.

>  can some one advise how to read user-context at the pool level ?

=> you need to get the address from the lease and use the getPool method
on the subnet to find what pool the address is from (note that getPool
interface was designed for allocation so the type is Lease::TYPE_V4 and
the anypool to false (critical as it defaults to true).

Thanks

Francis Dupont <fdupont at isc.org>

PS: the main reason pools are not saved in leases nor get their own
statistics is a pool is a bit hard to identify. If you have an idea
for a code and user friendly way to identify a pool please submit it.


More information about the Kea-users mailing list