Quagga: Add AS-Path Lists and Route-Maps to BGP (#157)

* Create dialogEditBGPASPath.xml
* Create dialogEditBGPRoutemaps.xml
* Rename dialogEditBGPRoutemaps.xml to dialogEditBGPRouteMaps.xml
* Update BgpController.php
* Update bgpd.conf
* Update bgp.volt
* Update bgp.xml
* Update BGP.xml
* Update dialogEditBGPASPath.xml
* Update dialogEditBGPNeighbor.xml
* Update dialogEditBGPRouteMaps.xml

Comment from @fabianfrz: Deduplicated commit message lines here
This commit is contained in:
Michael
2017-05-14 17:34:44 +02:00
committed by Fabian Franz
parent 73d0ec3227
commit d8cde46558
9 changed files with 507 additions and 6 deletions
@@ -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" )
array("enabled", "address", "remoteas", "updatesource", "nexthopself", "defaultoriginate", "linkedRoutemapIn", "linkedRoutemapOut" )
);
}
@@ -119,6 +119,7 @@ class BgpController extends ApiMutableModelControllerBase
// save config if validated correctly
$mdlBGP->serializeToConfig();
Config::getInstance()->save();
unset($result['validations']);
$result["result"] = "saved";
}
}
@@ -171,6 +172,200 @@ class BgpController extends ApiMutableModelControllerBase
return array("result" => "failed");
}
public function searchAspathAction()
{
$this->sessionClose();
$mdlBGP = $this->getModel();
$grid = new UIModelGrid($mdlBGP->aspaths->aspath);
return $grid->fetchBindRequest(
$this->request,
array("enabled", "number", "action", "as" )
);
}
public function getAspathAction($uuid = null)
{
$mdlBGP = $this->getModel();
if ($uuid != null) {
$node = $mdlBGP->getNodeByReference('aspaths.aspath.' . $uuid);
if ($node != null) {
// return node
return array("aspath" => $node->getNodes());
}
} else {
$node = $mdlBGP->aspaths->aspath->add();
return array("aspath" => $node->getNodes());
}
return array();
}
public function addAspathAction()
{
$result = array("result" => "failed");
if ($this->request->isPost() && $this->request->hasPost("aspath")) {
$result = array("result" => "failed", "validations" => array());
$mdlBGP = $this->getModel();
$node = $mdlBGP->aspaths->aspath->Add();
$node->setNodes($this->request->getPost("aspath"));
$valMsgs = $mdlBGP->performValidation();
foreach ($valMsgs as $field => $msg) {
$fieldnm = str_replace($node->__reference, "aspath", $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 delAspathAction($uuid)
{
$result = array("result" => "failed");
if ($this->request->isPost()) {
$mdlBGP = $this->getModel();
if ($uuid != null) {
if ($mdlBGP->aspaths->aspath->del($uuid)) {
$mdlBGP->serializeToConfig();
Config::getInstance()->save();
$result['result'] = 'deleted';
} else {
$result['result'] = 'not found';
}
}
}
return $result;
}
public function setAspathAction($uuid)
{
if ($this->request->isPost() && $this->request->hasPost("aspath")) {
$mdlNeighbor = $this->getModel();
if ($uuid != null) {
$node = $mdlNeighbor->getNodeByReference('aspaths.aspath.' . $uuid);
if ($node != null) {
$result = array("result" => "failed", "validations" => array());
$aspathInfo = $this->request->getPost("aspath");
$node->setNodes($aspathInfo);
$valMsgs = $mdlNeighbor->performValidation();
foreach ($valMsgs as $field => $msg) {
$fieldnm = str_replace($node->__reference, "aspath", $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();
$mdlBGP = $this->getModel();
$grid = new UIModelGrid($mdlBGP->routemaps->routemap);
return $grid->fetchBindRequest(
$this->request,
array("enabled", "name", "action", "id", "match", "set" )
);
}
public function getRoutemapAction($uuid = null)
{
$mdlBGP = $this->getModel();
if ($uuid != null) {
$node = $mdlBGP->getNodeByReference('routemaps.routemap.' . $uuid);
if ($node != null) {
// return node
return array("routemap" => $node->getNodes());
}
} else {
$node = $mdlBGP->routemaps->routemap->add();
return array("routemap" => $node->getNodes());
}
return array();
}
public function addRoutemapAction()
{
$result = array("result" => "failed");
if ($this->request->isPost() && $this->request->hasPost("routemap")) {
$result = array("result" => "failed", "validations" => array());
$mdlBGP = $this->getModel();
$node = $mdlBGP->routemaps->routemap->Add();
$node->setNodes($this->request->getPost("routemap"));
$valMsgs = $mdlBGP->performValidation();
foreach ($valMsgs as $field => $msg) {
$fieldnm = str_replace($node->__reference, "routemap", $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 delRoutemapAction($uuid)
{
$result = array("result" => "failed");
if ($this->request->isPost()) {
$mdlBGP = $this->getModel();
if ($uuid != null) {
if ($mdlBGP->routemaps->routemap->del($uuid)) {
$mdlBGP->serializeToConfig();
Config::getInstance()->save();
$result['result'] = 'deleted';
} else {
$result['result'] = 'not found';
}
}
}
return $result;
}
public function setRoutemapAction($uuid)
{
if ($this->request->isPost() && $this->request->hasPost("routemap")) {
$mdlNeighbor = $this->getModel();
if ($uuid != null) {
$node = $mdlNeighbor->getNodeByReference('routemaps.routemap.' . $uuid);
if ($node != null) {
$result = array("result" => "failed", "validations" => array());
$routemapInfo = $this->request->getPost("routemap");
$node->setNodes($routemapInfo);
$valMsgs = $mdlNeighbor->performValidation();
foreach ($valMsgs as $field => $msg) {
$fieldnm = str_replace($node->__reference, "routemap", $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 toggle_handler($uuid, $elements, $element)
{
$result = array("result" => "failed");
@@ -199,4 +394,14 @@ class BgpController extends ApiMutableModelControllerBase
{
return $this->toggle_handler($uuid, 'neighbors', 'neighbor');
}
public function toggleAspathAction($uuid)
{
return $this->toggle_handler($uuid, 'aspaths', 'aspath');
}
public function toggleRoutemapAction($uuid)
{
return $this->toggle_handler($uuid, 'routemaps', 'routemap');
}
}
@@ -31,6 +31,8 @@ class BgpController extends \OPNsense\Base\IndexController
$this->view->title = gettext("BGP Settings");
$this->view->bgpForm = $this->getForm("bgp");
$this->view->formDialogEditBGPNeighbor = $this->getForm("dialogEditBGPNeighbor");
$this->view->formDialogEditBGPASPaths = $this->getForm("dialogEditBGPASPath");
$this->view->formDialogEditBGPRouteMaps = $this->getForm("dialogEditBGPRouteMaps");
$this->view->pick('OPNsense/Quagga/bgp');
}
}
@@ -9,7 +9,7 @@
<id>bgp.asnumber</id>
<label>BGP AS Number</label>
<type>text</type>
<hint>Your AS Number here</hint>
<help>Your AS Number here</help>
</field>
<field>
<id>bgp.networks</id>
@@ -0,0 +1,26 @@
<form>
<field>
<id>aspath.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>Enable / Disable</help>
</field>
<field>
<id>aspath.number</id>
<label>Number</label>
<type>text</type>
<help>The ACL rule number (10-99); keep in mind that there are no sequence numbers with AS-Path lists. When you want to add a new line between you have to completely remove the ACL!</help>
</field>
<field>
<id>aspath.action</id>
<label>Action</label>
<type>select_multiple</type>
<help>Set permit for match or deny to negate the rule.</help>
</field>
<field>
<id>aspath.as</id>
<label>AS</label>
<type>text</type>
<help>The AS pattern you want to match, regexp allowed (e.g. *$ or _1$). It's not validated so please be careful!</help>
</field>
</form>
@@ -32,4 +32,16 @@
<label>Send Defaultroute</label>
<type>checkbox</type>
</field>
<field>
<id>neighbor.linkedRoutemapIn</id>
<label>Route-Map In</label>
<type>dropdown</type>
<help>Route-Map for inbound direction</help>
</field>
<field>
<id>neighbor.linkedRoutemapOut</id>
<label>Route-Map Out</label>
<type>dropdown</type>
<help>Route-Map for outbound direction</help>
</field>
</form>
@@ -0,0 +1,40 @@
<form>
<field>
<id>routemap.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>Enable / Disable</help>
</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 the neigbor configuration.</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.match</id>
<label>AS-Path List</label>
<type>select_multiple</type>
<style>tokenize</style>
<allownew>true</allownew>
<help>Select the AS-Path list</help>
</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-prefernce 300" or "community 1:1" (http://www.nongnu.org/quagga/docs/docs-multi/Route-Map-Set-Command.html#Route-Map-Set-Command)</help>
</field>
</form>
@@ -57,15 +57,107 @@
<enable>/^(?!0).*$/</enable>
</filters>
</updatesource>
<nexthopself type="BooleanField">
<nexthopself type="BooleanField">
<default>0</default>
<Required>N</Required>
</nexthopself>
<defaultoriginate type="BooleanField">
<defaultoriginate type="BooleanField">
<default>0</default>
<Required>N</Required>
</defaultoriginate>
</neighbor>
<linkedRoutemapIn type="ModelRelationField">
<Model>
<template>
<source>OPNsense.quagga.bgp</source>
<items>routemaps.routemap</items>
<display>name</display>
</template>
</Model>
<ValidationMessage>Related Route-Map item not found</ValidationMessage>
<Multiple>N</Multiple>
<Required>N</Required>
</linkedRoutemapIn>
<linkedRoutemapOut type="ModelRelationField">
<Model>
<template>
<source>OPNsense.quagga.bgp</source>
<items>routemaps.routemap</items>
<display>name</display>
</template>
</Model>
<ValidationMessage>Related Route-Map item not found</ValidationMessage>
<Multiple>N</Multiple>
<Required>N</Required>
</linkedRoutemapOut>
</neighbor>
</neighbors>
<aspaths>
<aspath type="ArrayField">
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<number type="IntegerField">
<default></default>
<Required>Y</Required>
<MinimumValue>10</MinimumValue>
<MaximumValue>99</MaximumValue>
</number>
<action type="OptionField">
<default></default>
<Required>Y</Required>
<OptionValues>
<permit>Permit</permit>
<deny>Deny</deny>
</OptionValues>
</action>
<as type="TextField">
<default></default>
<Required>Y</Required>
</as>
</aspath>
</aspaths>
<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">
<default></default>
<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>
<match type="ModelRelationField">
<Model>
<template>
<source>OPNsense.quagga.bgp</source>
<items>aspaths.aspath</items>
<display>number</display>
</template>
</Model>
<ValidationMessage>Related item not found</ValidationMessage>
<Multiple>Y</Multiple>
<Required>N</Required>
</match>
<set type="TextField">
<default></default>
<Required>Y</Required>
</set>
</routemap>
</routemaps>
</items>
</model>
@@ -31,6 +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="#routemaps">{{ lang._('Route Maps') }}</a></li>
</ul>
<div class="tab-content content-box tab-content">
<div id="general" class="tab-pane fade in active">
@@ -55,6 +57,8 @@ 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="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>
@@ -72,6 +76,61 @@ 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>
<tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle" data-sortable="false">{{ lang._('Enabled') }}</th>
<th data-column-id="number" data-type="string" data-visible="true" data-sortable="true">{{ lang._('Number') }}</th>
<th data-column-id="action" data-type="string" data-visible="true" data-sortable="false">{{ lang._('Action') }}</th>
<th data-column-id="as" data-type="string" data-visible="true" data-sortable="false">{{ lang._('AS Number') }}</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>
<tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="name" data-type="string" data-visible="true">{{ lang._('Name') }}</th>
<th data-column-id="action" data-type="string" data-visible="true">{{ lang._('Action') }}</th>
<th data-column-id="id" data-type="string" data-visible="true">{{ lang._('ID') }}</th>
<th data-column-id="match" data-type="string" data-visible="true">{{ lang._('AS Path List') }}</th>
<th data-column-id="set" data-type="string" data-visible="true">{{ lang._('Set') }}</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>
<script type="text/javascript">
@@ -105,8 +164,29 @@ $(document).ready(function() {
'options':{selection:false, multiSelect:false}
}
);
$("#grid-aspaths").UIBootgrid(
{ 'search':'/api/quagga/bgp/searchAspath',
'get':'/api/quagga/bgp/getAspath/',
'set':'/api/quagga/bgp/setAspath/',
'add':'/api/quagga/bgp/addAspath/',
'del':'/api/quagga/bgp/delAspath/',
'toggle':'/api/quagga/bgp/toggleAspath/',
'options':{selection:false, multiSelect:false}
}
);
$("#grid-routemaps").UIBootgrid(
{ 'search':'/api/quagga/bgp/searchRoutemap',
'get':'/api/quagga/bgp/getRoutemap/',
'set':'/api/quagga/bgp/setRoutemap/',
'add':'/api/quagga/bgp/addRoutemap/',
'del':'/api/quagga/bgp/delRoutemap/',
'toggle':'/api/quagga/bgp/toggleRoutemap/',
'options':{selection:false, multiSelect:false}
}
);
});
</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')])}}
@@ -27,9 +27,53 @@ router bgp {{ OPNsense.quagga.bgp.asnumber }}
{% if 'defaultoriginate' in neighbor and neighbor.defaultoriginate == '1' %}
neighbor {{ neighbor.address }} default-originate
{% endif %}
{% if neighbor.linkedRoutemapIn|default("") != "" %}
{% for aspath in neighbor.linkedRoutemapIn.split(",") %}
{% set routemap2_data = helpers.getUUID(aspath) %}
{% if routemap2_data != '' %}
neighbor {{ neighbor.address }} route-map {{ routemap2_data.name }} in
{% endif %}
{% endfor %}
{% endif %}
{% if neighbor.linkedRoutemapOut|default("") != "" %}
{% for aspath in neighbor.linkedRoutemapOut.split(",") %}
{% set routemap_data = helpers.getUUID(aspath) %}
{% if routemap_data != '' %}
neighbor {{ neighbor.address }} route-map {{ routemap_data.name }} out
{% endif %}
{% endfor %}
{% endif %}
{% 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' %}
ip as-path access-list {{ aspath.number }} {{ aspath.action }} {{ aspath.as }}
{% endif %}
{% endfor %}
{% endif %}
!
{% if helpers.exists('OPNsense.quagga.bgp.routemaps.routemap') %}
{% for routemap in helpers.sortDictList(OPNsense.quagga.bgp.routemaps.routemap, 'name', 'id' ) %}
{% if routemap.enabled == '1' %}
route-map {{ routemap.name }} {{ routemap.action }} {{ routemap.id }}
{% if routemap.match|default("") != "" %}
{% for aspath in routemap.match.split(",") %}
{% set aspath_data = helpers.getUUID(aspath) %}
{% if 'match' in routemap and routemap.match != '' %}
match as-path {{ aspath_data.number }}
{% endif %}
{% endfor %}
{% endif %}
{% if routemap.set != '' %}
set {{ routemap.set }}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
!
{% endif %}
!
line vty