From 5c4e345414f82341a4c833d0a1e422fce84d5600 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 3 May 2017 15:19:16 +0200 Subject: [PATCH] Quagga: Ospf6d #124 (#143) * Create ospf6d.conf * Update +TARGETS * Create Ospf6Controller.php * Create Ospf6settingsController.php * Create ospf6.xml * Create dialogEditOSPF6Interface.xml * Create OSPF6.php * Create OSPF6.xml * Update Menu.xml * Create ospf6.volt * Update Ospf6Controller.php * Update Ospf6settingsController.php * Update ospf6.xml * Create dialogEditOSPF6Networks.xml * Rename dialogEditOSPF6Networks.xml to dialogEditOSPF6Network.xml * Update Menu.xml * Update OSPF6.xml * Update OSPF.php * Update ospf6.volt * Update Ospf6Controller.php * Update OSPF6.php * Update OSPF.php * Update Ospf6settingsController.php * Update Ospf6Controller.php * Update Ospf6Controller.php * Update ospf6d.conf * Update OSPF6.php * Update OSPF6.php * Update ospf6d.conf * Update ospf6.volt * Update OSPF6.xml * Update Ospf6Controller.php * Update Ospf6settingsController.php * Delete dialogEditOSPF6Network.xml * Update ospf6.xml * Update Ospf6Controller.php * Update OSPF6.php * Update OSPF6.xml * Update ospf6d.conf * Update ospf6d.conf * Update dialogEditOSPF6Interface.xml * Update OSPF6.xml * Update ospf6.volt * Update ospf6d.conf * Update ospf6d.conf * Update ospf6d.conf * Update Ospf6settingsController.php * Update ospf6.xml * Update dialogEditOSPF6Interface.xml * Update OSPF6.xml * Update ospf6.volt * Update ospf6.xml * Update ospf6d.conf * Update ospf6d.conf * Update OSPF6.xml * move namespace and includes after (C) block * update signs * Update Ospf6Controller.php --- .../Quagga/Api/Ospf6settingsController.php | 195 ++++++++++++++++++ .../OPNsense/Quagga/Ospf6Controller.php | 35 ++++ .../Quagga/forms/dialogEditOSPF6Interface.xml | 55 +++++ .../OPNsense/Quagga/forms/ospf6.xml | 22 ++ .../app/models/OPNsense/Quagga/Menu/Menu.xml | 9 +- .../mvc/app/models/OPNsense/Quagga/OSPF6.php | 29 +++ .../mvc/app/models/OPNsense/Quagga/OSPF6.xml | 98 +++++++++ .../mvc/app/views/OPNsense/Quagga/ospf6.volt | 113 ++++++++++ .../templates/OPNsense/Quagga/+TARGETS | 1 + .../templates/OPNsense/Quagga/ospf6d.conf | 45 ++++ 10 files changed, 598 insertions(+), 4 deletions(-) create mode 100644 net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/Ospf6settingsController.php create mode 100644 net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Ospf6Controller.php create mode 100644 net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/dialogEditOSPF6Interface.xml create mode 100644 net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/ospf6.xml create mode 100644 net/quagga/src/opnsense/mvc/app/models/OPNsense/Quagga/OSPF6.php create mode 100644 net/quagga/src/opnsense/mvc/app/models/OPNsense/Quagga/OSPF6.xml create mode 100644 net/quagga/src/opnsense/mvc/app/views/OPNsense/Quagga/ospf6.volt create mode 100644 net/quagga/src/opnsense/service/templates/OPNsense/Quagga/ospf6d.conf diff --git a/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/Ospf6settingsController.php b/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/Ospf6settingsController.php new file mode 100644 index 000000000..472527127 --- /dev/null +++ b/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/Ospf6settingsController.php @@ -0,0 +1,195 @@ +request->isGet()) { + $mdlospf6 = new OSPF6(); + $result['ospf6'] = $mdlospf6->getNodes(); + } + return $result; + } + public function setAction() + { + $result = array("result"=>"failed"); + if ($this->request->isPost()) { + // load model and update with provided data + $mdlospf6 = new OSPF6(); + $mdlospf6->setNodes($this->request->getPost("ospf6")); + // perform validation + $valMsgs = $mdlospf6->performValidation(); + foreach ($valMsgs as $field => $msg) { + if (!array_key_exists("validations", $result)) { + $result["validations"] = array(); + } + $result["validations"]["general.".$msg->getField()] = $msg->getMessage(); + } + // serialize model to config and save + if ($valMsgs->count() == 0) { + $mdlospf6->serializeToConfig(); + Config::getInstance()->save(); + $result["result"] = "saved"; + } + } + return $result; + } +///////////////////////////////////////////////////////////////////// + public function searchInterfaceAction() + { + $this->sessionClose(); + $mdlOSPF6 = $this->getModel(); + $grid = new UIModelGrid($mdlOSPF6->interfaces->interface); + return $grid->fetchBindRequest( + $this->request, + array("enabled", "interfacename", "area", "networktype") + ); + } + public function getInterfaceAction($uuid = null) + { + $mdlOSPF6 = $this->getModel(); + if ($uuid != null) { + $node = $mdlOSPF6->getNodeByReference('interfaces.interface.' . $uuid); + if ($node != null) { + // return node + return array("interface" => $node->getNodes()); + } + } else { + $node = $mdlOSPF6->interfaces->interface->add(); + return array("interface" => $node->getNodes()); + } + return array(); + } + public function addInterfaceAction() + { + $result = array("result" => "failed"); + if ($this->request->isPost() && $this->request->hasPost("interface")) { + $result = array("result" => "failed", "validations" => array()); + $mdlOSPF6 = $this->getModel(); + $node = $mdlOSPF6->interfaces->interface->Add(); + $node->setNodes($this->request->getPost("interface")); + $valMsgs = $mdlOSPF6->performValidation(); + foreach ($valMsgs as $field => $msg) { + $fieldnm = str_replace($node->__reference, "interface", $msg->getField()); + $result["validations"][$fieldnm] = $msg->getMessage(); + } + if (count($result['validations']) == 0) { + // save config if validated correctly + $mdlOSPF6->serializeToConfig(); + Config::getInstance()->save(); + unset($result['validations']); + $result["result"] = "saved"; + } + } + return $result; + } + public function delInterfaceAction($uuid) + { + $result = array("result" => "failed"); + if ($this->request->isPost()) { + $mdlOSPF6 = $this->getModel(); + if ($uuid != null) { + if ($mdlOSPF6->interfaces->interface->del($uuid)) { + $mdlOSPF6->serializeToConfig(); + Config::getInstance()->save(); + $result['result'] = 'deleted'; + } else { + $result['result'] = 'not found'; + } + } + } + return $result; + } + public function setInterfaceAction($uuid) + { + if ($this->request->isPost() && $this->request->hasPost("interface")) { + $mdlNetwork = $this->getModel(); + if ($uuid != null) { + $node = $mdlNetwork->getNodeByReference('interfaces.interface.' . $uuid); + if ($node != null) { + $result = array("result" => "failed", "validations" => array()); + $interfaceInfo = $this->request->getPost("interface"); + $node->setNodes($interfaceInfo); + $valMsgs = $mdlNetwork->performValidation(); + foreach ($valMsgs as $field => $msg) { + $fieldnm = str_replace($node->__reference, "interface", $msg->getField()); + $result["validations"][$fieldnm] = $msg->getMessage(); + } + if (count($result['validations']) == 0) { + // save config if validated correctly + $mdlNetwork->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"); + if ($this->request->isPost()) { + $mdlNetwork = $this->getModel(); + if ($uuid != null) { + $node = $mdlNetwork->getNodeByReference($elements . '.'. $element .'.' . $uuid); + if ($node != null) { + if ($node->enabled->__toString() == "1") { + $result['result'] = "Disabled"; + $node->enabled = "0"; + } else { + $result['result'] = "Enabled"; + $node->enabled = "1"; + } + // if item has toggled, serialize to config and save + $mdlNetwork->serializeToConfig(); + Config::getInstance()->save(); + } + } + } + return $result; + } + public function toggleInterfaceAction($uuid) + { + return $this->toggle_handler($uuid, 'interfaces', 'interface'); + } +} diff --git a/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Ospf6Controller.php b/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Ospf6Controller.php new file mode 100644 index 000000000..53b757a85 --- /dev/null +++ b/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Ospf6Controller.php @@ -0,0 +1,35 @@ +view->title = gettext("OSPFv3 Settings"); + $this->view->ospf6Form = $this->getForm("ospf6"); + $this->view->formDialogEditInterface = $this->getForm("dialogEditOSPF6Interface"); + $this->view->pick('OPNsense/Quagga/ospf6'); + } +} diff --git a/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/dialogEditOSPF6Interface.xml b/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/dialogEditOSPF6Interface.xml new file mode 100644 index 000000000..85777c46a --- /dev/null +++ b/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/dialogEditOSPF6Interface.xml @@ -0,0 +1,55 @@ +
+ + interface.enabled + + checkbox + + + interface.interfacename + + + select_multiple + Select an interface where this settings apply to. + + + interface.area + + text + Area in wildcard mask style like 0.0.0.0 and no decimal 0 + + + interface.cost + + text + + + interface.hellointerval + + text + + + interface.deadinterval + + text + + + interface.retransmitinterval + + text + + + interface.transmitdelay + + text + + + interface.priority + + text + + + interface.networktype + + select_multiple + +
diff --git a/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/ospf6.xml b/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/ospf6.xml new file mode 100644 index 000000000..229bfa482 --- /dev/null +++ b/net/quagga/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/ospf6.xml @@ -0,0 +1,22 @@ +
+ + ospf6.enabled + + checkbox + This will activate the OSPFv3 service if routing protocols are enabled in "General". + + + ospf6.redistribute + + select_multiple + + + Type or select a route source. + + + ospf6.routerid + + text + Router ID as IPv4 Address + +
diff --git a/net/quagga/src/opnsense/mvc/app/models/OPNsense/Quagga/Menu/Menu.xml b/net/quagga/src/opnsense/mvc/app/models/OPNsense/Quagga/Menu/Menu.xml index fa17e6b9b..554222fea 100644 --- a/net/quagga/src/opnsense/mvc/app/models/OPNsense/Quagga/Menu/Menu.xml +++ b/net/quagga/src/opnsense/mvc/app/models/OPNsense/Quagga/Menu/Menu.xml @@ -1,10 +1,11 @@ - - - + + + + - + diff --git a/net/quagga/src/opnsense/mvc/app/models/OPNsense/Quagga/OSPF6.php b/net/quagga/src/opnsense/mvc/app/models/OPNsense/Quagga/OSPF6.php new file mode 100644 index 000000000..ed88b7875 --- /dev/null +++ b/net/quagga/src/opnsense/mvc/app/models/OPNsense/Quagga/OSPF6.php @@ -0,0 +1,29 @@ + + //OPNsense/quagga/ospf6 + OSPFv3 Routing configuration + + + 0 + Y + + + N + Y + + + Connected routes (directly attached subnet or host) + Statically configured routes + + + + + Y + /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ + + + + + 1 + Y + + + N + N + + + /^(?!0).*$/ + + + + + Y + /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ + + + + 0 + N + 4294967295 + Cost must be between 0 and 4294967295. + + + + 0 + N + 4294967295 + Hello interval must be between 0 and 4294967295. + + + + 0 + N + 4294967295 + Dead interval must be between 0 and 4294967295. + + + + 0 + N + 4294967295 + Retransmit interval must be between 0 and 4294967295. + + + + 0 + N + 4294967295 + Transmit delay must be between 0 and 4294967295. + + + + 0 + N + 4294967295 + Priority must be between 0 and 4294967295. + + + N + N + + + Broadcast multi-access network + NBMA network + Point-to-multipoint network + Point-to-point network + + + + + + diff --git a/net/quagga/src/opnsense/mvc/app/views/OPNsense/Quagga/ospf6.volt b/net/quagga/src/opnsense/mvc/app/views/OPNsense/Quagga/ospf6.volt new file mode 100644 index 000000000..91c25c7f5 --- /dev/null +++ b/net/quagga/src/opnsense/mvc/app/views/OPNsense/Quagga/ospf6.volt @@ -0,0 +1,113 @@ +{# + +OPNsense® is Copyright © 2014 – 2017 by Deciso B.V. +This file is Copyright © 2017 by Fabian Franz +This file is Copyright © 2017 by Michael Muenz +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. + +#} + + + +
+
+
+ {{ partial("layout_partials/base_form",['fields':ospf6Form,'id':'frm_ospf6_settings'])}} + +
+
+ +
+
+
+ + +
+ + + + + + + + + + + + + + + + + + + +
{{ lang._('Enabled') }}{{ lang._('Interface Name') }}{{ lang._('Area') }}{{ lang._('Network Type') }}{{ lang._('ID') }}{{ lang._('Commands') }}
+ + +
+
+ +
+ + + +{{ partial("layout_partials/base_dialog",['fields':formDialogEditInterface,'id':'DialogEditInterface','label':lang._('Edit Interface')])}} diff --git a/net/quagga/src/opnsense/service/templates/OPNsense/Quagga/+TARGETS b/net/quagga/src/opnsense/service/templates/OPNsense/Quagga/+TARGETS index 0ad27b58a..13d9f75c5 100644 --- a/net/quagga/src/opnsense/service/templates/OPNsense/Quagga/+TARGETS +++ b/net/quagga/src/opnsense/service/templates/OPNsense/Quagga/+TARGETS @@ -1,5 +1,6 @@ bgpd.conf:/usr/local/etc/quagga/bgpd.conf ospfd.conf:/usr/local/etc/quagga/ospfd.conf +ospf6d.conf:/usr/local/etc/quagga/ospf6d.conf ripd.conf:/usr/local/etc/quagga/ripd.conf quagga:/etc/rc.conf.d/quagga zebra.conf:/usr/local/etc/quagga/zebra.conf diff --git a/net/quagga/src/opnsense/service/templates/OPNsense/Quagga/ospf6d.conf b/net/quagga/src/opnsense/service/templates/OPNsense/Quagga/ospf6d.conf new file mode 100644 index 000000000..c852d7781 --- /dev/null +++ b/net/quagga/src/opnsense/service/templates/OPNsense/Quagga/ospf6d.conf @@ -0,0 +1,45 @@ +{% macro cline(directive, modelname) -%}{% if modelname %} + ipv6 ospf6 {{ directive }} {{ modelname }} +{% endif %}{%- endmacro %} +{% from 'OPNsense/Macros/interface.macro' import physical_interface %} +{% if helpers.exists('OPNsense.quagga.ospf6.enabled') and OPNsense.quagga.ospf6.enabled == '1' %} +! +! Zebra configuration saved from vty +! 2017/03/03 20:21:04 +! +! +! +! +{% if helpers.exists('OPNsense.quagga.ospf6.interfaces.interface') %} +{% for interface in helpers.toList('OPNsense.quagga.ospf6.interfaces.interface') %} +{% if interface.enabled == '1' %} +interface {{ physical_interface(interface.interfacename) }} +{{ cline("cost",interface.cost) +}}{{ cline("dead-interval",interface.deadinterval) +}}{{ cline("hello-interval",interface.hellointerval) +}}{{ cline("priority",interface.priority) +}}{{ cline("retransmit-interval",interface.retransmitinterval) +}}! +{% endif %} +{% endfor %} +{% endif %} +! +router ospf6 +{% if helpers.exists('OPNsense.quagga.ospf6.redistribute') and OPNsense.quagga.ospf6.redistribute != '' %} +{% for line in OPNsense.quagga.ospf6.redistribute.split(',') %} + redistribute {{ line }} +{% endfor %}{% endif %} +{% if helpers.exists('OPNsense.quagga.ospf6.interfaces.interface') %} +{% for interface in helpers.toList('OPNsense.quagga.ospf6.interfaces.interface') %} +{% if interface.enabled == '1' %} + interface {{ physical_interface(interface.interfacename) }} area {{ interface.area }} +{% endif %} +{% endfor %} +{% endif %} +{% if helpers.exists('OPNsense.quagga.ospf6.routerid') and OPNsense.quagga.ospf6.routerid != '' %} + router-id {{ OPNsense.quagga.ospf6.routerid }} +{% endif %} +! +line vty +! +{% endif %}