mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2024-12-18 06:53:08 +02:00
[package] 6in4: 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@32400 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
f6a09e69e9
commit
a17b7b615d
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2010-2011 OpenWrt.org
|
# Copyright (C) 2010-2012 OpenWrt.org
|
||||||
#
|
#
|
||||||
# This is free software, licensed under the GNU General Public License v2.
|
# This is free software, licensed under the GNU General Public License v2.
|
||||||
# See /LICENSE for more information.
|
# See /LICENSE for more information.
|
||||||
@ -8,7 +8,7 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=6in4
|
PKG_NAME:=6in4
|
||||||
PKG_VERSION:=10
|
PKG_VERSION:=11
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
@ -1,23 +1,14 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# 6in4.sh - IPv6-in-IPv4 tunnel backend
|
# 6in4.sh - IPv6-in-IPv4 tunnel backend
|
||||||
# Copyright (c) 2010 OpenWrt.org
|
# Copyright (c) 2010-2012 OpenWrt.org
|
||||||
|
|
||||||
[ -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_6in4_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_6in4_wanip() {
|
|
||||||
local ip=$(ip -4 a s dev "$1"); ip="${ip#*inet }"
|
|
||||||
echo "${ip%%[^0-9.]*}"
|
|
||||||
}
|
|
||||||
|
|
||||||
tun_error() {
|
tun_error() {
|
||||||
local cfg="$1"; shift;
|
local cfg="$1"; shift;
|
||||||
|
|
||||||
@ -30,42 +21,20 @@ proto_6in4_setup() {
|
|||||||
local iface="$2"
|
local iface="$2"
|
||||||
local link="6in4-$cfg"
|
local link="6in4-$cfg"
|
||||||
|
|
||||||
json_get_var mtu mtu
|
local mtu ttl local4 peeraddr ip6addr tunnelid username password
|
||||||
json_get_var ttl ttl
|
json_get_vars mtu ttl local4 peeraddr ip6addr tunnelid username password
|
||||||
json_get_var local4 ipaddr
|
|
||||||
json_get_var remote4 peeraddr
|
|
||||||
json_get_var ip6addr ip6addr
|
|
||||||
json_get_var tunnelid tunnelid
|
|
||||||
json_get_var username username
|
|
||||||
json_get_var password password
|
|
||||||
|
|
||||||
[ -z "$ip6addr" -o -z "$remote4" ] && {
|
[ -z "$ip6addr" -o -z "$peeraddr" ] && {
|
||||||
tun_error "$cfg" "MISSING_ADDRESS"
|
tun_error "$cfg" "MISSING_ADDRESS"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
[ -z "$local4" ] && {
|
[ -z "$local4" ] && {
|
||||||
local wanif=$(find_6in4_wanif)
|
local wanif
|
||||||
[ -z "$wanif" ] && {
|
if ! network_find_wan wanif || ! network_get_ipaddr local4 "$wanif"; then
|
||||||
tun_error "$cfg" "NO_WAN_LINK"
|
tun_error "$cfg" "NO_WAN_LINK"
|
||||||
return
|
return
|
||||||
}
|
fi
|
||||||
|
|
||||||
. /lib/network/config.sh
|
|
||||||
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.
|
|
||||||
[ -n "$wanif" ] && local4=$(find_6in4_wanip "$wanif")
|
|
||||||
|
|
||||||
[ -z "$local4" ] && {
|
|
||||||
tun_error "$cfg" "NO_WAN_LINK"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local local6="${ip6addr%%/*}"
|
local local6="${ip6addr%%/*}"
|
||||||
@ -81,7 +50,7 @@ proto_6in4_setup() {
|
|||||||
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 "$local4"
|
||||||
json_add_string remote "$remote4"
|
json_add_string remote "$peeraddr"
|
||||||
proto_close_tunnel
|
proto_close_tunnel
|
||||||
|
|
||||||
proto_send_update "$cfg"
|
proto_send_update "$cfg"
|
||||||
|
Loading…
Reference in New Issue
Block a user