[Kea-users] Extracting vendor-specific suboptions in hooks

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Kea-users] Extracting vendor-specific suboptions in hooks

Dave M
I am new to Kea so excuse my lack of knowledge here.

I have been running a ISC DHCP server to handle cable modems (and associated CPE and MTA) IP assignment. I needed some more advanced logic with the assignment of configuration file and Kea with the customizable hooks seemed like the logical choice.

I migrated my configuration to Kea and I'm now able to perform basic provisioning of CM and CPEs. I'm relying on a subset of the vendor class identifier (because it can be docsis3.0 or docsis3.1) and all is good with the following resulting class configuration

  "client-classes": [
        {
           "name": "CM",
           "test": "substring(option[vendor-class-identifier].text, 0, 6) == 'docsis'"

        },
        {
           "name": "MTA",
           "test": "substring(option[vendor-class-identifier].text, 0, 4) == 'pktc'"
        },
        {
           "name": "CPE",
           "test": "not (member('CM')) and not (member('MTA'))"
        }
  ],

My problem is with the hook. I want to dynamically assign the boot-file and server based on MAC address and model information (option 43, suboption 9) and potentially software version (option 43, suboption 6).

I will therefore need to extract these in pkt4_receive and then replace the boot-file and server according to my logic in pkt4_send.

I just don't know how to retrieve and parse the suboptions in option 43. Would anybody have sample code showing how I can extract these?

Thanks

Dave M.

_______________________________________________
Kea-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/kea-users
Reply | Threaded
Open this post in threaded view
|

Re: [Kea-users] Extracting vendor-specific suboptions in hooks

Tomek Mrugalski
On 29/05/2019 22:32, Dave M wrote:
> My problem is with the hook. I want to dynamically assign the boot-file
> and server based on MAC address and model information (option 43,
> suboption 9) and potentially software version (option 43, suboption 6).
>
> I will therefore need to extract these in pkt4_receive and then replace
> the boot-file and server according to my logic in pkt4_send.
>
> I just don't know how to retrieve and parse the suboptions in option 43.
> Would anybody have sample code showing how I can extract these?
Questions about hooks development are generally better addressed at kea-dev.

You may want to take a look at
src/bin/dhcp4/tests/vendor_opts_unittest.cc and possibly also at
src/lib/dhcp/tests/option_vendor_unittest.cc Overall, you can do
something similar to this:

// check if there's option 43 in the packet.
Option4Ptr opt43 = pkt->getOption(DHO_VENDOR_ENCAPSULATED_OPTIONS);
if (!opt43) {
    return;
}

// Get suboption 6 from the option 43.
Option4Ptr subopt6 = opt43->getOption(6);

// If you have option definitions, you may want to try casting to
// specific type. That way you'll be able to use type specific, such
// as getValue() returning a string for OptionString.
boost::shared_ptr<OptionVendor> str_subopt6 =
   boost::dynamic_pointer_cast<OptionString>(subopt6);

if (str_subopt6) {
 cout << "opt 43,subopt 6 value is " << str_subopt6->getValue() << endl;
}

You may want to take a look at src/lib/dhcp/option_*.h files.

Hope that helps,
Tomek
_______________________________________________
Kea-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/kea-users
Reply | Threaded
Open this post in threaded view
|

Re: [Kea-users] Extracting vendor-specific suboptions in hooks

Ola Thoresen
Hi,

I have a, rather old now, hook that you might want to look at.

https://github.com/Olen/kea_hooks

Please fork it and take over the project if you want to. As I don't
maintain any kea installations any longer, I have not updated it since a
really early version of Kea.



On 12.07.2019 15:50, Tomek Mrugalski wrote:

> On 29/05/2019 22:32, Dave M wrote:
>> My problem is with the hook. I want to dynamically assign the boot-file
>> and server based on MAC address and model information (option 43,
>> suboption 9) and potentially software version (option 43, suboption 6).
>>
>> I will therefore need to extract these in pkt4_receive and then replace
>> the boot-file and server according to my logic in pkt4_send.
>>
>> I just don't know how to retrieve and parse the suboptions in option 43.
>> Would anybody have sample code showing how I can extract these?
> Questions about hooks development are generally better addressed at kea-dev.
>
> You may want to take a look at
> src/bin/dhcp4/tests/vendor_opts_unittest.cc and possibly also at
> src/lib/dhcp/tests/option_vendor_unittest.cc Overall, you can do
> something similar to this:
>
> // check if there's option 43 in the packet.
> Option4Ptr opt43 = pkt->getOption(DHO_VENDOR_ENCAPSULATED_OPTIONS);
> if (!opt43) {
>      return;
> }
>
> // Get suboption 6 from the option 43.
> Option4Ptr subopt6 = opt43->getOption(6);
>
> // If you have option definitions, you may want to try casting to
> // specific type. That way you'll be able to use type specific, such
> // as getValue() returning a string for OptionString.
> boost::shared_ptr<OptionVendor> str_subopt6 =
>     boost::dynamic_pointer_cast<OptionString>(subopt6);
>
> if (str_subopt6) {
>   cout << "opt 43,subopt 6 value is " << str_subopt6->getValue() << endl;
> }
>
> You may want to take a look at src/lib/dhcp/option_*.h files.
>
> Hope that helps,
> Tomek
> _______________________________________________
> Kea-users mailing list
> [hidden email]
> https://lists.isc.org/mailman/listinfo/kea-users
_______________________________________________
Kea-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/kea-users
Reply | Threaded
Open this post in threaded view
|

Re: [Kea-users] Extracting vendor-specific suboptions in hooks

Michael Gugino
My approach was to modify the bootp information in pkt4_send to replace whatever was put there: https://github.com/michaelgugino/kea-pxe-replace-mod/blob/master/src/pkt4_send.cc
(Note: I'm not reading option 43 data, but if I was, I might do the same thing.  If that data isn't accessible in pkt4_send, I'd use a temp file based on mac to store this data and do the manipulation to the bootp bits in pkt4_send)



On Friday, July 12, 2019, 10:07:11 AM EDT, Ola Thoresen <[hidden email]> wrote:


Hi,

I have a, rather old now, hook that you might want to look at.

https://github.com/Olen/kea_hooks

Please fork it and take over the project if you want to. As I don't
maintain any kea installations any longer, I have not updated it since a
really early version of Kea.



On 12.07.2019 15:50, Tomek Mrugalski wrote:

> On 29/05/2019 22:32, Dave M wrote:
>> My problem is with the hook. I want to dynamically assign the boot-file
>> and server based on MAC address and model information (option 43,
>> suboption 9) and potentially software version (option 43, suboption 6).
>>
>> I will therefore need to extract these in pkt4_receive and then replace
>> the boot-file and server according to my logic in pkt4_send.
>>
>> I just don't know how to retrieve and parse the suboptions in option 43.
>> Would anybody have sample code showing how I can extract these?
> Questions about hooks development are generally better addressed at kea-dev.
>
> You may want to take a look at
> src/bin/dhcp4/tests/vendor_opts_unittest.cc and possibly also at
> src/lib/dhcp/tests/option_vendor_unittest.cc Overall, you can do
> something similar to this:
>
> // check if there's option 43 in the packet.
> Option4Ptr opt43 = pkt->getOption(DHO_VENDOR_ENCAPSULATED_OPTIONS);
> if (!opt43) {
>      return;
> }
>
> // Get suboption 6 from the option 43.
> Option4Ptr subopt6 = opt43->getOption(6);
>
> // If you have option definitions, you may want to try casting to
> // specific type. That way you'll be able to use type specific, such
> // as getValue() returning a string for OptionString.
> boost::shared_ptr<OptionVendor> str_subopt6 =
>    boost::dynamic_pointer_cast<OptionString>(subopt6);
>
> if (str_subopt6) {
>  cout << "opt 43,subopt 6 value is " << str_subopt6->getValue() << endl;
> }
>
> You may want to take a look at src/lib/dhcp/option_*.h files.
>
> Hope that helps,
> Tomek
> _______________________________________________
> Kea-users mailing list
> [hidden email]
> https://lists.isc.org/mailman/listinfo/kea-users
_______________________________________________
Kea-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/kea-users

_______________________________________________
Kea-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/kea-users