net/frr: add route-maps to OSPF (#1360)

This commit is contained in:
Michael 2019-06-23 20:42:37 +02:00 committed by Franco Fichtner
parent 9c4b22815d
commit 26bfd491d7
9 changed files with 193 additions and 6 deletions

View File

@ -1,5 +1,5 @@
PLUGIN_NAME= frr
PLUGIN_VERSION= 1.10
PLUGIN_VERSION= 1.11
PLUGIN_COMMENT= The FRRouting Protocol Suite
PLUGIN_DEPENDS= frr6 ruby
PLUGIN_MAINTAINER= franz.fabian.94@gmail.com

View File

@ -11,6 +11,10 @@ switching and routing, Internet access routers, and Internet peering.
Plugin Changelog
================
1.11
* Add route-map support to redistribution in OSPF
1.10
* XMLRPC sync support

View File

@ -2,6 +2,7 @@
/*
* Copyright (C) 2017 Fabian Franz
* Copyright (C) 2019 Michael Muenz <m.muenz@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -47,6 +48,10 @@ class OspfsettingsController extends ApiMutableModelControllerBase
{
return $this->searchBase('prefixlists.prefixlist', array("enabled", "name", "seqnumber", "action", "network" ));
}
public function searchRoutemapAction()
{
return $this->searchBase('routemaps.routemap', array("enabled", "name", "action", "id", "match2", "set"));
}
public function getNetworkAction($uuid = null)
{
$this->sessionClose();
@ -62,6 +67,11 @@ class OspfsettingsController extends ApiMutableModelControllerBase
$this->sessionClose();
return $this->getBase('prefixlist', 'prefixlists.prefixlist', $uuid);
}
public function getRoutemapAction($uuid = null)
{
$this->sessionClose();
return $this->getBase('routemap', 'routemaps.routemap', $uuid);
}
public function addNetworkAction()
{
return $this->addBase('network', 'networks.network');
@ -74,6 +84,10 @@ class OspfsettingsController extends ApiMutableModelControllerBase
{
return $this->addBase('prefixlist', 'prefixlists.prefixlist');
}
public function addRoutemapAction()
{
return $this->addBase('routemap', 'routemaps.routemap');
}
public function delNetworkAction($uuid)
{
return $this->delBase('networks.network', $uuid);
@ -86,6 +100,10 @@ class OspfsettingsController extends ApiMutableModelControllerBase
{
return $this->delBase('prefixlists.prefixlist', $uuid);
}
public function delRoutemapAction($uuid)
{
return $this->delBase('routemaps.routemap', $uuid);
}
public function setNetworkAction($uuid)
{
return $this->setBase('network', 'networks.network', $uuid);
@ -98,6 +116,10 @@ class OspfsettingsController extends ApiMutableModelControllerBase
{
return $this->setBase('prefixlist', 'prefixlists.prefixlist', $uuid);
}
public function setRoutemapAction($uuid)
{
return $this->setBase('routemap', 'routemaps.routemap', $uuid);
}
public function toggleNetworkAction($uuid)
{
return $this->toggleBase('networks.network', $uuid);
@ -110,4 +132,8 @@ class OspfsettingsController extends ApiMutableModelControllerBase
{
return $this->toggleBase('prefixlists.prefixlist', $uuid);
}
public function toggleRoutemapAction($uuid)
{
return $this->toggleBase('routemaps.routemap', $uuid);
}
}

View File

@ -35,6 +35,7 @@ class OspfController extends \OPNsense\Base\IndexController
$this->view->formDialogEditNetwork = $this->getForm("dialogEditOSPFNetwork");
$this->view->formDialogEditInterface = $this->getForm("dialogEditOSPFInterface");
$this->view->formDialogEditPrefixLists = $this->getForm("dialogEditOSPFPrefixLists");
$this->view->formDialogEditRouteMaps = $this->getForm("dialogEditOSPFRouteMaps");
$this->view->pick('OPNsense/Quagga/ospf');
}
}

View File

@ -0,0 +1,38 @@
<form>
<field>
<id>routemap.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
</field>
<field>
<id>routemap.name</id>
<label>Name</label>
<type>text</type>
<help>Route-map name to match and set your patterns, it will be enabled via redistribution.</help>
</field>
<field>
<id>routemap.action</id>
<label>Action</label>
<type>select_multiple</type>
<help>Set permit for match or deny to negate the rule.</help>
</field>
<field>
<id>routemap.id</id>
<label>ID</label>
<type>text</type>
<help>Route-map ID between 10 and 99. Be aware that the sorting will be done under the hood, so when you add an entry between it get's to the right position</help>
</field>
<field>
<id>routemap.match2</id>
<label>Prefix List</label>
<type>select_multiple</type>
<style>tokenize</style>
<allownew>true</allownew>
</field>
<field>
<id>routemap.set</id>
<label>Set</label>
<type>text</type>
<help>Free text field for your set, please be careful! You can set e.g. "local-preference 300" or "community 1:1" (http://docs.frrouting.org/en/latest/routemap.html#route-map-set-command)</help>
</field>
</form>

View File

@ -26,6 +26,12 @@
<help><![CDATA[Select other routing sources, which should be redistributed to the other nodes.]]></help>
<hint>Type or select a route source.</hint>
</field>
<field>
<id>ospf.redistributemap</id>
<label>Redistribution Map</label>
<type>dropdown</type>
<help>Route Map to set for Redistribution.</help>
</field>
<field>
<id>ospf.originate</id>
<label>Advertise Default Gateway</label>

View File

@ -47,6 +47,19 @@
<static>Statically configured routes</static>
</OptionValues>
</redistribute>
<redistributemap type="ModelRelationField">
<Model>
<template>
<source>OPNsense.quagga.ospf</source>
<items>routemaps.routemap</items>
<display>name</display>
<group>name</group>
</template>
</Model>
<ValidationMessage>Related Route-Map item not found</ValidationMessage>
<Multiple>N</Multiple>
<Required>N</Required>
</redistributemap>
<networks>
<network type="ArrayField">
<enabled type="BooleanField">
@ -223,5 +236,45 @@
</network>
</prefixlist>
</prefixlists>
<routemaps>
<routemap type="ArrayField">
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<name type="TextField">
<default></default>
<Required>Y</Required>
</name>
<action type="OptionField">
<Required>Y</Required>
<OptionValues>
<permit>Permit</permit>
<deny>Deny</deny>
</OptionValues>
</action>
<id type="IntegerField">
<default></default>
<Required>Y</Required>
<MinimumValue>10</MinimumValue>
<MaximumValue>99</MaximumValue>
</id>
<match2 type="ModelRelationField">
<Model>
<template>
<source>OPNsense.quagga.ospf</source>
<items>prefixlists.prefixlist</items>
<display>name</display>
</template>
</Model>
<ValidationMessage>Related item not found</ValidationMessage>
<Multiple>N</Multiple>
<Required>N</Required>
</match2>
<set type="TextField">
<Required>N</Required>
</set>
</routemap>
</routemaps>
</items>
</model>

View File

@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
<li><a data-toggle="tab" href="#networks">{{ lang._('Networks') }}</a></li>
<li><a data-toggle="tab" href="#interfaces">{{ lang._('Interfaces') }}</a></li>
<li><a data-toggle="tab" href="#prefixlists">{{ lang._('Prefix Lists') }}</a></li>
<li><a data-toggle="tab" href="#routemaps">{{ lang._('Route Maps') }}</a></li>
</ul>
<div class="tab-content content-box tab-content">
<div id="general" class="tab-pane fade in active">
@ -118,10 +119,36 @@ POSSIBILITY OF SUCH DAMAGE.
<tfoot>
<tr>
<td colspan="5"></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<!-- <button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button> -->
<button type="button" class="btn btn-xs reload_btn btn-primary"><span class="fa fa-refresh reloadAct_progress"></span> {{ lang._('Reload Service') }}</button>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<!-- <button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button> -->
<button type="button" class="btn btn-xs reload_btn btn-primary"><span class="fa fa-refresh reloadAct_progress"></span> {{ lang._('Reload Service') }}</button>
</td>
</tr>
</tfoot>
</table>
</div>
<div id="routemaps" class="tab-pane fade in">
<table id="grid-routemaps" class="table table-responsive" data-editDialog="DialogEditRouteMaps">
<thead>
<tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle" data-sortable="false">{{ lang._('Enabled') }}</th>
<th data-column-id="name" data-type="string" data-visible="true" data-sortable="true">{{ lang._('Name') }}</th>
<th data-column-id="seqnumber" data-type="string" data-visible="true" data-sortable="true">{{ lang._('Secquence Number') }}</th>
<th data-column-id="action" data-type="string" data-visible="true" data-sortable="false">{{ lang._('Action') }}</th>
<th data-column-id="network" data-type="string" data-visible="true" data-sortable="false">{{ lang._('Network') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button type="button" class="btn btn-xs reload_btn btn-primary"><span class="fa fa-refresh reloadAct_progress"></span> {{ lang._('Reload Service') }}</button>
</td>
</tr>
</tfoot>
@ -195,9 +222,20 @@ $( document ).ready(function() {
'options':{selection:false, multiSelect:false}
}
);
$("#grid-routemaps").UIBootgrid(
{ 'search':'/api/quagga/ospfsettings/searchRoutemap',
'get':'/api/quagga/ospfsettings/getRoutemap/',
'set':'/api/quagga/ospfsettings/setRoutemap/',
'add':'/api/quagga/ospfsettings/addRoutemap/',
'del':'/api/quagga/ospfsettings/delRoutemap/',
'toggle':'/api/quagga/ospfsettings/toggleRoutemap/',
'options':{selection:false, multiSelect:false}
}
);
});
</script>
{{ partial("layout_partials/base_dialog",['fields':formDialogEditNetwork,'id':'DialogEditNetwork','label':lang._('Edit Network')])}}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditInterface,'id':'DialogEditInterface','label':lang._('Edit Interface')])}}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditPrefixLists,'id':'DialogEditPrefixLists','label':lang._('Edit Prefix Lists')])}}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditRouteMaps,'id':'DialogEditRouteMaps','label':lang._('Edit Route Maps')])}}

View File

@ -45,7 +45,9 @@ router ospf
{% endif %}
{% if helpers.exists('OPNsense.quagga.ospf.redistribute') and OPNsense.quagga.ospf.redistribute != '' %}
{% for line in OPNsense.quagga.ospf.redistribute.split(',') %}
redistribute {{ line }}
{% set rmap = helpers.getUUID(OPNsense.quagga.ospf.redistributemap) %}
redistribute {{ line }} {% if helpers.exists('OPNsense.quagga.ospf.redistributemap') and OPNsense.quagga.ospf.redistributemap != '' %}route-map {{ rmap.name }}
{% endif %}
{% endfor %}{% endif %}
{% if helpers.exists('OPNsense.quagga.ospf.passiveinterfaces') and OPNsense.quagga.ospf.passiveinterfaces != '' %}
{% for line in OPNsense.quagga.ospf.passiveinterfaces.split(',') %}
@ -90,6 +92,25 @@ ip prefix-list {{ prefixlist.name }} seq {{ prefixlist.seqnumber }} {{ prefixlis
{% endfor %}
{% endif %}
!
{% if helpers.exists('OPNsense.quagga.ospf.routemaps.routemap') %}
{% for routemap in helpers.sortDictList(OPNsense.quagga.ospf.routemaps.routemap, 'name', 'id' ) %}
{% if routemap.enabled == '1' %}
route-map {{ routemap.name }} {{ routemap.action }} {{ routemap.id }}
{% if routemap.match2|default("") != "" %}
{% for prefixlist in routemap.match2.split(",") %}
{% set prefixlist_data = helpers.getUUID(prefixlist) %}
{% if 'match2' in routemap and routemap.match2 != '' %}
match ip address prefix-list {{ prefixlist_data.name }}
{% endif %}
{% endfor %}
{% endif %}
{% if routemap.set|default("") != "" %}
set {{ routemap.set }}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
!
line vty
!
{% endif %}