mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
Quagga / BGP: Add prefix lists, UX cleanup in neighbor configuration (#167)
* Update bgp.volt * Update BgpController.php * Update BgpController.php * Create dialogEditBGPPrefixLists.xml * Update dialogEditBGPNeighbor.xml * Update BGP.xml * Update BGP.xml * Update dialogEditBGPNeighbor.xml * Update dialogEditBGPNeighbor.xml * Update BgpController.php * Update bgp.volt * Update BGP.xml * Update bgpd.conf * Update bgpd.conf * Update bgpd.conf * Update bgpd.conf * Update BgpController.php * Update BGP.xml * Update BGP.xml * Update BGP.xml * Update bgp.volt
This commit is contained in:
@@ -81,7 +81,7 @@ class BgpController extends ApiMutableModelControllerBase
|
||||
$grid = new UIModelGrid($mdlBGP->neighbors->neighbor);
|
||||
return $grid->fetchBindRequest(
|
||||
$this->request,
|
||||
array("enabled", "address", "remoteas", "updatesource", "nexthopself", "defaultoriginate", "linkedRoutemapIn", "linkedRoutemapOut" )
|
||||
array("enabled", "address", "remoteas", "updatesource", "nexthopself", "defaultoriginate", "linkedPrefixlistIn", "linkedPrefixlistOut", "linkedRoutemapIn", "linkedRoutemapOut" )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -269,6 +269,99 @@ class BgpController extends ApiMutableModelControllerBase
|
||||
return array("result" => "failed");
|
||||
}
|
||||
|
||||
public function searchPrefixlistAction()
|
||||
{
|
||||
$this->sessionClose();
|
||||
$mdlBGP = $this->getModel();
|
||||
$grid = new UIModelGrid($mdlBGP->prefixlists->prefixlist);
|
||||
return $grid->fetchBindRequest(
|
||||
$this->request,
|
||||
array("enabled", "name", "seqnumber", "action", "network" )
|
||||
);
|
||||
}
|
||||
public function getPrefixlistAction($uuid = null)
|
||||
{
|
||||
$mdlBGP = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlBGP->getNodeByReference('prefixlists.prefixlist.' . $uuid);
|
||||
if ($node != null) {
|
||||
// return node
|
||||
return array("prefixlist" => $node->getNodes());
|
||||
}
|
||||
} else {
|
||||
$node = $mdlBGP->prefixlists->prefixlist->add();
|
||||
return array("prefixlist" => $node->getNodes());
|
||||
}
|
||||
return array();
|
||||
}
|
||||
public function addPrefixlistAction()
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost() && $this->request->hasPost("prefixlist")) {
|
||||
$result = array("result" => "failed", "validations" => array());
|
||||
$mdlBGP = $this->getModel();
|
||||
$node = $mdlBGP->prefixlists->prefixlist->Add();
|
||||
$node->setNodes($this->request->getPost("prefixlist"));
|
||||
$valMsgs = $mdlBGP->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
$fieldnm = str_replace($node->__reference, "prefixlist", $msg->getField());
|
||||
$result["validations"][$fieldnm] = $msg->getMessage();
|
||||
}
|
||||
if (count($result['validations']) == 0) {
|
||||
// save config if validated correctly
|
||||
$mdlBGP->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
unset($result['validations']);
|
||||
$result["result"] = "saved";
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function delPrefixlistAction($uuid)
|
||||
{
|
||||
$result = array("result" => "failed");
|
||||
if ($this->request->isPost()) {
|
||||
$mdlBGP = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
if ($mdlBGP->prefixlists->prefixlist->del($uuid)) {
|
||||
$mdlBGP->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result['result'] = 'deleted';
|
||||
} else {
|
||||
$result['result'] = 'not found';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function setPrefixlistAction($uuid)
|
||||
{
|
||||
if ($this->request->isPost() && $this->request->hasPost("prefixlist")) {
|
||||
$mdlNeighbor = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdlNeighbor->getNodeByReference('prefixlists.prefixlist.' . $uuid);
|
||||
if ($node != null) {
|
||||
$result = array("result" => "failed", "validations" => array());
|
||||
$prefixlistInfo = $this->request->getPost("prefixlist");
|
||||
$node->setNodes($prefixlistInfo);
|
||||
$valMsgs = $mdlNeighbor->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
$fieldnm = str_replace($node->__reference, "prefixlist", $msg->getField());
|
||||
$result["validations"][$fieldnm] = $msg->getMessage();
|
||||
}
|
||||
if (count($result['validations']) == 0) {
|
||||
// save config if validated correctly
|
||||
$mdlNeighbor->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result = array("result" => "saved");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array("result" => "failed");
|
||||
}
|
||||
|
||||
public function searchRoutemapAction()
|
||||
{
|
||||
$this->sessionClose();
|
||||
@@ -399,6 +492,11 @@ class BgpController extends ApiMutableModelControllerBase
|
||||
{
|
||||
return $this->toggle_handler($uuid, 'aspaths', 'aspath');
|
||||
}
|
||||
|
||||
public function togglePrefixlistAction($uuid)
|
||||
{
|
||||
return $this->toggle_handler($uuid, 'prefixlists', 'prefixlist');
|
||||
}
|
||||
|
||||
public function toggleRoutemapAction($uuid)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@ class BgpController extends \OPNsense\Base\IndexController
|
||||
$this->view->bgpForm = $this->getForm("bgp");
|
||||
$this->view->formDialogEditBGPNeighbor = $this->getForm("dialogEditBGPNeighbor");
|
||||
$this->view->formDialogEditBGPASPaths = $this->getForm("dialogEditBGPASPath");
|
||||
$this->view->formDialogEditBGPPrefixLists = $this->getForm("dialogEditBGPPrefixLists");
|
||||
$this->view->formDialogEditBGPRouteMaps = $this->getForm("dialogEditBGPRouteMaps");
|
||||
$this->view->pick('OPNsense/Quagga/bgp');
|
||||
}
|
||||
|
||||
+12
@@ -32,6 +32,18 @@
|
||||
<label>Send Defaultroute</label>
|
||||
<type>checkbox</type>
|
||||
</field>
|
||||
<field>
|
||||
<id>neighbor.linkedPrefixlistIn</id>
|
||||
<label>Prefix-List In</label>
|
||||
<type>dropdown</type>
|
||||
<help>Prefix-List for inbound direction</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>neighbor.linkedPrefixlistOut</id>
|
||||
<label>Prefix-List Out</label>
|
||||
<type>dropdown</type>
|
||||
<help>Prefix-List for outbound direction</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>neighbor.linkedRoutemapIn</id>
|
||||
<label>Route-Map In</label>
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<form>
|
||||
<field>
|
||||
<id>prefixlist.enabled</id>
|
||||
<label>Enabled</label>
|
||||
<type>checkbox</type>
|
||||
<help>Enable / Disable</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>prefixlist.name</id>
|
||||
<label>Name</label>
|
||||
<type>text</type>
|
||||
<help>The name of your Prefix-List, please choose one near to the result you want to achieve.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>prefixlist.seqnumber</id>
|
||||
<label>Number</label>
|
||||
<type>text</type>
|
||||
<help>The ACL sequence number (10-99)</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>prefixlist.action</id>
|
||||
<label>Action</label>
|
||||
<type>select_multiple</type>
|
||||
<help>Set permit for match or deny to negate the rule.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>prefixlist.network</id>
|
||||
<label>Network</label>
|
||||
<type>text</type>
|
||||
<help>The network pattern you want to match. You can also add "ge" or "le" additions after the network statement. It's not validated so please be careful!</help>
|
||||
</field>
|
||||
</form>
|
||||
@@ -65,12 +65,39 @@
|
||||
<default>0</default>
|
||||
<Required>N</Required>
|
||||
</defaultoriginate>
|
||||
<linkedPrefixlistIn type="ModelRelationField">
|
||||
<Model>
|
||||
<template>
|
||||
<source>OPNsense.quagga.bgp</source>
|
||||
<items>prefixlists.prefixlist</items>
|
||||
<display>name</display>
|
||||
<group>name</group>
|
||||
</template>
|
||||
</Model>
|
||||
<ValidationMessage>Related Prefix-List item not found</ValidationMessage>
|
||||
<Multiple>N</Multiple>
|
||||
<Required>N</Required>
|
||||
</linkedPrefixlistIn>
|
||||
<linkedPrefixlistOut type="ModelRelationField">
|
||||
<Model>
|
||||
<template>
|
||||
<source>OPNsense.quagga.bgp</source>
|
||||
<items>prefixlists.prefixlist</items>
|
||||
<display>name</display>
|
||||
<group>name</group>
|
||||
</template>
|
||||
</Model>
|
||||
<ValidationMessage>Related Prefix-List item not found</ValidationMessage>
|
||||
<Multiple>N</Multiple>
|
||||
<Required>N</Required>
|
||||
</linkedPrefixlistOut>
|
||||
<linkedRoutemapIn 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>
|
||||
@@ -83,6 +110,7 @@
|
||||
<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>
|
||||
@@ -117,6 +145,36 @@
|
||||
</as>
|
||||
</aspath>
|
||||
</aspaths>
|
||||
<prefixlists>
|
||||
<prefixlist type="ArrayField">
|
||||
<enabled type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>Y</Required>
|
||||
</enabled>
|
||||
<name type="TextField">
|
||||
<default></default>
|
||||
<Required>Y</Required>
|
||||
</name>
|
||||
<seqnumber type="IntegerField">
|
||||
<default></default>
|
||||
<Required>Y</Required>
|
||||
<MinimumValue>10</MinimumValue>
|
||||
<MaximumValue>99</MaximumValue>
|
||||
</seqnumber>
|
||||
<action type="OptionField">
|
||||
<default></default>
|
||||
<Required>Y</Required>
|
||||
<OptionValues>
|
||||
<permit>Permit</permit>
|
||||
<deny>Deny</deny>
|
||||
</OptionValues>
|
||||
</action>
|
||||
<network type="TextField">
|
||||
<default></default>
|
||||
<Required>Y</Required>
|
||||
</network>
|
||||
</prefixlist>
|
||||
</prefixlists>
|
||||
<routemaps>
|
||||
<routemap type="ArrayField">
|
||||
<enabled type="BooleanField">
|
||||
|
||||
@@ -31,7 +31,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
|
||||
<li class="active"><a data-toggle="tab" href="#general">{{ lang._('General') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#neighbors">{{ lang._('Neighbors') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#aspaths">{{ lang._('AS-Path Lists') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#aspaths">{{ lang._('AS Path Lists') }}</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">
|
||||
@@ -45,8 +46,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="neighbors" class="tab-pane fade in">
|
||||
<table id="grid-neighbors" class="table table-responsive" data-editDialog="DialogEditBGPNeighbor">
|
||||
<thead>
|
||||
@@ -57,8 +56,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
<th data-column-id="updatesource" data-type="string" data-visible="true">{{ lang._('Update Source Address') }}</th>
|
||||
<th data-column-id="nexthopself" data-type="string" data-formatter="rowtoggle">{{ lang._('Next Hop Self') }}</th>
|
||||
<th data-column-id="defaultoriginate" data-type="string" data-formatter="rowtoggle">{{ lang._('Default Originate') }}</th>
|
||||
<th data-column-id="linkedRoutemapIn" data-type="string" data-visible="true">{{ lang._('Route-Map Inbound') }}</th>
|
||||
<th data-column-id="linkedRoutemapOut" data-type="string" data-visible="true">{{ lang._('Route-Map Outbound') }}</th>
|
||||
<th data-column-id="linkedPrefixlistIn" data-type="string" data-visible="true">{{ lang._('Prefix List inbound') }}</th>
|
||||
<th data-column-id="linkedPrefixlistOut" data-type="string" data-visible="true">{{ lang._('Prefix List outbound') }}</th>
|
||||
<th data-column-id="linkedRoutemapIn" data-type="string" data-visible="true">{{ lang._('Route Map inbound') }}</th>
|
||||
<th data-column-id="linkedRoutemapOut" data-type="string" data-visible="true">{{ lang._('Route Map outbound') }}</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>
|
||||
@@ -76,7 +77,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="aspaths" class="tab-pane fade in">
|
||||
<table id="grid-aspaths" class="table table-responsive" data-editDialog="DialogEditBGPASPaths">
|
||||
<thead>
|
||||
@@ -102,7 +102,32 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="prefixlists" class="tab-pane fade in">
|
||||
<table id="grid-prefixlists" class="table table-responsive" data-editDialog="DialogEditBGPPrefixLists">
|
||||
<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 data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button> -->
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<div id="routemaps" class="tab-pane fade in">
|
||||
<table id="grid-routemaps" class="table table-responsive" data-editDialog="DialogEditBGPRouteMaps">
|
||||
<thead>
|
||||
@@ -124,13 +149,11 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
<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> -->
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
@@ -174,6 +197,16 @@ $(document).ready(function() {
|
||||
'options':{selection:false, multiSelect:false}
|
||||
}
|
||||
);
|
||||
$("#grid-prefixlists").UIBootgrid(
|
||||
{ 'search':'/api/quagga/bgp/searchPrefixlist',
|
||||
'get':'/api/quagga/bgp/getPrefixlist/',
|
||||
'set':'/api/quagga/bgp/setPrefixlist/',
|
||||
'add':'/api/quagga/bgp/addPrefixlist/',
|
||||
'del':'/api/quagga/bgp/delPrefixlist/',
|
||||
'toggle':'/api/quagga/bgp/togglePrefixlist/',
|
||||
'options':{selection:false, multiSelect:false}
|
||||
}
|
||||
);
|
||||
$("#grid-routemaps").UIBootgrid(
|
||||
{ 'search':'/api/quagga/bgp/searchRoutemap',
|
||||
'get':'/api/quagga/bgp/getRoutemap/',
|
||||
@@ -188,5 +221,6 @@ $(document).ready(function() {
|
||||
</script>
|
||||
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogEditBGPNeighbor,'id':'DialogEditBGPNeighbor','label':lang._('Edit Neighbor')])}}
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogEditBGPASPaths,'id':'DialogEditBGPASPaths','label':lang._('Edit AS-Paths')])}}
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogEditBGPRouteMaps,'id':'DialogEditBGPRouteMaps','label':lang._('Edit Route-Maps')])}}
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogEditBGPASPaths,'id':'DialogEditBGPASPaths','label':lang._('Edit AS Paths')])}}
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogEditBGPPrefixLists,'id':'DialogEditBGPPrefixLists','label':lang._('Edit Prefix Lists')])}}
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogEditBGPRouteMaps,'id':'DialogEditBGPRouteMaps','label':lang._('Edit Route Maps')])}}
|
||||
|
||||
@@ -27,6 +27,22 @@ router bgp {{ OPNsense.quagga.bgp.asnumber }}
|
||||
{% if 'defaultoriginate' in neighbor and neighbor.defaultoriginate == '1' %}
|
||||
neighbor {{ neighbor.address }} default-originate
|
||||
{% endif %}
|
||||
{% if neighbor.linkedPrefixlistIn|default("") != "" %}
|
||||
{% for prefixlist in neighbor.linkedPrefixlistIn.split(",") %}
|
||||
{% set prefixlist2_data = helpers.getUUID(prefixlist) %}
|
||||
{% if prefixlist2_data != '' %}
|
||||
neighbor {{ neighbor.address }} prefix-list {{ prefixlist2_data.name }} in
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if neighbor.linkedPrefixlistOut|default("") != "" %}
|
||||
{% for prefixlist in neighbor.linkedPrefixlistOut.split(",") %}
|
||||
{% set prefixlist_data = helpers.getUUID(prefixlist) %}
|
||||
{% if prefixlist_data != '' %}
|
||||
neighbor {{ neighbor.address }} prefix-list {{ prefixlist_data.name }} out
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if neighbor.linkedRoutemapIn|default("") != "" %}
|
||||
{% for aspath in neighbor.linkedRoutemapIn.split(",") %}
|
||||
{% set routemap2_data = helpers.getUUID(aspath) %}
|
||||
@@ -47,6 +63,14 @@ router bgp {{ OPNsense.quagga.bgp.asnumber }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
!
|
||||
{% if helpers.exists('OPNsense.quagga.bgp.prefixlists.prefixlist') %}
|
||||
{% for prefixlist in helpers.sortDictList(OPNsense.quagga.bgp.prefixlists.prefixlist, 'name', 'seqnumber' ) %}
|
||||
{% if prefixlist.enabled == '1' %}
|
||||
ip prefix-list {{ prefixlist.name }} seq {{ prefixlist.seqnumber }} {{ prefixlist.action }} {{ prefixlist.network }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
!
|
||||
{% if helpers.exists('OPNsense.quagga.bgp.aspaths.aspath') %}
|
||||
{% for aspath in helpers.sortDictList(OPNsense.quagga.bgp.aspaths.aspath, 'number' ) %}
|
||||
{% if aspath.enabled == '1' %}
|
||||
|
||||
Reference in New Issue
Block a user