Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/frr: Add BGP/OSPF/OSPF6 route redistribution with route-map feature #4578

Merged
merged 9 commits into from
Mar 21, 2025
2 changes: 2 additions & 0 deletions net/frr/pkg-descr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Plugin Changelog

1.44

* Add route-map functionality to route redistribution in bgp (opnsense/plugins/issues/4570)
* Add route-map functionality to route redistribution in ospf/ospf6 (opnsense/plugins/issues/4580)
* Add BGP remote-as internal and external (opnsense/plugins/issues/4609)

1.43
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,31 @@ public function setPeergroupAction($uuid)
return $this->setBase('peergroup', 'peergroups.peergroup', $uuid);
}

public function searchRedistributionAction()
{
return $this->searchBase('redistributions.redistribution');
}

public function getRedistributionAction($uuid = null)
{
return $this->getBase('redistribution', 'redistributions.redistribution', $uuid);
}

public function addRedistributionAction()
{
return $this->addBase('redistribution', 'redistributions.redistribution');
}

public function delRedistributionAction($uuid)
{
return $this->delBase('redistributions.redistribution', $uuid);
}

public function setRedistributionAction($uuid)
{
return $this->setBase('redistribution', 'redistributions.redistribution', $uuid);
}

public function toggleCommunitylistAction($uuid)
{
return $this->toggleBase('communitylists.communitylist', $uuid);
Expand Down Expand Up @@ -216,4 +241,10 @@ public function togglePeergroupAction($uuid)
{
return $this->toggleBase('peergroups.peergroup', $uuid);
}

public function toggleRedistributionAction($uuid)
{
return $this->toggleBase('redistributions.redistribution', $uuid);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,29 @@ public function toggleRoutemapAction($uuid)
{
return $this->toggleBase('routemaps.routemap', $uuid);
}
public function searchRedistributionAction()
{
return $this->searchBase('redistributions.redistribution');
}
public function getRedistributionAction($uuid = null)
{
return $this->getBase('redistribution', 'redistributions.redistribution', $uuid);
}
public function addRedistributionAction()
{
return $this->addBase('redistribution', 'redistributions.redistribution');
}
public function delRedistributionAction($uuid)
{
return $this->delBase('redistributions.redistribution', $uuid);
}
public function setRedistributionAction($uuid)
{
return $this->setBase('redistribution', 'redistributions.redistribution', $uuid);
}
public function toggleRedistributionAction($uuid)
{
return $this->toggleBase('redistributions.redistribution', $uuid);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,30 @@ public function toggleRoutemapAction($uuid)
{
return $this->toggleBase('routemaps.routemap', $uuid);
}

public function searchRedistributionAction()
{
return $this->searchBase('redistributions.redistribution');
}
public function getRedistributionAction($uuid = null)
{
return $this->getBase('redistribution', 'redistributions.redistribution', $uuid);
}
public function addRedistributionAction()
{
return $this->addBase('redistribution', 'redistributions.redistribution');
}
public function delRedistributionAction($uuid)
{
return $this->delBase('redistributions.redistribution', $uuid);
}
public function setRedistributionAction($uuid)
{
return $this->setBase('redistribution', 'redistributions.redistribution', $uuid);
}
public function toggleRedistributionAction($uuid)
{
return $this->toggleBase('redistributions.redistribution', $uuid);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public function indexAction()
$this->view->formDialogEditBGPPeergroups = $this->getForm("dialogEditBGPPeergroups");
$this->view->formGridEditBGPPeergroups = $this->getFormGrid("dialogEditBGPPeergroups");

$this->view->formDialogEditRedistribution = $this->getForm("dialogEditRedistribution");
$this->view->formGridEditRedistribution = $this->getFormGrid("dialogEditRedistribution");

$this->view->pick('OPNsense/Quagga/bgp');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function indexAction()
$this->view->formDialogEditRouteMaps = $this->getForm("dialogEditOSPF6RouteMaps");
$this->view->formGridEditRouteMaps = $this->getFormGrid("dialogEditOSPF6RouteMaps");

$this->view->formDialogEditRedistribution = $this->getForm("dialogEditRedistribution");
$this->view->formGridEditRedistribution = $this->getFormGrid("dialogEditRedistribution");

$this->view->pick('OPNsense/Quagga/ospf6');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function indexAction()
$this->view->formDialogEditRouteMaps = $this->getForm("dialogEditOSPFRouteMaps");
$this->view->formGridEditRouteMaps = $this->getFormGrid("dialogEditOSPFRouteMaps");

$this->view->formDialogEditRedistribution = $this->getForm("dialogEditRedistribution");
$this->view->formGridEditRedistribution = $this->getFormGrid("dialogEditRedistribution");

$this->view->pick('OPNsense/Quagga/ospf');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,4 @@
<type>checkbox</type>
<help>Enable extended logging of BGP neighbor changes.</help>
</field>
<field>
<id>bgp.redistribute</id>
<label>Route Redistribution</label>
<type>select_multiple</type>
<help>Select routing sources to redistribute to other nodes.</help>
</field>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<form>
<field>
<id>redistribution.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<grid_view>
<width>6em</width>
<type>boolean</type>
<formatter>rowtoggle</formatter>
</grid_view>
</field>
<field>
<id>redistribution.redistribute</id>
<label>Route Redistribution</label>
<type>dropdown</type>
<help>Select routing sources to redistribute to other nodes.</help>
</field>
<field>
<id>redistribution.linkedRoutemap</id>
<label>Route-Map</label>
<type>dropdown</type>
<help>Optional Route-map to apply to this redistribution.</help>
</field>
<field>
<id>redistribution.description</id>
<label>Description</label>
<type>text</type>
<help>Optional description for this redistribution.</help>
<grid_view>
<visible>false</visible>
</grid_view>
</field>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@
<type>select_multiple</type>
<help>Select the interfaces where no OSPF packets should be sent.</help>
</field>
<field>
<id>ospf.redistribute</id>
<label>Route Redistribution</label>
<type>select_multiple</type>
<help>Select other routing sources to redistribute to other nodes.</help>
</field>
<field>
<id>ospf.redistributemap</id>
<label>Redistribution Map</label>
<type>dropdown</type>
<help>Route Map to set for Redistribution, can be used to send a specific network as advertisement when it is defined in a Prefix List attached to a Route Map.</help>
</field>
<field>
<id>ospf.logadjacencychanges</id>
<label>Log Adjacency Changes</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
<type>checkbox</type>
<help>Register CARP status monitor. When no neighbors are found, consider this node less attractive. Requires syslog enabled with “Debugging” logging. Incompatible with “Enable CARP Failover”.</help>
</field>
<field>
<id>ospf6.redistribute</id>
<label>Route Redistribution</label>
<type>select_multiple</type>
<help>Select other routing sources to redistribute to other nodes.</help>
</field>
<field>
<id>ospf6.redistributemap</id>
<label>Redistribution Map</label>
<type>dropdown</type>
<help>Route Map to set for Redistribution, can be used to send a specific network as advertisement when it is defined in a Prefix List attached to a Route Map.</help>
</field>
<field>
<id>ospf6.routerid</id>
<label>Router ID</label>
Expand Down
45 changes: 32 additions & 13 deletions net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/BGP.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<model>
<mount>//OPNsense/quagga/bgp</mount>
<description>BGP Routing configuration</description>
<version>1.0.9</version>
<version>1.1.0</version>
<items>
<enabled type="BooleanField">
<default>0</default>
Expand Down Expand Up @@ -37,18 +37,6 @@
<default></default>
<Required>N</Required>
</networks>
<redistribute type="OptionField">
<Required>N</Required>
<multiple>Y</multiple>
<default></default>
<OptionValues>
<ospf>Open Shortest Path First (OSPF)</ospf>
<connected>Connected routes (directly attached subnet or host)</connected>
<kernel>Kernel routes (not installed via the zebra RIB)</kernel>
<rip>Routing Information Protocol (RIP)</rip>
<static>Statically configured routes</static>
</OptionValues>
</redistribute>
<neighbors>
<neighbor type="ArrayField">
<enabled type="BooleanField">
Expand Down Expand Up @@ -493,5 +481,36 @@
</linkedRoutemapOut>
</peergroup>
</peergroups>
<redistributions>
<redistribution type="ArrayField">
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<description type="DescriptionField"/>
<redistribute type="OptionField">
<Required>Y</Required>
<Default>connected</Default>
<OptionValues>
<ospf>Open Shortest Path First (OSPF)</ospf>
<connected>Connected routes (directly attached subnet or host)</connected>
<kernel>Kernel routes (not installed via the zebra RIB)</kernel>
<rip>Routing Information Protocol (RIP)</rip>
<static>Statically configured routes</static>
</OptionValues>
</redistribute>
<linkedRoutemap type="ModelRelationField">
<Model>
<template>
<source>OPNsense.quagga.bgp</source>
<items>routemaps.routemap</items>
<display>name</display>
<group>name</group>
</template>
</Model>
<ValidationMessage>Related Route-Map item not found</ValidationMessage>
</linkedRoutemap>
</redistribution>
</redistributions>
</items>
</model>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/*
* Copyright (C) 2025 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 and the following disclaimer 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\Quagga\Migrations;

use OPNsense\Base\BaseModelMigration;
use OPNsense\Core\Config;

class M1_1_0 extends BaseModelMigration
{
public function run($model)
{
$config = Config::getInstance()->object();

if ($model->getNodeByReference('redistributions') === null) {
$model->addChild('redistributions');
}
$redistributions = $model->getNodeByReference('redistributions.redistribution');

// We migrate multiple models at the same time
$protocols = ['bgp', 'ospf', 'ospf6'];

foreach ($protocols as $protocol) {
if (isset($config->OPNsense->quagga->{$protocol})) {
$this->migrateRedistribute(
$redistributions,
$config->OPNsense->quagga->{$protocol},
$protocol
);
}
}
}

private function migrateRedistribute($redistributions, $configNode, $protocol)
{
if (!$configNode || empty($configNode->redistribute)) {
return;
}

$redistributeValues = explode(',', (string)$configNode->redistribute);
$redistributemap = isset($configNode->redistributemap) ? (string)$configNode->redistributemap : '';

if ($redistributions === null) {
$redistributions = $model->addChild('redistributions');
}

// Collect existing redistribution values to prevent duplicates
$existingRedistributions = [];
foreach ($redistributions->iterateItems() as $existing) {
if (!empty((string)$existing->redistribute)) {
$existingRedistributions[] = (string)$existing->redistribute;
}
}

foreach ($redistributeValues as $value) {
$value = trim($value);
if (empty($value) || in_array($value, $existingRedistributions, true)) {
continue;
}

// Create a new redistribution entry
$redistributionNode = $redistributions->add();
$redistributionNode->enabled = '1';
$redistributionNode->description = "Migrated route redistribution ($protocol)";
$redistributionNode->redistribute = $value;
$redistributionNode->linkedRoutemap = !empty($redistributemap) ? $redistributemap : '';
}
}

// Model is saved by 'run_migrations.php'
}
Loading