2 # 6in4.sh - IPv6-in-IPv4 tunnel backend
3 # Copyright (c) 2010 OpenWrt.org
5 [ -n "$INCLUDE_ONLY" ] ||
{
12 local if=$
(ip
-4 r l e
0.0.0.0/0); if="${if#default* dev }"; if="${if%% *}"
13 [ -n "$if" ] && grep -qs "^ *$if:" /proc
/net
/dev
&& echo "$if"
17 local ip
=$
(ip
-4 a s dev
"$1"); ip
="${ip#*inet }"
18 echo "${ip%%[^0-9.]*}"
22 local cfg
="$1"; shift;
24 [ -n "$1" ] && proto_notify_error
"$cfg" "$@"
25 proto_block_restart
"$cfg"
31 local link
="6in4-$cfg"
35 json_get_var local4 ipaddr
36 json_get_var remote4 peeraddr
37 json_get_var ip6addr ip6addr
38 json_get_var tunnelid tunnelid
39 json_get_var username username
40 json_get_var password password
42 [ -z "$ip6addr" -o -z "$remote4" ] && {
43 tun_error
"$cfg" "MISSING_ADDRESS"
48 local wanif
=$
(find_6in4_wanif
)
50 tun_error
"$cfg" "NO_WAN_LINK"
54 .
/lib
/network
/config.sh
55 local wancfg
="$(find_config "$wanif")"
57 tun_error
"$cfg" "NO_WAN_LINK"
61 # If local4 is unset, guess local IPv4 address from the
62 # interface used by the default route.
63 [ -n "$wanif" ] && local4
=$
(find_6in4_wanip
"$wanif")
66 tun_error
"$cfg" "NO_WAN_LINK"
71 local local6
="${ip6addr%%/*}"
72 local mask6
="${ip6addr##*/}"
73 [[ "$local6" = "$mask6" ]] && mask6
=
75 proto_init_update
"$link" 1
76 proto_add_ipv6_address
"$local6" "$mask6"
77 proto_add_ipv6_route
"::" 0
80 json_add_string mode sit
81 json_add_int mtu
"${mtu:-1280}"
82 json_add_int ttl
"${ttl:-64}"
83 json_add_string
local "$local4"
84 json_add_string remote
"$remote4"
87 proto_send_update
"$cfg"
89 [ -n "$tunnelid" -a -n "$username" -a -n "$password" ] && {
90 [ "${#password}" == 32 -a -z "${password//[a-fA-F0-9]/}" ] ||
{
91 password
="$(echo -n "$password" | md5sum)"; password
="${password%% *}"
94 local url
="http://ipv4.tunnelbroker.net/ipv4_end.php?ip=AUTO&apikey=$username&pass=$password&tid=$tunnelid"
98 while [ $
((++try
)) -le $max ]; do
99 wget
-qO/dev
/null
"$url" 2>/dev
/null
&& break
105 proto_6in4_teardown
() {
109 proto_6in4_init_config
() {
113 proto_config_add_string
"ipaddr"
114 proto_config_add_string
"ip6addr"
115 proto_config_add_string
"peeraddr"
116 proto_config_add_string
"tunnelid"
117 proto_config_add_string
"username"
118 proto_config_add_string
"password"
119 proto_config_add_int
"mtu"
120 proto_config_add_int
"ttl"
123 [ -n "$INCLUDE_ONLY" ] ||
{