|
@@ -0,0 +1,92 @@
|
|
1
|
+#!/bin/sh
|
|
2
|
+# tayga.sh - TAYGA proto
|
|
3
|
+# Copyright (c) 2014 OpenWrt.org
|
|
4
|
+
|
|
5
|
+[ -n "$INCLUDE_ONLY" ] || {
|
|
6
|
+ . /lib/functions.sh
|
|
7
|
+ . /lib/functions/network.sh
|
|
8
|
+ . ../netifd-proto.sh
|
|
9
|
+ init_proto "$@"
|
|
10
|
+}
|
|
11
|
+
|
|
12
|
+proto_tayga_setup() {
|
|
13
|
+ local cfg="$1"
|
|
14
|
+ local iface="$2"
|
|
15
|
+ local link="tayga-$cfg"
|
|
16
|
+
|
|
17
|
+ local ipv4_addr ipv6_addr prefix dynamic_pool ipaddr ip6addr
|
|
18
|
+ json_get_vars ipv4_addr ipv6_addr prefix dynamic_pool ipaddr ip6addr
|
|
19
|
+ [ -z "$ipv4_addr" -o -z "$prefix" ] && {
|
|
20
|
+ proto_notify_error "$cfg" "REQUIRED_PARAMETERS_MISSING"
|
|
21
|
+ proto_block_restart "$cfg"
|
|
22
|
+ return
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ local tmpconf="/var/etc/tayga-$cfg.conf"
|
|
26
|
+ mkdir -p /var/etc
|
|
27
|
+ mkdir -p /var/run/tayga/$cfg
|
|
28
|
+
|
|
29
|
+ echo "tun-device $link" >$tmpconf
|
|
30
|
+ echo "ipv4-addr $ipv4_addr" >>$tmpconf
|
|
31
|
+ [ -n "$ipv6_addr" ] &&
|
|
32
|
+ echo "ipv6-addr $ipv6_addr" >>$tmpconf
|
|
33
|
+ [ -n "$prefix" ] &&
|
|
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
|
|
39
|
+
|
|
40
|
+ # here we create TUN device and check configuration
|
|
41
|
+ tayga -c $tmpconf --mktun
|
|
42
|
+ [ "$?" -ne 0 ] && {
|
|
43
|
+ proto_notify_error "$cfg" "TAYGA_FAILED"
|
|
44
|
+ proto_block_restart "$cfg"
|
|
45
|
+ return
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ proto_init_update "$link" 1
|
|
49
|
+
|
|
50
|
+ [ -n "$ipaddr" ] && proto_add_ipv4_address "$ipaddr" "255.255.255.255"
|
|
51
|
+ [ -n "$ip6addr" ] && proto_add_ipv6_address "$ip6addr" "128"
|
|
52
|
+ [ -n "$ipv6_addr" ] && proto_add_ipv6_route "$ipv6_addr" "128"
|
|
53
|
+ [ -n "$dynamic_pool" ] && {
|
|
54
|
+ local pool="${dynamic_pool%%/*}"
|
|
55
|
+ local mask="${dynamic_pool##*/}"
|
|
56
|
+ proto_add_ipv4_route "$pool" "$mask"
|
|
57
|
+ }
|
|
58
|
+ [ -n "$prefix" ] && {
|
|
59
|
+ local prefix6="${prefix%%/*}"
|
|
60
|
+ local mask6="${prefix##*/}"
|
|
61
|
+ proto_add_ipv6_route "$prefix6" "$mask6"
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ proto_send_update "$cfg"
|
|
65
|
+
|
|
66
|
+ proto_run_command "$cfg" tayga -n -c $tmpconf \
|
|
67
|
+ -p /var/run/$link.pid
|
|
68
|
+
|
|
69
|
+}
|
|
70
|
+
|
|
71
|
+proto_tayga_teardown() {
|
|
72
|
+ local cfg="$1"
|
|
73
|
+ local tmpconf="/var/etc/tayga-$cfg.conf"
|
|
74
|
+ proto_kill_command "$cfg"
|
|
75
|
+ sleep 1
|
|
76
|
+ tayga -c $tmpconf --rmtun
|
|
77
|
+}
|
|
78
|
+
|
|
79
|
+proto_tayga_init_config() {
|
|
80
|
+ no_device=1
|
|
81
|
+ available=1
|
|
82
|
+ proto_config_add_string "ipv4_addr"
|
|
83
|
+ proto_config_add_string "ipv6_addr"
|
|
84
|
+ proto_config_add_string "prefix"
|
|
85
|
+ proto_config_add_string "dynamic_pool"
|
|
86
|
+ proto_config_add_string "ipaddr"
|
|
87
|
+ proto_config_add_string "ip6addr:ip6addr"
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+[ -n "$INCLUDE_ONLY" ] || {
|
|
91
|
+ add_protocol tayga
|
|
92
|
+}
|