2 # 6in4.sh - IPv6-in-IPv4 tunnel backend
3 # Copyright (c) 2010-2015 OpenWrt.org
5 [ -n "$INCLUDE_ONLY" ] ||
{
7 .
/lib
/functions
/network.sh
16 (while [ $((timeout--)) -gt 0 ]; do
19 done; kill -9 $$) 2>/dev/null &
28 local link
="6in4-$cfg"
30 local mtu ttl tos ipaddr peeraddr ip6addr ip6prefix tunlink tunnelid username password updatekey
31 json_get_vars mtu ttl tos ipaddr peeraddr ip6addr ip6prefix tunlink tunnelid username password updatekey
33 [ -z "$peeraddr" ] && {
34 proto_notify_error
"$cfg" "MISSING_ADDRESS"
35 proto_block_restart
"$cfg"
39 ( proto_add_host_dependency
"$cfg" "$peeraddr" "$tunlink" )
42 local wanif
="$tunlink"
43 if [ -z "$wanif" ] && ! network_find_wan wanif
; then
44 proto_notify_error
"$cfg" "NO_WAN_LINK"
48 if ! network_get_ipaddr ipaddr
"$wanif"; then
49 proto_notify_error
"$cfg" "NO_WAN_LINK"
54 proto_init_update
"$link" 1
56 [ -n "$ip6addr" ] && {
57 local local6
="${ip6addr%%/*}"
58 local mask6
="${ip6addr##*/}"
59 [[ "$local6" = "$mask6" ]] && mask6
=
60 proto_add_ipv6_address
"$local6" "$mask6"
61 proto_add_ipv6_route
"::" 0 "" "" "" "$local6/$mask6"
64 [ -n "$ip6prefix" ] && {
65 proto_add_ipv6_prefix
"$ip6prefix"
66 proto_add_ipv6_route
"::" 0 "" "" "" "$ip6prefix"
70 json_add_string mode sit
71 json_add_int mtu
"${mtu:-1280}"
72 json_add_int ttl
"${ttl:-64}"
73 [ -n "$tos" ] && json_add_string tos
"$tos"
74 json_add_string
local "$ipaddr"
75 json_add_string remote
"$peeraddr"
76 [ -n "$tunlink" ] && json_add_string link
"$tunlink"
79 proto_send_update
"$cfg"
81 [ -n "$tunnelid" -a -n "$username" -a \
( -n "$password" -o -n "$updatekey" \
) ] && {
82 [ -n "$updatekey" ] && password
="$updatekey"
85 local urlget
="uclient-fetch"
86 local urlget_opts
="-qO-"
87 local ca_path
="${SSL_CERT_DIR:-/etc/ssl/certs}"
89 [ -f /lib
/libustream-ssl.so
] && http
=https
90 [ "$http" = "https" -a -z "$(find $ca_path -name "*.0" 2>/dev/null)" ] && {
91 urlget_opts
="$urlget_opts --no-check-certificate"
94 local url
="$http://ipv4.tunnelbroker.net/nic/update?hostname=$tunnelid"
100 while [ $
((++try
)) -le $max ]; do
101 if proto_6in4_update
$urlget $urlget_opts --user="$username" --password="$password" "$url" 2>&1 | \
102 sed -e 's,^Killed$,timeout,' -e "s,^,update $try/$max: ," | \
105 logger
-t "$link" "updated"
110 logger
-t "$link" "update failed"
115 proto_6in4_teardown
() {
119 proto_6in4_init_config
() {
123 proto_config_add_string
"ipaddr"
124 proto_config_add_string
"ip6addr"
125 proto_config_add_string
"ip6prefix"
126 proto_config_add_string
"peeraddr"
127 proto_config_add_string
"tunlink"
128 proto_config_add_string
"tunnelid"
129 proto_config_add_string
"username"
130 proto_config_add_string
"password"
131 proto_config_add_string
"updatekey"
132 proto_config_add_int
"mtu"
133 proto_config_add_int
"ttl"
134 proto_config_add_string
"tos"
137 [ -n "$INCLUDE_ONLY" ] ||
{