dnsmasq: Require interface when ra_mode is selected due to ra-param interface requirement. (#8482)

* dnsmasq: Require interface when ra_mode is selected due to ra-param interface requirement. Hide ra-param in dialog when ra_mode is default, since then the global enable_ra defaults are used instead.

* Update src/opnsense/mvc/app/controllers/OPNsense/Dnsmasq/forms/dialogDHCPrange.xml

Co-authored-by: Franco Fichtner <franco@opnsense.org>

* Update src/opnsense/mvc/app/models/OPNsense/Dnsmasq/Dnsmasq.php

Co-authored-by: Franco Fichtner <franco@opnsense.org>

* Update src/opnsense/mvc/app/views/OPNsense/Dnsmasq/settings.volt

Co-authored-by: Franco Fichtner <franco@opnsense.org>

---------

Co-authored-by: Franco Fichtner <franco@opnsense.org>
This commit is contained in:
Monviech 2025-03-25 11:48:12 +01:00 committed by GitHub
parent cd3c2eefd2
commit 0538ef324e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 17 deletions

View File

@ -27,8 +27,8 @@
<id>range.constructor</id>
<label>Constructor</label>
<type>dropdown</type>
<style>selectpicker style_dhcpv6</style>
<help>Interface to use to calculate the proper range, when selected, a range may be specified as a suffix (e.g. ::1, ::400)</help>
<style>selectpicker</style>
<help>Interface to use to calculate a DHCPv6 or RA range. Start address can then be specified as a suffix (e.g. ::, ::1 or ::400).</help>
<grid_view>
<visible>false</visible>
</grid_view>
@ -60,7 +60,7 @@
<label>RA Priority</label>
<type>dropdown</type>
<help>Priority of the RA announcements.</help>
<style>selectpicker style_dhcpv6</style>
<style>selectpicker style_ra</style>
<grid_view>
<visible>false</visible>
</grid_view>
@ -69,7 +69,7 @@
<id>range.ra_mtu</id>
<label>RA MTU</label>
<type>text</type>
<style>style_dhcpv6</style>
<style>style_ra</style>
<help>Optional MTU to send to clients via Router Advertisements. If unsure leave empty.</help>
<grid_view>
<visible>false</visible>
@ -80,7 +80,7 @@
<label>RA Interval</label>
<type>text</type>
<hint>60</hint>
<style>style_dhcpv6</style>
<style>style_ra</style>
<help>Time (seconds) between Router Advertisements.</help>
<grid_view>
<visible>false</visible>
@ -91,7 +91,7 @@
<label>RA Router Lifetime</label>
<type>text</type>
<hint>1200</hint>
<style>style_dhcpv6</style>
<style>style_ra</style>
<help>The lifetime of the route may be changed or set to zero, which allows a router to advertise prefixes but not a route via itself. When using HA, setting a short timespan here is adviced for faster IPv6 failover. A good combination could be 10 seconds RA interval and 30 seconds RA router lifetime. Going lower than that can pose issues in busy networks.</help>
<grid_view>
<visible>false</visible>

View File

@ -161,6 +161,15 @@ class Dnsmasq extends BaseModel
);
}
if ($range->interface->isEmpty() && !$range->ra_mode->isEmpty()) {
$messages->appendMessage(
new Message(
gettext("Selecting an RA Mode requires an interface."),
$key . ".interface"
)
);
}
// Validate RA mode combinations
$valid_ra_mode_combinations = [
['ra-names', 'slaac'],

View File

@ -125,15 +125,29 @@
let selected_tab = window.location.hash != "" ? window.location.hash : "#general";
$('a[href="' +selected_tab + '"]').click();
$("#range\\.start_addr").on("keyup change", function() {
let value = $(this).val() || "";
if (value.includes(":")) {
$(".style_dhcpv6").closest('tr').show();
$(".style_dhcpv4").closest('tr').hide();
} else {
$(".style_dhcpv6").closest('tr').hide();
$(".style_dhcpv4").closest('tr').show();
}
$("#range\\.start_addr, #range\\.ra_mode").on("keyup change", function () {
const addr = $("#range\\.start_addr").val() || "";
const ra_mode = String($("#range\\.ra_mode").val() || "").trim();
const styleVisibility = [
{
class: "style_dhcpv4",
visible: !addr.includes(":")
},
{
class: "style_dhcpv6",
visible: addr.includes(":")
},
{
class: "style_ra",
visible: ra_mode !== ""
}
];
styleVisibility.forEach(style => {
const elements = $("." + style.class).closest("tr");
style.visible ? elements.show() : elements.hide();
});
});
});

View File

@ -174,8 +174,9 @@ constructor:{{helpers.physical_interface(dhcp_range.constructor)}},
domain={{ dhcp_range.domain }},{{dhcp_range.start_addr}},{{dhcp_range.end_addr}}
{% endif %}
{% if dhcp_range.ra_mode %}
ra-param={{ helpers.physical_interface(dhcp_range.constructor) }}
{#- Only gets added if a custom ra_mode is chosen, otherwise the global defaults of enable-ra are used. -#}
{% if dhcp_range.ra_mode and dhcp_range.interface %}
ra-param={{ helpers.physical_interface(dhcp_range.interface) }}
{%- if dhcp_range.ra_mtu %},mtu:{{ dhcp_range.ra_mtu }}{% endif -%}
{%- if dhcp_range.ra_priority %},{{ dhcp_range.ra_priority }}{% endif -%},
{%- if dhcp_range.ra_interval %}{{ dhcp_range.ra_interval }}{% else %}60{% endif -%},