2 # 6in4.sh - IPv6-in-IPv4 tunnel backend
3 # Copyright (c) 2010-2014 OpenWrt.org
5 [ -n "$INCLUDE_ONLY" ] || {
7 . /lib/functions/network.sh
15 local link="6in4-$cfg"
17 local mtu ttl tos ipaddr peeraddr ip6addr ip6prefix tunnelid username password updatekey sourcerouting
18 json_get_vars mtu ttl tos ipaddr peeraddr ip6addr ip6prefix tunnelid username password updatekey sourcerouting
20 [ -z "$peeraddr" ] && {
21 proto_notify_error "$cfg" "MISSING_ADDRESS"
22 proto_block_restart "$cfg"
26 ( proto_add_host_dependency "$cfg" 0.0.0.0 )
30 if ! network_find_wan wanif || ! network_get_ipaddr ipaddr "$wanif"; then
31 proto_notify_error "$cfg" "NO_WAN_LINK"
36 proto_init_update "$link" 1
39 [ "$sourcerouting" != "0" ] && source="::/128"
40 proto_add_ipv6_route "::" 0 "" "" "" "$source"
42 [ -n "$ip6addr" ] && {
43 local local6="${ip6addr%%/*}"
44 local mask6="${ip6addr##*/}"
45 [[ "$local6" = "$mask6" ]] && mask6=
46 proto_add_ipv6_address "$local6" "$mask6"
47 [ "$sourcerouting" != "0" ] && proto_add_ipv6_route "::" 0 "" "" "" "$local6/$mask6"
50 [ -n "$ip6prefix" ] && {
51 proto_add_ipv6_prefix "$ip6prefix"
52 [ "$sourcerouting" != "0" ] && proto_add_ipv6_route "::" 0 "" "" "" "$ip6prefix"
56 json_add_string mode sit
57 json_add_int mtu "${mtu:-1280}"
58 json_add_int ttl "${ttl:-64}"
59 [ -n "$tos" ] && json_add_string tos "$tos"
60 json_add_string local "$ipaddr"
61 json_add_string remote "$peeraddr"
64 proto_send_update "$cfg"
66 [ -n "$tunnelid" -a -n "$username" -a \( -n "$password" -o -n "$updatekey" \) ] && {
67 [ -n "$updatekey" ] && password="$updatekey"
70 local wget_opts="-qO/dev/null"
71 if wget --version | grep -qF "+https"; then
73 [ -z "$(find ${SSL_CERT_DIR-/etc/ssl/certs} -name "*.0" 2>/dev/null)" ] && {
74 wget_opts="$wget_opts --no-check-certificate"
78 local url="$http://ipv4.tunnelbroker.net/nic/update?username=$username&password=$password&hostname=$tunnelid"
82 while [ $((++try)) -le $max ]; do
83 ( exec wget $wget_opts "$url" 2>/dev/null ) &
85 ( sleep 5; kill $pid 2>/dev/null ) &
91 proto_6in4_teardown() {
95 proto_6in4_init_config() {
99 proto_config_add_string "ipaddr"
100 proto_config_add_string "ip6addr"
101 proto_config_add_string "ip6prefix"
102 proto_config_add_string "peeraddr"
103 proto_config_add_string "tunnelid"
104 proto_config_add_string "username"
105 proto_config_add_string "password"
106 proto_config_add_string "updatekey"
107 proto_config_add_int "mtu"
108 proto_config_add_int "ttl"
109 proto_config_add_string "tos"
110 proto_config_add_boolean "sourcerouting"
113 [ -n "$INCLUDE_ONLY" ] || {