net/tayga: New plugin (#1673)

This commit is contained in:
Michael
2020-02-07 10:28:57 +01:00
committed by GitHub
parent c60ac7e7b5
commit c62b8ce046
19 changed files with 450 additions and 0 deletions
+1
View File
@@ -67,6 +67,7 @@ net/pptp -- End of life, no replacement
net/relayd -- Relayd Load Balancer
net/shadowsocks -- Secure socks5 proxy
net/siproxd -- Siproxd is a proxy daemon for the SIP protocol
net/tayga -- Tayga is a stateless NAT64 daemon
net/upnp -- Universal Plug and Play Service
net/vnstat -- vnStat is a console-based network traffic monitor
net/wireguard -- WireGuard VPN service
+7
View File
@@ -0,0 +1,7 @@
PLUGIN_NAME= tayga
PLUGIN_VERSION= 0.1
PLUGIN_COMMENT= Tayga IPv6 64NAT
PLUGIN_DEPENDS= tayga
PLUGIN_MAINTAINER= m.muenz@gmail.com
.include "../../Mk/plugins.mk"
+14
View File
@@ -0,0 +1,14 @@
TAYGA is an out-of-kernel stateless NAT64 implementation that uses
the TUN driver to exchange IPv4 and IPv6 packets with the kernel.
It is intended to provide production-quality NAT64 service for
networks where dedicated NAT64 hardware would be overkill.
Plugin Changelog
================
1.0
* Support for IPv6 prefix and IPv4 pool
WWW: http://www.litech.org/tayga/
@@ -0,0 +1,63 @@
<?php
/*
* Copyright (C) 2020 Michael Muenz <m.muenz@gmail.com>
* 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.
*/
function tayga_enabled()
{
$model = new \OPNsense\Tayga\General();
return (string)$model->enabled == '1';
}
function tayga_services()
{
$services = array();
if (tayga_enabled()) {
$services[] = array(
'description' => gettext('Tayga'),
'configd' => array(
'restart' => array('tayga restart'),
'start' => array('tayga start'),
'stop' => array('tayga stop'),
),
'name' => 'tayga',
'pidfile' => '/var/run/tayga.pid'
);
}
return $services;
}
function tayga_xmlrpc_sync()
{
$result = array();
$result['id'] = 'taygavpn';
$result['section'] = 'OPNsense.tayga';
$result['description'] = gettext('Tayga');
return array($result);
}
+35
View File
@@ -0,0 +1,35 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: opnsense-tayga
# REQUIRE: SERVERS
# KEYWORD: shutdown
#
. /etc/rc.subr
name=tayga
stop_cmd=tayga_stop
rcvar=tayga_enable
load_rc_config opnsense-tayga
pidfile=/var/run/${name}.pid
command=/usr/local/sbin/${name}
command_args="-p ${pidfile}"
[ -z "$tayga_enable" ] && tayga_enable="NO"
tayga_stop()
{
if [ -n "$rc_pid" ]; then
echo "stopping tayga"
kill -2 ${rc_pid}
ifconfig nat64 destroy
else
echo "${name} is not running."
fi
}
run_rc_command $1
@@ -0,0 +1,37 @@
<?php
/*
* Copyright (C) 2020 Michael Muenz <m.muenz@gmail.com>
* 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 GeneralController extends ApiMutableModelControllerBase
{
protected static $internalModelClass = '\OPNsense\Tayga\General';
protected static $internalModelName = 'general';
}
@@ -0,0 +1,39 @@
<?php
/*
* Copyright (C) 2020 Michael Muenz <m.muenz@gmail.com>
* 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\ApiMutableServiceControllerBase;
class ServiceController extends ApiMutableServiceControllerBase
{
protected static $internalServiceClass = '\OPNsense\Tayga\General';
protected static $internalServiceTemplate = 'OPNsense/Tayga';
protected static $internalServiceEnabled = 'enabled';
protected static $internalServiceName = 'tayga';
}
@@ -0,0 +1,38 @@
<?php
/*
* Copyright (C) 2020 Michael Muenz <m.muenz@gmail.com>
* 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;
class GeneralController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->generalForm = $this->getForm("general");
$this->view->pick('OPNsense/Tayga/general');
}
}
@@ -0,0 +1,32 @@
<form>
<field>
<id>general.enabled</id>
<label>Enable</label>
<type>checkbox</type>
<help>This will activate Tayga.</help>
</field>
<field>
<id>general.v4address</id>
<label>IPv4 Address</label>
<type>text</type>
<help>This is not your router's IPv4 address. Tayga requires its own address because it acts as an IPv4 and IPv6 router, and needs to be able to send ICMP messages. This address can safely be located inside the dynamic-pool prefix.</help>
</field>
<field>
<id>general.v6address</id>
<label>IPv6 Address</label>
<type>text</type>
<help>This is not your routers IPv6 address. Tayga requires its own address because it acts as an IPv4 and IPv6 router, and needs to be able to send ICMP messages. Tayga will also respond to ICMP echo requests (ping6) at this address. You can leave it unspecified and Tayga will construct its IPv6 address using IPv4 address and the NAT64 prefix.</help>
</field>
<field>
<id>general.v6prefix</id>
<label>IPv6 Prefix</label>
<type>text</type>
<help>This must be a prefix selected from your organizations IPv6 address space or the Well-Known Prefix 64:ff9b::/96. The IPv4 address space is mapped into the IPv6 address space by prepending this prefix to the IPv4 address.</help>
</field>
<field>
<id>general.v4pool</id>
<label>IPv4 Pool</label>
<type>text</type>
<help>Dynamic pool prefix. IPv6 hosts which send traffic through Tayga will be assigned an IPv4 address from the dynamic pool.</help>
</field>
</form>
@@ -0,0 +1,9 @@
<acl>
<page-tayga-config>
<name>Services: Tayga configuration</name>
<patterns>
<pattern>ui/tayga/*</pattern>
<pattern>api/tayga/*</pattern>
</patterns>
</page-tayga-config>
</acl>
@@ -0,0 +1,35 @@
<?php
/*
Copyright (C) 2020 Michael Muenz <m.muenz@gmail.com>
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 General extends BaseModel
{
}
@@ -0,0 +1,27 @@
<model>
<mount>//OPNsense/tayga/general</mount>
<description>Tayga configuration</description>
<version>0.0.2</version>
<items>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
<v4address type="NetworkField">
<default>192.168.255.1</default>
<Required>N</Required>
</v4address>
<v6address type="NetworkField">
<default>2001:db8:1::2</default>
<Required>N</Required>
</v6address>
<v6prefix type="NetworkField">
<default>2001:db8:1:ffff::/96</default>
<Required>N</Required>
</v6prefix>
<v4pool type="NetworkField">
<default>192.168.255.0/24</default>
<Required>N</Required>
</v4pool>
</items>
</model>
@@ -0,0 +1,5 @@
<menu>
<Services>
<Tayga cssClass="fa fa-exchange" url="/ui/tayga/general/index" />
</Services>
</menu>
@@ -0,0 +1,61 @@
{#
OPNsense® is Copyright © 2014 2020 by Deciso B.V.
This file is Copyright © 2020 by Michael Muenz <m.muenz@gmail.com>
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.
#}
<div class="content-box" style="padding-bottom: 1.5em;">
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}}
<div class="col-md-12">
<hr />
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b> <i id="saveAct_progress"></i></button>
</div>
</div>
<script>
$( document ).ready(function() {
var data_get_map = {'frm_general_settings':"/api/tayga/general/get"};
mapDataToFormUI(data_get_map).done(function(data){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
});
ajaxCall(url="/api/tayga/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
// link save button to API set action
$("#saveAct").click(function(){
saveFormToEndpoint(url="/api/tayga/general/set", formid='frm_general_settings',callback_ok=function(){
$("#saveAct_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/tayga/service/reconfigure", sendData={}, callback=function(data,status) {
ajaxCall(url="/api/tayga/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
$("#saveAct_progress").removeClass("fa fa-spinner fa-pulse");
});
});
});
});
</script>
@@ -0,0 +1,5 @@
#!/bin/sh
mkdir -p /var/db/tayga/
chmod 644 /var/db/tayga
chown root:wheel /var/db/tayga
@@ -0,0 +1,23 @@
[stop]
command:/usr/local/etc/rc.d/opnsense-tayga stop
parameters:
type:script_output
message:stopping tayga
[start]
command:/usr/local/opnsense/scripts/OPNsense/Tayga/setup.sh; /usr/local/etc/rc.d/opnsense-tayga start
parameters:
type:script_output
message:starting tayga
[restart]
command:/usr/local/etc/rc.d/opnsense-tayga stop; /usr/local/opnsense/scripts/OPNsense/Tayga/setup.sh; /usr/local/etc/rc.d/opnsense-tayga start
parameters:
type:script_output
message:restarting tayga
[status]
command:/usr/local/etc/rc.d/opnsense-tayga status; exit 0
parameters:
type:script_output
message:tayga status
@@ -0,0 +1,2 @@
tayga:/etc/rc.conf.d/opnsense-tayga
tayga.conf:/usr/local/etc/tayga.conf
@@ -0,0 +1,6 @@
{% if helpers.exists('OPNsense.tayga.general.enabled') and OPNsense.tayga.general.enabled == '1' %}
tayga_var_script="/usr/local/opnsense/scripts/OPNsense/Tayga/setup.sh"
tayga_enable="YES"
{% else %}
tayga_enable="NO"
{% endif %}
@@ -0,0 +1,11 @@
{% if helpers.exists('OPNsense.tayga.general.enabled') and OPNsense.tayga.general.enabled == '1' %}
tun-device nat64
data-dir /var/db/tayga
ipv4-addr {{ OPNsense.tayga.general.v4address }}
ipv6-addr {{ OPNsense.tayga.general.v6address }}
prefix {{ OPNsense.tayga.general.v6prefix }}
dynamic-pool {{ OPNsense.tayga.general.v4pool }}
{% endif %}