2 # tayga.sh - TAYGA proto
3 # Copyright (c) 2014 OpenWrt.org
5 [ -n "$INCLUDE_ONLY" ] ||
{
7 .
/lib
/functions
/network.sh
15 local link
="tayga-$cfg"
17 local ipv4_addr ipv6_addr prefix dynamic_pool ipaddr ip6addr noroutes
18 json_get_vars ipv4_addr ipv6_addr prefix dynamic_pool ipaddr ip6addr noroutes
19 [ -z "$ipv4_addr" -o -z "$prefix" ] && {
20 proto_notify_error
"$cfg" "REQUIRED_PARAMETERS_MISSING"
21 proto_block_restart
"$cfg"
25 local tmpconf
="/var/etc/tayga-$cfg.conf"
27 mkdir
-p /var
/run
/tayga
/$cfg
29 echo "tun-device $link" >$tmpconf
30 echo "ipv4-addr $ipv4_addr" >>$tmpconf
31 [ -n "$ipv6_addr" ] &&
32 echo "ipv6-addr $ipv6_addr" >>$tmpconf
34 echo "prefix $prefix" >>$tmpconf
35 [ -n "$dynamic_pool" ] &&
36 echo "dynamic-pool $dynamic_pool" >>$tmpconf
37 echo "data-dir /var/run/tayga/$cfg" >>$tmpconf
38 #TODO: Support static mapping of IPv4 <-> IPv6
40 # here we create TUN device and check configuration
41 tayga
-c $tmpconf --mktun
43 proto_notify_error
"$cfg" "TAYGA_FAILED"
44 proto_block_restart
"$cfg"
48 proto_init_update
"$link" 1
50 [ -n "$ipaddr" ] && proto_add_ipv4_address
"$ipaddr" "255.255.255.255"
51 [ -n "$ip6addr" ] && proto_add_ipv6_address
"$ip6addr" "128"
53 [ "$noroutes" != 1 ] && {
54 [ -n "$ipv6_addr" ] && proto_add_ipv6_route
"$ipv6_addr" "128"
55 [ -n "$dynamic_pool" ] && {
56 local pool
="${dynamic_pool%%/*}"
57 local mask
="${dynamic_pool##*/}"
58 proto_add_ipv4_route
"$pool" "$mask"
61 local prefix6
="${prefix%%/*}"
62 local mask6
="${prefix##*/}"
63 proto_add_ipv6_route
"$prefix6" "$mask6"
67 proto_send_update
"$cfg"
69 proto_run_command
"$cfg" tayga
-n -c $tmpconf \
74 proto_tayga_teardown
() {
76 local tmpconf
="/var/etc/tayga-$cfg.conf"
77 proto_kill_command
"$cfg"
79 tayga
-c $tmpconf --rmtun
82 proto_tayga_init_config
() {
85 proto_config_add_string
"ipv4_addr"
86 proto_config_add_string
"ipv6_addr"
87 proto_config_add_string
"prefix"
88 proto_config_add_string
"dynamic_pool"
89 proto_config_add_string
"ipaddr"
90 proto_config_add_string
"ip6addr:ip6addr"
91 proto_config_add_boolean
"noroutes"
94 [ -n "$INCLUDE_ONLY" ] ||
{