From cd23cfce17c00aa900c4357589387fa01c5cd202 Mon Sep 17 00:00:00 2001 From: Monviech <79600909+Monviech@users.noreply.github.com> Date: Fri, 7 Mar 2025 08:23:18 +0100 Subject: [PATCH] dnsmasq: Use interface directly as tag in dhcp options (#8408) * dnsmasq: Use interface directly as tag in dhcp options * dnsmasq: Always add tag to interface since set is automatic when interface receives DHCP Broadcast. --- .../Dnsmasq/forms/dialogDHCPoption.xml | 8 +++++++- .../app/models/OPNsense/Dnsmasq/Dnsmasq.xml | 7 +++++++ .../templates/OPNsense/Dnsmasq/dnsmasq.conf | 20 ++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Dnsmasq/forms/dialogDHCPoption.xml b/src/opnsense/mvc/app/controllers/OPNsense/Dnsmasq/forms/dialogDHCPoption.xml index d9c46cc46..b1f11a8f1 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Dnsmasq/forms/dialogDHCPoption.xml +++ b/src/opnsense/mvc/app/controllers/OPNsense/Dnsmasq/forms/dialogDHCPoption.xml @@ -5,11 +5,17 @@ dropdown Option to offer to the client. + + option.interface + + dropdown + This adds a single interface as tag so this DHCP option can match the interface of a DHCP range. + option.tag select_multiple - If the optional tags are given then this option is only sent when all the tags are matched. + If the optional tags are given then this option is only sent when all the tags are matched. Can be optionally combined with an interface tag. option.value diff --git a/src/opnsense/mvc/app/models/OPNsense/Dnsmasq/Dnsmasq.xml b/src/opnsense/mvc/app/models/OPNsense/Dnsmasq/Dnsmasq.xml index a5cbcb0ef..7ab53cf2f 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Dnsmasq/Dnsmasq.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Dnsmasq/Dnsmasq.xml @@ -171,6 +171,13 @@ dnsmasq list dhcp_options Y + + Any + + /^(?!lo0$).*/ + + Y + diff --git a/src/opnsense/service/templates/OPNsense/Dnsmasq/dnsmasq.conf b/src/opnsense/service/templates/OPNsense/Dnsmasq/dnsmasq.conf index 1d8e3cfb0..2184a666a 100644 --- a/src/opnsense/service/templates/OPNsense/Dnsmasq/dnsmasq.conf +++ b/src/opnsense/service/templates/OPNsense/Dnsmasq/dnsmasq.conf @@ -132,7 +132,7 @@ set:{{dhcp_range.set_tag|replace('-','')}}, {% else %} {# IPv6 range #} dhcp-range={%if dhcp_range.interface -%} -{{helpers.physical_interface(dhcp_range.interface)}}, +tag:{{helpers.physical_interface(dhcp_range.interface)}}, {%- endif -%} {%- if dhcp_range.set_tag -%} set:{{dhcp_range.set_tag|replace('-','')}}, @@ -165,11 +165,21 @@ dhcp-host={{host.hwaddr}}{% if host.set_tag%},set:{{host.set_tag|replace('-','') {% set has_default=[] %} {% for option in helpers.toList('dnsmasq.dhcp_options') %} -dhcp-option{% if option.force == '1' %}-force{% endif %}={% if option.tag %}tag:{{option.tag.replace('-','').split(',')|join(',tag:')}},{% endif %}{{ option.option }},{{ option.value }} -{% if not option.tag and option.option == '6' %} -{%- do has_default.append(1) -%} -{%- endif -%} +{% set all_tags = [] %} +{% if option.tag %} +{% for tag in option.tag.replace('-','').split(',') %} +{% do all_tags.append('tag:' + tag) %} +{% endfor %} +{% endif %} +{% if option.interface %} +{% do all_tags.append('tag:' + helpers.physical_interface(option.interface)) %} +{% endif %} +dhcp-option{% if option.force == '1' %}-force{% endif %}={% if all_tags %}{{ all_tags|join(',') }},{% endif %}{{ option.option }},{{ option.value }} +{% if not option.tag and not option.interface and option.option == '6' %} +{% do has_default.append(1) %} +{% endif %} {% endfor %} + {% if not has_default %} # default dns mapped to this server (0.0.0.0) dhcp-option=6,0.0.0.0