From 3222e2e1f9e62916b849be20b39a4832818d0209 Mon Sep 17 00:00:00 2001 From: Matthias Valvekens Date: Fri, 24 Oct 2025 09:15:42 +0200 Subject: [PATCH] net/tayga: static mapping support (#4986) Implement support for the 'map' directive in Tayga that can be used to statically define one-to-one maps between IPv4 and IPv6 prefixes. Implements #4606. --- net/tayga/Makefile | 3 +- net/tayga/pkg-descr | 4 ++ .../OPNsense/Tayga/Api/MappingController.php | 67 +++++++++++++++++++ .../OPNsense/Tayga/GeneralController.php | 2 + .../Tayga/forms/dialogEditStaticMapping.xml | 34 ++++++++++ .../mvc/app/models/OPNsense/Tayga/General.xml | 8 ++- .../models/OPNsense/Tayga/StaticMapping.php | 35 ++++++++++ .../models/OPNsense/Tayga/StaticMapping.xml | 24 +++++++ .../mvc/app/views/OPNsense/Tayga/general.volt | 49 ++++++++------ .../templates/OPNsense/Tayga/tayga.conf | 8 +++ 10 files changed, 212 insertions(+), 22 deletions(-) create mode 100644 net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/Api/MappingController.php create mode 100644 net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/forms/dialogEditStaticMapping.xml create mode 100644 net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/StaticMapping.php create mode 100644 net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/StaticMapping.xml diff --git a/net/tayga/Makefile b/net/tayga/Makefile index fe232e6ac..9b9a62daf 100644 --- a/net/tayga/Makefile +++ b/net/tayga/Makefile @@ -1,6 +1,5 @@ PLUGIN_NAME= tayga -PLUGIN_VERSION= 1.2 -PLUGIN_REVISION= 2 +PLUGIN_VERSION= 1.3 PLUGIN_COMMENT= Tayga NAT64 PLUGIN_DEPENDS= tayga PLUGIN_MAINTAINER= m.muenz@gmail.com diff --git a/net/tayga/pkg-descr b/net/tayga/pkg-descr index 4ff06aba2..c97a14600 100644 --- a/net/tayga/pkg-descr +++ b/net/tayga/pkg-descr @@ -7,6 +7,10 @@ networks where dedicated NAT64 hardware would be overkill. Plugin Changelog ================ +1.3 + +* Static mapping support + 1.2 * Custom IPv6 routing option diff --git a/net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/Api/MappingController.php b/net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/Api/MappingController.php new file mode 100644 index 000000000..05b88d727 --- /dev/null +++ b/net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/Api/MappingController.php @@ -0,0 +1,67 @@ + + 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. +*/ + +namespace OPNsense\Tayga\Api; + +use OPNsense\Base\ApiMutableModelControllerBase; + +class MappingController extends ApiMutableModelControllerBase +{ + protected static $internalModelName = 'staticmapping'; + protected static $internalModelClass = '\OPNsense\Tayga\StaticMapping'; + + public function searchStaticmappingAction() + { + return $this->searchBase('staticmappings.staticmapping', ['enabled', 'v4', 'v6']); + } + + public function getStaticmappingAction($uuid = null) + { + return $this->getBase('staticmapping', 'staticmappings.staticmapping', $uuid); + } + + public function addStaticmappingAction() + { + return $this->addBase('staticmapping', 'staticmappings.staticmapping'); + } + + public function delStaticmappingAction($uuid) + { + return $this->delBase('staticmappings.staticmapping', $uuid); + } + + public function setStaticmappingAction($uuid) + { + return $this->setBase('staticmapping', 'staticmappings.staticmapping', $uuid); + } + + public function toggleStaticmappingAction($uuid) + { + return $this->toggleBase('staticmappings.staticmapping', $uuid); + } +} diff --git a/net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/GeneralController.php b/net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/GeneralController.php index 6cf94562b..667f30cc9 100644 --- a/net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/GeneralController.php +++ b/net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/GeneralController.php @@ -34,5 +34,7 @@ class GeneralController extends \OPNsense\Base\IndexController { $this->view->generalForm = $this->getForm("general"); $this->view->pick('OPNsense/Tayga/general'); + $this->view->formDialogEditStaticMapping = $this->getForm("dialogEditStaticMapping"); + $this->view->formGridStaticMapping = $this->getFormGrid("dialogEditStaticMapping"); } } diff --git a/net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/forms/dialogEditStaticMapping.xml b/net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/forms/dialogEditStaticMapping.xml new file mode 100644 index 000000000..e838c49e7 --- /dev/null +++ b/net/tayga/src/opnsense/mvc/app/controllers/OPNsense/Tayga/forms/dialogEditStaticMapping.xml @@ -0,0 +1,34 @@ +
+ + staticmapping.enabled + + checkbox + This will enable or disable the static mapping + + 6em + boolean + rowtoggle + + + + staticmapping.v4 + + text + IPv4 network to map. Can overlap with dynamic pool. + + + staticmapping.v6 + + text + IPv4 network to map. Must not overlap with NAT64 prefix. + + + staticmapping.description + + text + Optionally describe the purpose of the mapping. + + false + + +
diff --git a/net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/General.xml b/net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/General.xml index 0644ef618..19861baff 100644 --- a/net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/General.xml +++ b/net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/General.xml @@ -1,7 +1,7 @@ //OPNsense/tayga/general Tayga configuration - 1.2.0 + 1.3.0 0 @@ -10,24 +10,30 @@ 192.168.255.1 Y + ipv4 192.168.254.1 Y + ipv4 N + ipv6 2001:db8:1:ffff::1 + ipv6 Y 64:ff9b::/96 + ipv6 Y 192.168.255.0/24 + ipv4 Y diff --git a/net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/StaticMapping.php b/net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/StaticMapping.php new file mode 100644 index 000000000..be26d28b0 --- /dev/null +++ b/net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/StaticMapping.php @@ -0,0 +1,35 @@ + + 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. +*/ + +namespace OPNsense\Tayga; + +use OPNsense\Base\BaseModel; + +class StaticMapping extends BaseModel +{ +} diff --git a/net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/StaticMapping.xml b/net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/StaticMapping.xml new file mode 100644 index 000000000..ad7429652 --- /dev/null +++ b/net/tayga/src/opnsense/mvc/app/models/OPNsense/Tayga/StaticMapping.xml @@ -0,0 +1,24 @@ + + //OPNsense/tayga/staticmapping + Static NAT64 mappings + 1.3.0 + + + + + Y + 1 + + + Y + ipv4 + + + Y + ipv6 + + + + + + diff --git a/net/tayga/src/opnsense/mvc/app/views/OPNsense/Tayga/general.volt b/net/tayga/src/opnsense/mvc/app/views/OPNsense/Tayga/general.volt index bded11ae6..0732903f5 100644 --- a/net/tayga/src/opnsense/mvc/app/views/OPNsense/Tayga/general.volt +++ b/net/tayga/src/opnsense/mvc/app/views/OPNsense/Tayga/general.volt @@ -26,13 +26,23 @@ 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':generalForm,'id':'frm_general_settings'])}} -
-
- + + + + +
+
+ {{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}} +
+
+ {{ partial('layout_partials/base_bootgrid_table', formGridStaticMapping) }}
+{{ partial("layout_partials/base_dialog",['fields':formDialogEditStaticMapping,'id': formGridStaticMapping['edit_dialog_id'], 'label':lang._('Edit mapping')])}} +{{ partial('layout_partials/base_apply_button', {'data_endpoint': '/api/tayga/service/reconfigure', 'data_service_widget': 'tayga'}) }} diff --git a/net/tayga/src/opnsense/service/templates/OPNsense/Tayga/tayga.conf b/net/tayga/src/opnsense/service/templates/OPNsense/Tayga/tayga.conf index 2c8a3bd58..853353f95 100644 --- a/net/tayga/src/opnsense/service/templates/OPNsense/Tayga/tayga.conf +++ b/net/tayga/src/opnsense/service/templates/OPNsense/Tayga/tayga.conf @@ -10,4 +10,12 @@ ipv6-addr {{ OPNsense.tayga.general.v6address }} prefix {{ OPNsense.tayga.general.v6prefix }} dynamic-pool {{ OPNsense.tayga.general.v4pool }} +{% if helpers.exists('OPNsense.tayga.staticmapping.staticmappings.staticmapping') %} +{% for mapping in helpers.toList('OPNsense.tayga.staticmapping.staticmappings.staticmapping') %} +{% if mapping.enabled == '1' %} +map {{ mapping.v4 }} {{ mapping.v6 }} +{% endif %} +{% endfor %} +{% endif %} + {% endif %}