Skip to content

Commit 05032eb

Browse files
committed
Allow setting client class test expression for option.
1 parent 4c56f7d commit 05032eb

File tree

3 files changed

+53
-53
lines changed

3 files changed

+53
-53
lines changed

src/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogOption4.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
<label>Name</label>
55
<type>text</type>
66
</field>
7+
<field>
8+
<id>option.test</id>
9+
<label>Client Class Test</label>
10+
<type>text</type>
11+
<advanced>true</advanced>
12+
<help><![CDATA[Only send this option if the client matches the given <a rel="help" href="https://kea.readthedocs.io/en/kea-2.2.0/arm/classify.html?highlight=test%20expressions#using-expressions-in-classification">test expression</a>.]]></help>
13+
</field>
714
<field>
815
<id>option.code</id>
916
<label>Code</label>
@@ -31,6 +38,7 @@
3138
<label>Record Types</label>
3239
<type>text</type>
3340
<help><![CDATA[Comma-separated list of <a rel="help" href="https://kea.readthedocs.io/en/latest/arm/dhcp4-srv.html#dhcp-types">DHCP option types</a>. Only applies if <b>Type</b> is <code>record</code>.]]></help>
41+
<style>record_types</style>
3442
</field>
3543
<field>
3644
<id>option.data</id>

src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
</check001>
4141
</Constraints>
4242
</name>
43+
<test type="TextField">
44+
<Default></Default>
45+
</test>
4346
<code type="IntegerField">
4447
<Required>Y</Required>
4548
</code>
@@ -86,39 +89,14 @@
8689
<check>record</check>
8790
</check001>
8891
</Constraints>
92+
<AsList>Y</AsList>
93+
<FieldSeparator>,</FieldSeparator>
8994
</record_types>
90-
<data type="TextField">
95+
<data type="TextField">
9196
<Required>Y</Required>
9297
</data>
9398
</option>
9499
</options>
95-
<client_classes>
96-
<client_class type="ArrayField">
97-
<name type="TextField">
98-
<Required>Y</Required>
99-
<Constraints>
100-
<check001>
101-
<ValidationMessage>Duplicate entry exists</ValidationMessage>
102-
<type>UniqueConstraint</type>
103-
</check001>
104-
</Constraints>
105-
</name>
106-
<test type="TextField"></test>
107-
<option type="ModelRelationField">
108-
<Multiple>Y</Multiple>
109-
<Model>
110-
<subnets>
111-
<source>OPNsense.Kea.KeaDhcpv4</source>
112-
<items>options.option</items>
113-
<display>name</display>
114-
</subnets>
115-
</Model>
116-
<ValidationMessage>Related option definition not found</ValidationMessage>
117-
<Required>Y</Required>
118-
<AsList>1</AsList>
119-
</option>
120-
</client_class>
121-
</client_classes>
122100
<subnets>
123101
<subnet4 type="ArrayField">
124102
<subnet type="NetworkField">

src/opnsense/service/templates/OPNsense/Kea/kea-dhcp4.conf

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,41 +49,55 @@
4949
}{% if not loop.last %},{% endif +%}
5050
{% endfor %}
5151
],
52+
{% for option in options %}
53+
{% if loop.first %}
54+
"client-classes": [
55+
{%- endif +%}
56+
{
57+
"name": {{option.name|tojson}},
58+
{%- if option.test +%}
59+
"test": {{option.test|tojson}},
60+
{%- else +%}
61+
"test": "0 == 0",
62+
{%- endif +%}
63+
"only-if-required": true,
64+
"option-data": [
65+
{%- if option.space == 'vendor_encapsulated_options_space' +%}
66+
{
67+
"name": "vendor-encapsulated-options",
68+
"always-send": true
69+
},
70+
{%- endif +%}
71+
{
72+
"name": {{option.name|tojson}},
73+
"space": {{option.space.replace('_','-')|tojson}},
74+
"code": {{option.code|int|tojson}},
75+
"data": {{option.data|tojson}}
76+
}
77+
]
78+
}{% if not loop.last %},{% endif +%}
79+
{% if loop.last %}
80+
],
81+
{% endif %}
82+
{% endfor %}
5283
"subnet4": [
53-
{% for subnet in helpers.toList('OPNsense.Kea.dhcp4.subnets.subnet4') %}
84+
{%- for subnet in helpers.toList('OPNsense.Kea.dhcp4.subnets.subnet4') %}
85+
{% set additional_options = (subnet.additional_options|default('')).split(',') +%}
5486
{
5587
"id": {{loop.index}},
5688
"subnet": "{{subnet.subnet}}",
89+
"require-client-classes": [
90+
{%- for option in options if option['@uuid'] in additional_options +%}
91+
{{option.name|tojson}}{% if not loop.last %},{% endif %}
92+
{%- endfor +%}
93+
],
5794
"option-data": [
58-
59-
{% set ns = namespace(options_printed=false) %}
6095
{% 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 %}
61-
{% set ns.options_printed = True %}
6296
{
6397
"name": {{od_attr.replace('_','-')|tojson}},
6498
"data": {{subnet.option_data[od_attr]|default(option_data_defaults[od_attr])|tojson}}
6599
}{% if not loop.last %},{% endif +%}
66-
{%- endfor %}
67-
68-
{%- set additional_options = (subnet.additional_options|default('')).split(',') -%}
69-
70-
{%- for option in helpers.toList('OPNsense.Kea.dhcp4.options.option') if option['@uuid'] in additional_options %}
71-
{%- set print_leading_comma = loop.first and ns.options_printed -%}
72-
{%- if print_leading_comma %},{% endif %}
73-
74-
{% if option.space == 'vendor_encapsulated_options_space' %}
75-
{
76-
"name": "vendor-encapsulated-options",
77-
"always-send": true
78-
},
79-
{% endif %}
80-
{
81-
"name": {{option.name|tojson}},
82-
"space": {{option.space.replace('_','-')|tojson}},
83-
"code": {{option.code|int|tojson}},
84-
"data": {{option.data|tojson}}
85-
}{%- if not loop.last %},{% endif +%}
86-
{% endfor %}
100+
{%- endfor +%}
87101
],
88102
"pools": [
89103
{% for pool in (subnet.pools|default('')).split("\n") if pool|length > 1%}

0 commit comments

Comments
 (0)