Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions net/frr/src/etc/inc/plugins.inc.d/frr.inc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ function frr_carp_enabled()
(string)$model->enablecarp == '1';
}

function frr_configure()
{
return [
'frr_sync' => ['frr_configure_do'],
];
}

function frr_configure_do($verbose = false)
{
$model = new \OPNsense\Quagga\General();
if (!$model->manual_config->isEmpty()) {
return;
}
(new \OPNsense\Core\Backend())->configdpRun('template reload', ['OPNsense/Quagga']);
}

function frr_firewall($fw)
{
global $config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
class ServiceController extends ApiMutableServiceControllerBase
{
protected static $internalServiceClass = '\OPNsense\Quagga\General';
protected static $internalServiceTemplate = 'OPNsense/Quagga';
// We intentionally only reload this template to allow manual_config for the templates
protected static $internalServiceTemplate = 'OPNsense/Quagga/rc_conf_d';
protected static $internalServiceEnabled = 'enabled';
protected static $internalServiceName = 'quagga';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
<id>general.enabled</id>
<label>Enable</label>
<type>checkbox</type>
<style>manual_config</style>
<help>This will activate the routing service. Without enabling it globally, none of the individual services will run.</help>
</field>
<field>
<id>general.manual_config</id>
<label>Manual config</label>
<type>checkbox</type>
<style>manual_config</style>
<advanced>true</advanced>
<help>Disable configuration file generation and manage the file (/usr/local/etc/frr/frr.conf) manually.</help>
</field>
<field>
<id>general.profile</id>
<label>Profile</label>
Expand All @@ -16,12 +25,14 @@
<id>general.enablecarp</id>
<label>Enable CARP Failover</label>
<type>checkbox</type>
<style>manual_config</style>
<help>This will activate the routing service only on the master device. The backup device will stop the service completely.</help>
</field>
<field>
<id>general.enablesnmp</id>
<label>Enable SNMP AgentX Support</label>
<type>checkbox</type>
<style>manual_config</style>
<help>This will activate support for Net-SNMP AgentX.</help>
</field>
<field>
Expand All @@ -40,6 +51,7 @@
<id>general.fwrules</id>
<label>Firewall rules</label>
<type>checkbox</type>
<style>manual_config</style>
<help>Enable automatically created firewall rules, when additional policies are needed, disable this and define your own custom policies in the Firewall section.</help>
</field>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* Copyright (C) 2026 Deciso B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, OR BUSINESS
* INTERRUPTION HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

namespace OPNsense\System\Status;

use OPNsense\Quagga\General;
use OPNsense\System\AbstractStatus;
use OPNsense\System\SystemStatusCode;

class FrrManualConfigStatus extends AbstractStatus
{
public function __construct()
{
$this->internalPriority = 2;
$this->internalPersistent = true;
$this->internalIsBanner = true;
$this->internalTitle = gettext('FRR manual configuration');
$this->internalScope = [
'/ui/quagga/*'
];
}

public function collectStatus()
{
if (!(new General())->manual_config->isEmpty()) {
$this->internalMessage = gettext(
'Manual FRR configuration is enabled. Configuration file generation is disabled. Settings configured here may no longer affect the active FRR configuration.'
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to hide configuration entries in the menu when manual mode is selected, we have options for that now and it avoids throwing messages on each page one can't use anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same but the issue is each daemon has its on model with its own "enabled" key. So we either have to reflect these or do lots of javascript magic to hide everything except enabled on every page.

This here definitely needs some more thought.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't planning in hiding options in the forms, I was thinking of hiding these options in the menu when their not used. We just need to move some glue to the menu system in order to support that, but I think we have all we need already.

When I have a bit of time, I can give it a shot.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont we have to reflect all enabled keys inside the frr general model as volatile fields? If the whole daemon specific menu items hide completely there is no way for the user to change these anymore as they are still owned by the rc.d script which is still regenerated by the template system here:

if helpers.exists('OPNsense.quagga.ospf.enabled') and OPNsense.quagga.ospf.enabled == '1' %} ospfd{% endif %}{%

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably have to think this through before committing anything, I assume the intention of the general "use manual config" option is to not write any configurations at all anymore, which the template system isn't very helpful in achieving due to some different spots flushing them out (e.g. boot).

For KEA this was rather easy as it's not bound to the template system, but our current template generation language doesn't really offer the flexibility yet which we would need in this particular case.

Logically, we would like to have some "break" on the template generation to skip it when not specifically requested and have the menu system cope with the options that are not relevant when in manual mode (effectively making the service boilerplate only responsible for the usual rc stuff).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think that's what the PR mostly offers by splitting the rc.conf template into a subdirectory. It's pretty effective although we have more boilerplate in the plugin backend to pull this off, but it's also not different from Kea or other legacy services.

A more unified template approach would be nice to have as an additional stage in the reconfigureAction() but it requires a bit of preparation and unification between services that should to use it. There are already a few.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, a bootup will still regenerate the frr.conf and vtysh.conf files, which is likely unintended when the user manages its own set of settings.

We could smarten the +TARGETS construction a bit to bail-out of the "generate all unconditional" option to solve that part of the puzzle, using the subdirectory for the rc part is indeed a practical boundary to use for splitting the functions.

Just need to think about this for a bit, as a general pattern, I think it makes sense to have some easy glue to support this scenario.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thank you. No rush here at all. I'll leave this open until there is a good way forward.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, a bootup will still regenerate the frr.conf and vtysh.conf files, which is likely unintended when the user manages its own set of settings.

Fair point. There are a number of ways to deal with this :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "make upgrade" of a plugin also regenerates all templates unconditionally. I don't know if that's the same path as boot.

$this->internalStatus = SystemStatusCode::NOTICE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<Default>0</Default>
<Required>Y</Required>
</enabled>
<manual_config type="BooleanField"/>
<profile type="OptionField">
<Required>Y</Required>
<Default>traditional</Default>
Expand Down
24 changes: 24 additions & 0 deletions net/frr/src/opnsense/mvc/app/views/OPNsense/Quagga/general.volt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ POSSIBILITY OF SUCH DAMAGE.
updateServiceControlUI('quagga');
}
});

/* Manual configuration, hide all config elements except manual_config fields */
$("#general\\.manual_config").change(function() {
let manual_config = $(this).is(':checked');

if (manual_config) {
if (!$("#show_advanced_frm_general_settings").hasClass('fa-toggle-on')) {
/* enforce advanced mode so the user notices the checkbox */
$("#show_advanced_frm_general_settings").click();
}

$("#frm_general_settings").find('tr').each(function() {
if ($(this).find('.manual_config').length == 0) {
$(this).hide();
} else {
$(this).show();
}
});
} else {
$("#frm_general_settings").find('tr').show();
}

$('.selectpicker').selectpicker('refresh');
});
});
</script>

Expand Down
3 changes: 3 additions & 0 deletions net/frr/src/opnsense/scripts/frr/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ chown -R $user:$group /var/run/frr
touch /var/log/frr.log
chown $user:$group /var/log/frr.log

# Reload templates here since we allow manual_config
/usr/local/sbin/pluginctl -c frr_sync

# register Security Associations
/usr/local/opnsense/scripts/frr/register_sas

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
frr:/etc/rc.conf.d/frr
frr.conf:/usr/local/etc/frr/frr.conf
vtysh.conf:/usr/local/etc/frr/vtysh.conf
ospf6d_carp.conf:/usr/local/etc/frr/ospf6d_carp.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
frr:/etc/rc.conf.d/frr