2 # 6in4.sh - IPv6-in-IPv4 tunnel backend
3 # Copyright (c) 2010-2012 OpenWrt.org
5 [ -n "$INCLUDE_ONLY" ] || {
7 . /lib/functions/network.sh
15 local link="6in4-$cfg"
17 local mtu ttl ipaddr peeraddr ip6addr tunnelid username password
18 json_get_vars mtu ttl ipaddr peeraddr ip6addr tunnelid username password
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
37 proto_add_ipv6_route "::" 0
39 [ -n "$ip6addr" ] && {
40 local local6="${ip6addr%%/*}"
41 local mask6="${ip6addr##*/}"
42 [[ "$local6" = "$mask6" ]] && mask6=
43 proto_add_ipv6_address "$local6" "$mask6"
47 json_add_string mode sit
48 json_add_int mtu "${mtu:-1280}"
49 json_add_int ttl "${ttl:-64}"
50 json_add_string local "$ipaddr"
51 json_add_string remote "$peeraddr"
54 proto_send_update "$cfg"
56 [ -n "$tunnelid" -a -n "$username" -a -n "$password" ] && {
57 [ "${#password}" == 32 -a -z "${password//[a-fA-F0-9]/}" ] || {
58 password="$(echo -n "$password" | md5sum)"; password="${password%% *}"
61 local url="http://ipv4.tunnelbroker.net/ipv4_end.php?ip=AUTO&apikey=$username&pass=$password&tid=$tunnelid"
65 while [ $((++try)) -le $max ]; do
66 wget -qO/dev/null "$url" 2>/dev/null && break
72 proto_6in4_teardown() {
76 proto_6in4_init_config() {
80 proto_config_add_string "ipaddr"
81 proto_config_add_string "ip6addr"
82 proto_config_add_string "peeraddr"
83 proto_config_add_string "tunnelid"
84 proto_config_add_string "username"
85 proto_config_add_string "password"
86 proto_config_add_int "mtu"
87 proto_config_add_int "ttl"
90 [ -n "$INCLUDE_ONLY" ] || {