[Kea-users] Hook subnet4_select callout modifying subnet ID
Bryan Perry
bryan at sfcn.org
Thu May 12 18:01:47 UTC 2016
Fantastic example Thomas. Thank you.
I intend to determine the subnet ID I want to use with a quick call to
the hosts table for that client to check for a reservation. If a
reservation exists, I will modify the subnet to match the reservation.
I will try this out today and let you know how it goes.
Thanks!
Bryan
On 5/12/2016 11:57 AM, Thomas Markwalder wrote:
> On 5/12/16 1:13 PM, Bryan Perry wrote:
>> Hi All,
>>
>> I am needing to modify the subnet ID for certain clients. It looks
>> like the best way to do this is in the subnet4_select hook callout,
>> but I'm not the most skilled C++ coder. Can anyone provide me with a
>> quick example of modifying the subnet ID? Even pseudo-code would be
>> somewhat helpful.
>>
>> I do have a library compiled and loaded, and I can read the value of
>> the subnet ID this way:
>>
>> Subnet4Ptr subnet4_ptr;
>> handle.getArgument("subnet4", subnet4_ptr);
>> SubnetID subnetId = subnet4_ptr->getID();
>>
>> What I don't know is how to correctly set it to a different value.
>>
>> Thanks in advance for any help,
>> Bryan
>> _______________________________________________
>> Kea-users mailing list
>> Kea-users at lists.isc.org
>> https://lists.isc.org/mailman/listinfo/kea-users
>
> Hi Bryan:
>
> If you're trying to change the subnet that's been selected, altering the
> subnet ID as you suggest will not work. You need to update the
> "subnet4" argument with the desired subnet as illustrated in the snippet
> below:
>
> :
>
> // Get the collection of subnets from the callout argument set
> const isc::dhcp::Subnet4Collection* subnets;
> handle.getArgument("subnet4collection", subnets);
>
> // Am assuming you somehow know the ID of the subnet you want
> int the_id_you_want = 2;
>
> // Next, we iterate over the collection of subnets, looking for the
> // ID we want
> for (int i = 0; i < subnets->size(); ++i) {
> Subnet4Ptr new_subnet = (*subnets)[i];
> if (new_subnet->getID() == the_id_you_want) {
> // id matched so replace the selected subnet by
> // setting the "subnet4" callout argument with
> // the new subnet
> handle.setArgument("subnet4", new_subnet);
> break;
> }
> }
>
> :
>
>
> The snippet above is written for clarity, I'm sure there are slicker
> ways to do it. It assumes that you somehow know the ID of the subnet
> you want and if there's no match it leaves the selected subnet as is.
> Really it is just intended to show you how one might alter the selected
> subnet. Hope this helps.
>
>
> Thomas Markwalder,
>
> ISC Software Engineering
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Kea-users mailing list
> Kea-users at lists.isc.org
> https://lists.isc.org/mailman/listinfo/kea-users
>
More information about the Kea-users
mailing list