Feature #15321
openFeature #15650: Kea Feature Integration for parity with ISC DHCP
Kea DHCP Custom Options Support (IPv4 and IPv6)
Added by Alhusein Zawi 9 months ago. Updated about 2 months ago.
0%
Description
adding customs options to KEA DHCP
Files
sample-kea-option-def.json (344 Bytes) sample-kea-option-def.json | Dale Harron, 10/03/2024 07:41 PM |
Related issues
Updated by Lev Prokofev 6 months ago
Below is an example of possible options with the right syntax:
https://github.com/isc-projects/kea/blob/master/doc/examples/kea4/all-options.json
Updated by Jim Pingle 4 months ago
- Subject changed from KEA DHCP custom options to Kea DHCP Custom Options Support (IPv4 and IPv6)
- Parent task set to #15650
Updated by Marcos M about 2 months ago
I'm providing a patch here to experiment with custom options for DHCP4; no support will be provided for this. ShowHide
diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index 62cbcd4e40..48c90ee690 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -1221,6 +1221,22 @@ function services_kea4_configure() { $dhcpdcfg = config_get_path('dhcpd'); $Iflist = get_configured_interface_list(); + /* custom options */ + $kea_custom_options_set = false; + $kea_custom_options_config = config_get_path('kea/custom_options_patch'); + if (!empty($kea_custom_options_config)) { + $kea_custom_options_config = base64_decode($kea_custom_options_config); + if (is_string($kea_custom_options_config)) { + $kea_custom_options_set = true; + } + } + if ($kea_custom_options_set) { + $kea_custom_options_config = json_decode($kea_custom_options_config, true); + if (empty($kea_custom_options_config) || !is_array($kea_custom_options_config)) { + $kea_custom_options_set = false; + } + } + /* configuration is built as a PHP array and converted to json */ $keaconf = []; $keaconf['Dhcp4'] = [ @@ -1265,6 +1281,13 @@ function services_kea4_configure() { ], ]; + /* custom option definitions */ + if ($kea_custom_options_set) { + foreach ($kea_custom_options_config['option-def'] as $option_def) { + $keaconf['Dhcp4']['option-def'][] = $option_def; + } + } + /* See https://redmine.pfsense.org/issues/15328 */ $keaconf['Dhcp4']['sanity-checks'] = [ 'lease-checks' => 'fix-del' @@ -1504,6 +1527,16 @@ function services_kea4_configure() { $all_pools = array_merge($all_pools, $dhcpifconf['pool']); } + /* custom option data */ + if ($kea_custom_options_set) { + foreach (array_get_path($kea_custom_options_config, "option-data/all", []) as $custom_option_data) { + $keasubnet['option-data'][] = $custom_option_data; + } + foreach (array_get_path($kea_custom_options_config, "option-data/{$dhcpif}", []) as $custom_option_data) { + $keasubnet['option-data'][] = $custom_option_data; + } + } + if ($dhcpifconf['domain']) { $keasubnet['option-data'][] = [ 'name' => 'domain-name', diff --git a/src/usr/local/www/services_dhcp_settings.php b/src/usr/local/www/services_dhcp_settings.php index b219460f5c..aa5f352363 100644 --- a/src/usr/local/www/services_dhcp_settings.php +++ b/src/usr/local/www/services_dhcp_settings.php @@ -61,6 +61,21 @@ if ($_POST['apply']) { } elseif ($_POST['act']) { switch($_POST['act']) { case 'save': + /* custom options config */ + if (!empty($_POST['custom_options_patch'])) { + $temp_data = json_decode($_POST['custom_options_patch'], true); + if (is_array($temp_data) && !empty($temp_data)) { + array_set_path($pconfig, 'custom_options_patch', base64_encode($_POST['custom_options_patch'])); + config_set_path('kea/custom_options_patch', base64_encode($_POST['custom_options_patch'])); + write_config("DHCP Server - added custom options"); + mark_subsystem_dirty('dhcpd'); + } + } elseif (config_get_path('kea/custom_options_patch') !== null) { + array_del_path($pconfig, 'custom_options_patch'); + config_del_path('kea/custom_options_patch'); + write_config("DHCP Server - removed custom options"); + mark_subsystem_dirty('dhcpd'); + } [$input_errors, $pconfig] = dhcp_do_settings_post($subnets); $subnets = kea_build_subnet_list(); /* refresh subnet list */ break; @@ -342,6 +357,15 @@ $section->addInput(new Form_Select( $form->add($section); +/* custom options input */ +$section = new Form_Section(gettext('Custom Options')); +$section->addInput(new Form_Textarea( + 'custom_options_patch', + 'JSON Data', + ((array_get_path($pconfig, 'custom_options_patch') !== null) ? base64_decode($pconfig['custom_options_patch']) : null) +)); +$form->add($section); + $form->addGlobal(new Form_Input( 'act', '',
Apply it with the System Patches package, then go to Services > DHCP Server > Settings
, enter the JSON-formatted custom option data, then Save/Apply.
The custom option needs to be defined once and applied per interface. Here's an example that adds a vendor option (43) to the opt1 interface (get the name from Status > Interfaces
):
ShowHide
{ "option-def": [ { "space": "dhcp4", "name": "custom-option-vendor", "code": 43, "type": "string" } ], "option-data": { "opt1": [ { "name": "custom-option-vendor", "data": "01:04:0a:01:01:01" } ] } }
Updated by Dale Harron about 2 months ago
After a lot of experimentation and help from Marcos, I discovered it is important to know if the option is already defined or not. For that go to https://kea.readthedocs.io/en/kea-2.2.0/arm/dhcp4-srv.html#known-rfc-violations.
Look up the option and if it is already defined do not include the option-def portion because it is already defined.
"option-def": [
{
"space": "dhcp4",
"name": "custom-option-vendor",
"code": 43,
"type": "string"
}
],
If you wish to define the same option on multiple interfaces, simply cascade them with a comma, so the JSON sample now becomes (option 114 as an example):
{
"option-data": {
"opt4": [
{
"name": "v4-captive-portal",
"data": “https://sub4.domain.com:8007/rfc8910.php?zone=vlan30”
}
],
"opt5": [
{
"name": "v4-captive-portal",
"data": “https://sub5.domain.com:8009/rfc8910.php?zone=vlan40”
}
]
}
}
Updated by Jim Pingle about 1 month ago
- Has duplicate Feature #13422: Add a 'type' field to the DHCPv6 server Additional BOOTP/DHCP Options added