From 05032ebfc7f4a7bf2619bdd31afa179d722952f8 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 7 Apr 2024 15:55:57 +0200 Subject: [PATCH] Allow setting client class test expression for option. --- .../OPNsense/Kea/forms/dialogOption4.xml | 8 +++ .../mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml | 34 ++-------- .../templates/OPNsense/Kea/kea-dhcp4.conf | 64 +++++++++++-------- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogOption4.xml b/src/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogOption4.xml index 964f7129524..d44b76c4ae0 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogOption4.xml +++ b/src/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogOption4.xml @@ -4,6 +4,13 @@ text + + option.test + + text + true + test expression.]]> + option.code @@ -31,6 +38,7 @@ text DHCP option types. Only applies if Type is record.]]> + option.data diff --git a/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml b/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml index ea01bf4f098..0524882c48c 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml @@ -40,6 +40,9 @@ + + + Y @@ -86,39 +89,14 @@ record + Y + , - + Y - - - - Y - - - Duplicate entry exists - UniqueConstraint - - - - - - - diff --git a/src/opnsense/service/templates/OPNsense/Kea/kea-dhcp4.conf b/src/opnsense/service/templates/OPNsense/Kea/kea-dhcp4.conf index 4b4757de821..7509e00e50c 100644 --- a/src/opnsense/service/templates/OPNsense/Kea/kea-dhcp4.conf +++ b/src/opnsense/service/templates/OPNsense/Kea/kea-dhcp4.conf @@ -49,41 +49,55 @@ }{% if not loop.last %},{% endif +%} {% endfor %} ], +{% for option in options %} +{% if loop.first %} + "client-classes": [ +{%- endif +%} + { + "name": {{option.name|tojson}}, + {%- if option.test +%} + "test": {{option.test|tojson}}, + {%- else +%} + "test": "0 == 0", + {%- endif +%} + "only-if-required": true, + "option-data": [ + {%- if option.space == 'vendor_encapsulated_options_space' +%} + { + "name": "vendor-encapsulated-options", + "always-send": true + }, + {%- endif +%} + { + "name": {{option.name|tojson}}, + "space": {{option.space.replace('_','-')|tojson}}, + "code": {{option.code|int|tojson}}, + "data": {{option.data|tojson}} + } + ] + }{% if not loop.last %},{% endif +%} +{% if loop.last %} + ], +{% endif %} +{% endfor %} "subnet4": [ -{% for subnet in helpers.toList('OPNsense.Kea.dhcp4.subnets.subnet4') %} +{%- for subnet in helpers.toList('OPNsense.Kea.dhcp4.subnets.subnet4') %} +{% set additional_options = (subnet.additional_options|default('')).split(',') +%} { "id": {{loop.index}}, "subnet": "{{subnet.subnet}}", + "require-client-classes": [ + {%- for option in options if option['@uuid'] in additional_options +%} + {{option.name|tojson}}{% if not loop.last %},{% endif %} + {%- endfor +%} + ], "option-data": [ - -{% set ns = namespace(options_printed=false) %} {% for od_attr in (subnet.option_data|list + option_data_defaults|list)|unique if subnet.option_data[od_attr]|length > 1 or od_attr in option_data_defaults %} -{% set ns.options_printed = True %} { "name": {{od_attr.replace('_','-')|tojson}}, "data": {{subnet.option_data[od_attr]|default(option_data_defaults[od_attr])|tojson}} }{% if not loop.last %},{% endif +%} -{%- endfor %} - -{%- set additional_options = (subnet.additional_options|default('')).split(',') -%} - -{%- for option in helpers.toList('OPNsense.Kea.dhcp4.options.option') if option['@uuid'] in additional_options %} -{%- set print_leading_comma = loop.first and ns.options_printed -%} -{%- if print_leading_comma %},{% endif %} - -{% if option.space == 'vendor_encapsulated_options_space' %} - { - "name": "vendor-encapsulated-options", - "always-send": true - }, -{% endif %} - { - "name": {{option.name|tojson}}, - "space": {{option.space.replace('_','-')|tojson}}, - "code": {{option.code|int|tojson}}, - "data": {{option.data|tojson}} - }{%- if not loop.last %},{% endif +%} -{% endfor %} +{%- endfor +%} ], "pools": [ {% for pool in (subnet.pools|default('')).split("\n") if pool|length > 1%}