6to4: use network_find_wan() and network_get_iapddr() to find local ip, use json_get_vars() to read settings

SVN-Revision: 32402
owl
Jo-Philipp Wich 2012-06-17 13:17:39 +00:00
parent 89732577aa
commit bb6dde0fbf
2 changed files with 13 additions and 44 deletions

View File

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=6to4 PKG_NAME:=6to4
PKG_VERSION:=8 PKG_VERSION:=9
PKG_RELEASE:=1 PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/package.mk

View File

@ -4,20 +4,11 @@
[ -n "$INCLUDE_ONLY" ] || { [ -n "$INCLUDE_ONLY" ] || {
. /lib/functions.sh . /lib/functions.sh
. /lib/functions/network.sh
. ../netifd-proto.sh . ../netifd-proto.sh
init_proto "$@" 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() { find_6to4_prefix() {
local ip4="$1" local ip4="$1"
local oIFS="$IFS"; IFS="."; set -- $ip4; IFS="$oIFS" local oIFS="$IFS"; IFS="."; set -- $ip4; IFS="$oIFS"
@ -119,46 +110,24 @@ proto_6to4_setup() {
local iface="$2" local iface="$2"
local link="6to4-$cfg" local link="6to4-$cfg"
json_get_var mtu mtu local mtu ttl ipaddr adv_subnet adv_interface adv_valid_lifetime adv_preferred_lifetime
json_get_var ttl ttl json_get_vars mtu ttl ipaddr adv_subnet adv_interface adv_valid_lifetime adv_preferred_lifetime
json_get_var local4 ipaddr
json_get_var adv_subnet adv_subnet [ -z "$ipaddr" ] && {
json_get_var adv_interface adv_interface local wanif
json_get_var adv_valid_lifetime adv_valid_lifetime if ! network_find_wan wanif || ! network_get_ipaddr ipaddr "$wanif"; then
json_get_var adv_preferred_lifetime adv_preferred_lifetime tun_error "$cfg" "NO_WAN_LINK"
return
local wanif=$(find_6to4_wanif) fi
[ -z "$wanif" ] && {
tun_error "$cfg" "NO_WAN_LINK"
return
} }
. /lib/network/config.sh test_6to4_rfc1918 "$ipaddr" && {
local wancfg="$(find_config "$wanif")"
[ -z "$wancfg" ] && {
tun_error "$cfg" "NO_WAN_LINK"
return
}
# 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
}
test_6to4_rfc1918 "$local4" && {
tun_error "$cfg" "INVALID_LOCAL_ADDRESS" tun_error "$cfg" "INVALID_LOCAL_ADDRESS"
return return
} }
# find our local prefix # find our local prefix
local prefix6=$(find_6to4_prefix "$local4") local prefix6=$(find_6to4_prefix "$ipaddr")
local local6="$prefix6::1" local local6="$prefix6::1"
proto_init_update "$link" 1 proto_init_update "$link" 1
@ -169,7 +138,7 @@ proto_6to4_setup() {
json_add_string mode sit json_add_string mode sit
json_add_int mtu "${mtu:-1280}" json_add_int mtu "${mtu:-1280}"
json_add_int ttl "${ttl:-64}" json_add_int ttl "${ttl:-64}"
json_add_string local "$local4" json_add_string local "$ipaddr"
proto_close_tunnel proto_close_tunnel
proto_send_update "$cfg" proto_send_update "$cfg"