[package] 6in4: implement metric option
[openwrt/svn-archive/archive.git] / package / 6in4 / files / 6in4.sh
index 5e416ee0bd557d37b2b649cd91cd934c9272365f..5f8dfffe5785913db4b0308c2fd44d8f2b35cbb4 100755 (executable)
@@ -2,13 +2,13 @@
 # Copyright (c) 2010 OpenWrt.org
 
 find_6in4_wanif() {
-       local if=$(ip -4 r l e 0/0); if="${if#default via * dev }"; if="${if%% *}"
+       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]* brd *}"
+       echo "${ip%%[^0-9.]*}"
 }
 
 # Hook into scan_interfaces() to synthesize a .device option
@@ -28,8 +28,7 @@ setup_interface_6in4() {
        local cfg="$2"
        local link="6in4-$cfg"
 
-       local local4
-       config_get local4 "$cfg" ipaddr
+       local local4=$(uci_get network "$cfg" ipaddr)
 
        local remote4
        config_get remote4 "$cfg" peeraddr
@@ -43,6 +42,9 @@ setup_interface_6in4() {
        local ttl
        config_get ttl "$cfg" ttl
 
+       local metric
+       config_get metric "$cfg" metric
+
        local defaultroute
        config_get_bool defaultroute "$cfg" defaultroute 1
 
@@ -62,17 +64,16 @@ setup_interface_6in4() {
                uci_set_state network "$cfg" ifname $link
                uci_set_state network "$cfg" auto 0
 
-               ip tunnel add $link mode sit remote $remote4 local $local4 ttl 255
+               ip tunnel add $link mode sit remote $remote4 local $local4 ttl ${ttl:-64}
                ip link set $link up
                ip link set mtu ${mtu:-1280} dev $link
-               ip tunnel change $link ttl ${ttl:-64}
                ip addr add $local6 dev $link
 
                uci_set_state network "$cfg" ipaddr $local4
                uci_set_state network "$cfg" ip6addr $local6
 
                [ "$defaultroute" = 1 ] && {
-                       ip -6 route add ::/0 dev $link
+                       ip -6 route add ::/0 ${metric:+metric $metric} dev $link
                        uci_set_state network "$cfg" defaultroute 1
                }