base-files: change network_find_wan() procedure to ignore default gateways in differe...
[openwrt/staging/lynxis/omap.git] / package / base-files / files / lib / functions / network.sh
index d242abbe62db559c8d5482ecef30979fa5995adb..d86a504bf44c3f66392d5e2252e6fcadb293a687 100644 (file)
@@ -39,11 +39,11 @@ __network_parse_ifstatus()
                # parse addresses
                local __family
                for __family in 4 6; do
-                       if json_get_type __tmp "ipv${__family}_address" && [ "$__tmp" = array ]; then
+                       if json_is_a "ipv${__family}_address" array; then
 
                                json_select "ipv${__family}_address"
 
-                               if json_get_type __tmp 1 && [ "$__tmp" = object ]; then
+                               if json_is_a 1 object; then
 
                                        json_select 1
                                        __network_set_cache "${__key}_address${__family}" address
@@ -57,25 +57,43 @@ __network_parse_ifstatus()
                        fi
                done
 
+               # parse prefixes
+               if json_is_a "ipv6_prefix" array; then
+                       json_select "ipv6_prefix"
+
+                       if json_is_a 1 object; then
+                               json_select 1
+                               __network_set_cache "${__key}_prefix6_address"  address
+                               __network_set_cache "${__key}_prefix6_mask"     mask
+                               json_select ".."
+                       fi
+
+                       json_select ".."
+               fi
+
                # parse routes
-               if json_get_type __tmp route && [ "$__tmp" = array ]; then
+               if json_is_a route array; then
 
                        json_select "route"
 
                        local __idx=1
-                       while json_get_type __tmp "$__idx" && [ "$__tmp" = object ]; do
+                       while json_is_a "$__idx" object; do
 
                                json_select "$((__idx++))"
-                               json_get_var __tmp target
-
-                               case "${__tmp}" in
-                                       0.0.0.0)
-                                               __network_set_cache "${__key}_gateway4" nexthop
-                                       ;;
-                                       ::)
-                                               __network_set_cache "${__key}_gateway6" nexthop
-                                       ;;
-                               esac
+                               json_get_var __tmp table
+
+                               if [ -z "$__tmp" ]; then
+                                       json_get_var __tmp target
+
+                                       case "${__tmp}" in
+                                               0.0.0.0)
+                                                       __network_set_cache "${__key}_gateway4" nexthop
+                                               ;;
+                                               ::)
+                                                       __network_set_cache "${__key}_gateway6" nexthop
+                                               ;;
+                                       esac
+                               fi
 
                                json_select ".."
 
@@ -88,14 +106,14 @@ __network_parse_ifstatus()
                # parse dns info
                local __field
                for __field in "dns_server" "dns_search"; do
-                       if json_get_type __tmp "$__field" && [ "$__tmp" = array ]; then
+                       if json_is_a "$__field" array; then
 
                                json_select "$__field"
 
                                local __idx=1
                                local __dns=""
 
-                               while json_get_type __tmp "$__idx" && [ "$__tmp" = string ]; do
+                               while json_is_a "$__idx" string; do
 
                                        json_get_var __tmp "$((__idx++))"
                                        __dns="${__dns:+$__dns }$__tmp"
@@ -118,7 +136,7 @@ __network_parse_ifstatus()
                done
 
                # descend into inactive table
-               json_get_type __tmp "inactive" && [ "$__tmp" = object ] && json_select "inactive"
+               json_is_a "inactive" object && json_select "inactive"
 
        done
 
@@ -170,6 +188,19 @@ network_get_subnet()  { __network_ipaddr "$1" "$2" 4 1; }
 # 2: interface
 network_get_subnet6() { __network_ipaddr "$1" "$2" 6 1; }
 
+# determine IPv6 prefix
+network_get_prefix6() {
+       local __var="$1"
+       local __iface="$2"
+       local __address
+       local __mask
+
+       __network_parse_ifstatus "$__iface" || return 1
+       __network_export __mask "${__iface}_prefix6_mask" || return 1
+       __network_export "$__var" "${__iface}_prefix6_address" "/$__mask"
+       return $?
+}
+
 
 __network_gateway()
 {