diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2012-06-17 13:17:39 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2012-06-17 13:17:39 +0000 |
commit | 58795003a7d52f83cb0d67e51052e71398c6bdae (patch) | |
tree | e7db6cb7ae7280c639214cbfc1c5af89a4cb7cd7 /package/6to4/files | |
parent | 942bbda6d951f94157446abb3d3aa071c8cee58a (diff) | |
download | master-187ad058-58795003a7d52f83cb0d67e51052e71398c6bdae.tar.gz master-187ad058-58795003a7d52f83cb0d67e51052e71398c6bdae.tar.bz2 master-187ad058-58795003a7d52f83cb0d67e51052e71398c6bdae.zip |
[package] 6to4: use network_find_wan() and network_get_iapddr() to find local ip, use json_get_vars() to read settings
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@32402 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/6to4/files')
-rwxr-xr-x | package/6to4/files/6to4.sh | 55 |
1 files changed, 12 insertions, 43 deletions
diff --git a/package/6to4/files/6to4.sh b/package/6to4/files/6to4.sh index c2e911a6ef..5a1ad47594 100755 --- a/package/6to4/files/6to4.sh +++ b/package/6to4/files/6to4.sh @@ -4,20 +4,11 @@ [ -n "$INCLUDE_ONLY" ] || { . /lib/functions.sh + . /lib/functions/network.sh . ../netifd-proto.sh init_proto "$@" } -find_6to4_wanif() { - local if=$(ip -4 r l e 0.0.0.0/0); if="${if#default* dev }"; if="${if%% *}" - [ -n "$if" ] && grep -qs "^ *$if:" /proc/net/dev && echo "$if" -} - -find_6to4_wanip() { - local ip=$(ip -4 a s dev "$1"); ip="${ip#*inet }" - echo "${ip%%[^0-9.]*}" -} - find_6to4_prefix() { local ip4="$1" local oIFS="$IFS"; IFS="."; set -- $ip4; IFS="$oIFS" @@ -119,46 +110,24 @@ proto_6to4_setup() { local iface="$2" local link="6to4-$cfg" - json_get_var mtu mtu - json_get_var ttl ttl - json_get_var local4 ipaddr - - json_get_var adv_subnet adv_subnet - json_get_var adv_interface adv_interface - json_get_var adv_valid_lifetime adv_valid_lifetime - json_get_var adv_preferred_lifetime adv_preferred_lifetime - - local wanif=$(find_6to4_wanif) - [ -z "$wanif" ] && { - tun_error "$cfg" "NO_WAN_LINK" - return - } - - . /lib/network/config.sh - local wancfg="$(find_config "$wanif")" - [ -z "$wancfg" ] && { - tun_error "$cfg" "NO_WAN_LINK" - return - } + local mtu ttl ipaddr adv_subnet adv_interface adv_valid_lifetime adv_preferred_lifetime + json_get_vars mtu ttl ipaddr adv_subnet adv_interface adv_valid_lifetime adv_preferred_lifetime - # If local4 is unset, guess local IPv4 address from the - # interface used by the default route. - [ -z "$local4" ] && { - [ -n "$wanif" ] && local4=$(find_6to4_wanip "$wanif") - } - - [ -z "$local4" ] && { - tun_error "$cfg" "NO_WAN_LINK" - return + [ -z "$ipaddr" ] && { + local wanif + if ! network_find_wan wanif || ! network_get_ipaddr ipaddr "$wanif"; then + tun_error "$cfg" "NO_WAN_LINK" + return + fi } - test_6to4_rfc1918 "$local4" && { + test_6to4_rfc1918 "$ipaddr" && { tun_error "$cfg" "INVALID_LOCAL_ADDRESS" return } # find our local prefix - local prefix6=$(find_6to4_prefix "$local4") + local prefix6=$(find_6to4_prefix "$ipaddr") local local6="$prefix6::1" proto_init_update "$link" 1 @@ -169,7 +138,7 @@ proto_6to4_setup() { json_add_string mode sit json_add_int mtu "${mtu:-1280}" json_add_int ttl "${ttl:-64}" - json_add_string local "$local4" + json_add_string local "$ipaddr" proto_close_tunnel proto_send_update "$cfg" |