aboutsummaryrefslogtreecommitdiff
path: root/ipv6/tayga/files/tayga-proto.sh
diff options
context:
space:
mode:
authorOndřej Caletka <ondrej@caletka.cz>2014-06-23 10:55:22 +0200
committerOndřej Caletka <ondrej@caletka.cz>2014-06-23 16:25:05 +0200
commit545b84c5478774872fa8236d297854570a90fccf (patch)
treea53c42cbc0d4ef2bda2f29e2c975c64e2d8a07b4 /ipv6/tayga/files/tayga-proto.sh
parent8a90bbadd7e11444713da51827a93600e8355f1b (diff)
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>
Diffstat (limited to 'ipv6/tayga/files/tayga-proto.sh')
-rwxr-xr-xipv6/tayga/files/tayga-proto.sh92
1 files changed, 92 insertions, 0 deletions
diff --git a/ipv6/tayga/files/tayga-proto.sh b/ipv6/tayga/files/tayga-proto.sh
new file mode 100755
index 000000000..6bec0b60d
--- /dev/null
+++ b/ipv6/tayga/files/tayga-proto.sh
@@ -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
+}