Browse Source

tayga: Add Netifd support

This patch integrates tayga with netifd. Parametres are nearly same as
with the older scripts. Support for static mapping of IPv4<=>IPv6 addresses
is missing. Example configuration:

config interface 'nat64'
        option proto 'tayga'
        option prefix 64:ff9b::/96
        option dynamic_pool 10.128.0.0/24
        option ipv4_addr 10.128.0.1	#address of the TAYGA itself
        option ipv6_addr 2001:470:5990::64
        option ipaddr  192.168.1.1 #optional address of TUN interface
        option ip6addr 2001:db8::1

Signed-off-by: Ondrej Caletka <ondrej@caletka.cz>
lilik-openwrt-22.03
Ondřej Caletka 11 years ago
parent
commit
545b84c547
2 changed files with 96 additions and 4 deletions
  1. +4
    -4
      ipv6/tayga/Makefile
  2. +92
    -0
      ipv6/tayga/files/tayga-proto.sh

+ 4
- 4
ipv6/tayga/Makefile View File

@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=tayga PKG_NAME:=tayga
PKG_VERSION:=0.9.2 PKG_VERSION:=0.9.2
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_SOURCE:=tayga-$(PKG_VERSION).tar.bz2 PKG_SOURCE:=tayga-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=http://www.litech.org/tayga/ PKG_SOURCE_URL:=http://www.litech.org/tayga/
@ -31,11 +31,11 @@ define Package/tayga/description
kernel, which is the same driver used by OpenVPN and QEMU/KVM. kernel, which is the same driver used by OpenVPN and QEMU/KVM.
endef endef
# TODO: port scripts to netifd
ifdef CONFIG_PACAKGE_netifd
ifdef CONFIG_PACKAGE_netifd
define Package/tayga/install define Package/tayga/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_DIR) $(1)/usr/sbin $(1)/lib/netifd/proto
$(INSTALL_BIN) $(PKG_BUILD_DIR)/tayga $(1)/usr/sbin/ $(INSTALL_BIN) $(PKG_BUILD_DIR)/tayga $(1)/usr/sbin/
$(INSTALL_BIN) ./files/tayga-proto.sh $(1)/lib/netifd/proto/tayga.sh
endef endef
else else
define Package/tayga/install define Package/tayga/install


+ 92
- 0
ipv6/tayga/files/tayga-proto.sh View File

@ -0,0 +1,92 @@
#!/bin/sh
# tayga.sh - TAYGA proto
# Copyright (c) 2014 OpenWrt.org
[ -n "$INCLUDE_ONLY" ] || {
. /lib/functions.sh
. /lib/functions/network.sh
. ../netifd-proto.sh
init_proto "$@"
}
proto_tayga_setup() {
local cfg="$1"
local iface="$2"
local link="tayga-$cfg"
local ipv4_addr ipv6_addr prefix dynamic_pool ipaddr ip6addr
json_get_vars ipv4_addr ipv6_addr prefix dynamic_pool ipaddr ip6addr
[ -z "$ipv4_addr" -o -z "$prefix" ] && {
proto_notify_error "$cfg" "REQUIRED_PARAMETERS_MISSING"
proto_block_restart "$cfg"
return
}
local tmpconf="/var/etc/tayga-$cfg.conf"
mkdir -p /var/etc
mkdir -p /var/run/tayga/$cfg
echo "tun-device $link" >$tmpconf
echo "ipv4-addr $ipv4_addr" >>$tmpconf
[ -n "$ipv6_addr" ] &&
echo "ipv6-addr $ipv6_addr" >>$tmpconf
[ -n "$prefix" ] &&
echo "prefix $prefix" >>$tmpconf
[ -n "$dynamic_pool" ] &&
echo "dynamic-pool $dynamic_pool" >>$tmpconf
echo "data-dir /var/run/tayga/$cfg" >>$tmpconf
#TODO: Support static mapping of IPv4 <-> IPv6
# here we create TUN device and check configuration
tayga -c $tmpconf --mktun
[ "$?" -ne 0 ] && {
proto_notify_error "$cfg" "TAYGA_FAILED"
proto_block_restart "$cfg"
return
}
proto_init_update "$link" 1
[ -n "$ipaddr" ] && proto_add_ipv4_address "$ipaddr" "255.255.255.255"
[ -n "$ip6addr" ] && proto_add_ipv6_address "$ip6addr" "128"
[ -n "$ipv6_addr" ] && proto_add_ipv6_route "$ipv6_addr" "128"
[ -n "$dynamic_pool" ] && {
local pool="${dynamic_pool%%/*}"
local mask="${dynamic_pool##*/}"
proto_add_ipv4_route "$pool" "$mask"
}
[ -n "$prefix" ] && {
local prefix6="${prefix%%/*}"
local mask6="${prefix##*/}"
proto_add_ipv6_route "$prefix6" "$mask6"
}
proto_send_update "$cfg"
proto_run_command "$cfg" tayga -n -c $tmpconf \
-p /var/run/$link.pid
}
proto_tayga_teardown() {
local cfg="$1"
local tmpconf="/var/etc/tayga-$cfg.conf"
proto_kill_command "$cfg"
sleep 1
tayga -c $tmpconf --rmtun
}
proto_tayga_init_config() {
no_device=1
available=1
proto_config_add_string "ipv4_addr"
proto_config_add_string "ipv6_addr"
proto_config_add_string "prefix"
proto_config_add_string "dynamic_pool"
proto_config_add_string "ipaddr"
proto_config_add_string "ip6addr:ip6addr"
}
[ -n "$INCLUDE_ONLY" ] || {
add_protocol tayga
}

Loading…
Cancel
Save