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@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@lists.isc.org https://lists.isc.org/mailman/listinfo/kea-users