From 74c1c75491948645bef117e8b573374ef6533464 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Sat, 13 Apr 2024 14:56:04 +0200 Subject: [PATCH] Add staticd to routing suite (#3904) --------- Co-authored-by: Mike Shuey --- .../OPNsense/Quagga/Api/StaticController.php | 69 +++++++++++ .../OPNsense/Quagga/StaticController.php | 41 +++++++ .../Quagga/forms/dialogEditSTATICRoute.xml | 25 ++++ .../OPNsense/Quagga/forms/static.xml | 8 ++ .../app/models/OPNsense/Quagga/Menu/Menu.xml | 3 +- .../app/models/OPNsense/Quagga/STATICd.php | 69 +++++++++++ .../app/models/OPNsense/Quagga/STATICd.xml | 36 ++++++ .../views/OPNsense/Quagga/diagnostics.volt | 3 +- .../mvc/app/views/OPNsense/Quagga/static.volt | 113 ++++++++++++++++++ .../templates/OPNsense/Quagga/+TARGETS | 1 + .../service/templates/OPNsense/Quagga/frr | 1 + .../templates/OPNsense/Quagga/staticd.conf | 18 +++ 12 files changed, 385 insertions(+), 2 deletions(-) create mode 100644 net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/StaticController.php create mode 100644 net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/StaticController.php create mode 100644 net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/dialogEditSTATICRoute.xml create mode 100644 net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/static.xml create mode 100644 net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/STATICd.php create mode 100644 net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/STATICd.xml create mode 100644 net/frr/src/opnsense/mvc/app/views/OPNsense/Quagga/static.volt create mode 100644 net/frr/src/opnsense/service/templates/OPNsense/Quagga/staticd.conf diff --git a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/StaticController.php b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/StaticController.php new file mode 100644 index 000000000..802d27983 --- /dev/null +++ b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/StaticController.php @@ -0,0 +1,69 @@ +searchBase('routes.route'); + } + + public function getRouteAction($uuid = null) + { + return $this->getBase('route', 'routes.route', $uuid); + } + + public function setRouteAction($uuid) + { + return $this->setBase('route', 'routes.route', $uuid); + } + + public function addRouteAction() + { + return $this->addBase('route', 'routes.route'); + } + + public function delRouteAction($uuid) + { + return $this->delBase('routes.route', $uuid); + } + + public function toggleRouteAction($uuid) + { + return $this->toggleBase('routes.route', $uuid); + } +} diff --git a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/StaticController.php b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/StaticController.php new file mode 100644 index 000000000..5798e168e --- /dev/null +++ b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/StaticController.php @@ -0,0 +1,41 @@ +view->staticForm = $this->getForm("static"); + $this->view->formDialogEditSTATICRoute = $this->getForm("dialogEditSTATICRoute"); + $this->view->pick('OPNsense/Quagga/static'); + } +} diff --git a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/dialogEditSTATICRoute.xml b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/dialogEditSTATICRoute.xml new file mode 100644 index 000000000..adbbeb2d4 --- /dev/null +++ b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/dialogEditSTATICRoute.xml @@ -0,0 +1,25 @@ +
+ + route.enabled + + checkbox + + + route.network + + text + Defines the target for the static route, in CIDR notation. + + + route.gateway + + text + Optional gateway IP address for this route. + + + route.interfacename + + dropdown + Select an interface where this settings apply to. + +
diff --git a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/static.xml b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/static.xml new file mode 100644 index 000000000..0a766e8f6 --- /dev/null +++ b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/forms/static.xml @@ -0,0 +1,8 @@ +
+ + staticd.enabled + + checkbox + This will activate the staticd service if the support of routing protocols is enabled in "General". + +
diff --git a/net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/Menu/Menu.xml b/net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/Menu/Menu.xml index 2a0fc1634..e63c3a58e 100644 --- a/net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/Menu/Menu.xml +++ b/net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/Menu/Menu.xml @@ -7,7 +7,8 @@ - + + diff --git a/net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/STATICd.php b/net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/STATICd.php new file mode 100644 index 000000000..b365c62f0 --- /dev/null +++ b/net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/STATICd.php @@ -0,0 +1,69 @@ +routes->route->iterateItems() as $route) { + if (!$validateFullModel && !$route->isFieldChanged()) { + continue; + } + $key = $route->__reference; + if (!empty((string)$route->network) && !empty((string)$route->gateway)) { + $net_proto = str_contains($route->network, ':') ? 'inet6' : 'inet'; + $gw_proto = str_contains($route->gateway, ':') ? 'inet6' : 'inet'; + if ($net_proto != $gw_proto) { + $messages->appendMessage( + new Message(gettext("Gateway IP protocol should match network protocol"), $key . ".gateway") + ); + } + } + if (empty((string)$route->gateway) && empty((string)$route->interfacename)) { + $messages->appendMessage( + new Message( + gettext("When no interface is provided, at least a gateway must be offered"), + $key . ".gateway" + ) + ); + } + } + return $messages; + } +} diff --git a/net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/STATICd.xml b/net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/STATICd.xml new file mode 100644 index 000000000..f0c7d37c2 --- /dev/null +++ b/net/frr/src/opnsense/mvc/app/models/OPNsense/Quagga/STATICd.xml @@ -0,0 +1,36 @@ + + //OPNsense/quagga/static + Staticd Routing configuration + 1.0.0 + + + 0 + Y + + + + + 1 + Y + + + Y + Y + Specify a valid network matching the gateways ip protocol. + + + N + N + + + N + Y + + /^(?!0).*$/ + /^(?!group).*$/ + + + + + + diff --git a/net/frr/src/opnsense/mvc/app/views/OPNsense/Quagga/diagnostics.volt b/net/frr/src/opnsense/mvc/app/views/OPNsense/Quagga/diagnostics.volt index 8c3f69d67..289f2bbf5 100644 --- a/net/frr/src/opnsense/mvc/app/views/OPNsense/Quagga/diagnostics.volt +++ b/net/frr/src/opnsense/mvc/app/views/OPNsense/Quagga/diagnostics.volt @@ -115,7 +115,8 @@ POSSIBILITY OF SUCH DAMAGE. 'connected': {short: 'C', long: '{{ lang._('Connected') }}'}, 'bgp': {short: 'B', long: '{{ lang._('BGP') }}'}, 'ospf': {short: 'O', long: '{{ lang._('OSPF') }}'}, - 'ospf6': {short: 'O', long: '{{ lang._('OSPFv3') }}'} + 'ospf6': {short: 'O', long: '{{ lang._('OSPFv3') }}'}, + 'static': {short: 'S', long: '{{ lang._('STATIC') }}'}, }; let field = $("
"); if (protocols[row.protocol] !== undefined) { diff --git a/net/frr/src/opnsense/mvc/app/views/OPNsense/Quagga/static.volt b/net/frr/src/opnsense/mvc/app/views/OPNsense/Quagga/static.volt new file mode 100644 index 000000000..5de53fc3e --- /dev/null +++ b/net/frr/src/opnsense/mvc/app/views/OPNsense/Quagga/static.volt @@ -0,0 +1,113 @@ +{# + # Copyright (c) 2024 Deciso B.V. + # Copyright (c) 2024 by Mike Shuey + # 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':staticForm,'id':'frm_static_settings'])}} +
+ +
+ + + + + + + + + + + + + + + + + + + +
{{ lang._('ID') }}{{ lang._('Enabled') }}{{ lang._('Network') }}{{ lang._('Gateway') }}{{ lang._('Interface') }}{{ lang._('Commands') }}
+ + +
+
+
+ +
+
+
+
+ +

+
+
+
+ +{{ partial("layout_partials/base_dialog",['fields':formDialogEditSTATICRoute,'id':'DialogEditSTATICRoute','label':lang._('Edit Routes')])}} diff --git a/net/frr/src/opnsense/service/templates/OPNsense/Quagga/+TARGETS b/net/frr/src/opnsense/service/templates/OPNsense/Quagga/+TARGETS index ea22bda2d..430e87167 100644 --- a/net/frr/src/opnsense/service/templates/OPNsense/Quagga/+TARGETS +++ b/net/frr/src/opnsense/service/templates/OPNsense/Quagga/+TARGETS @@ -6,6 +6,7 @@ ospf6d.conf:/usr/local/etc/frr/ospf6d.conf ospf6d_carp.conf:/usr/local/etc/frr/ospf6d_carp.conf ripd.conf:/usr/local/etc/frr/ripd.conf sa_policies.conf:/usr/local/etc/frr/sa_policies.conf +staticd.conf:/usr/local/etc/frr/staticd.conf frr:/etc/rc.conf.d/frr zebra.conf:/usr/local/etc/frr/zebra.conf vtysh.conf:/usr/local/etc/frr/vtysh.conf diff --git a/net/frr/src/opnsense/service/templates/OPNsense/Quagga/frr b/net/frr/src/opnsense/service/templates/OPNsense/Quagga/frr index d85566ce8..4347dd76c 100644 --- a/net/frr/src/opnsense/service/templates/OPNsense/Quagga/frr +++ b/net/frr/src/opnsense/service/templates/OPNsense/Quagga/frr @@ -13,6 +13,7 @@ if helpers.exists('OPNsense.quagga.bfd.enabled') and OPNsense.quagga.bfd.enabled if helpers.exists('OPNsense.quagga.bgp.enabled') and OPNsense.quagga.bgp.enabled == '1' %} bgpd{% endif %}{% if helpers.exists('OPNsense.quagga.ospf6.enabled') and OPNsense.quagga.ospf6.enabled == '1' %} ospf6d{% endif %}{% if helpers.exists('OPNsense.quagga.ripng.enabled') and OPNsense.quagga.ripng.enabled == '1' %} ripngd{% endif %}{% +if helpers.exists('OPNsense.quagga.staticd.enabled') and OPNsense.quagga.staticd.enabled == '1' %} staticd{% endif %}{% if helpers.exists('OPNsense.quagga.isis.enabled') and OPNsense.quagga.isis.enabled == '1' %} isisd{% endif %}" frr_carp_demote="{% if not helpers.empty('OPNsense.quagga.ospf.carp_demote') %} ospfd{% endif %}{% diff --git a/net/frr/src/opnsense/service/templates/OPNsense/Quagga/staticd.conf b/net/frr/src/opnsense/service/templates/OPNsense/Quagga/staticd.conf new file mode 100644 index 000000000..099a06ea7 --- /dev/null +++ b/net/frr/src/opnsense/service/templates/OPNsense/Quagga/staticd.conf @@ -0,0 +1,18 @@ +! +! staticd Zebra config autogenerated by OPNsense +! +{% if not helpers.empty('OPNsense.quagga.static.enabled') %} +{% if not helpers.empty('OPNsense.quagga.general') %} +log syslog {{ OPNsense.quagga.general.sysloglevel }} +{% endif %} +{% if not helpers.empty('OPNsense.quagga.general.profile') %} +frr defaults {{ OPNsense.quagga.general.profile }} +{% endif %} +! +{% for route in helpers.toList('OPNsense.quagga.static.routes.route') %} +{% if route.enabled == '1' %} +{% if ':' in route.network %}ipv6{% else %}ip{% endif %} route {{ route.network }} {{ route.gateway|default('')}} {{ helpers.physical_interface(route.interfacename) }} +{% endif %} +{% endfor %} +! +{% endif %}