firewall: rework interface address determination to skip ipv6 addresses
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 16 May 2012 13:37:49 +0000 (13:37 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 16 May 2012 13:37:49 +0000 (13:37 +0000)
SVN-Revision: 31755

package/firewall/files/reflection.hotplug

index 73d9c61df8d49a756bc645e91baed9b505c12f25..62f509729175ba304e393152472fad48d03bf1fc 100644 (file)
@@ -9,24 +9,34 @@ find_iface_address()
        local ipaddr="$2"
        local prefix="$3"
 
+       local idx=1
        local tmp="$(ubus call network.interface."$iface" status 2>/dev/null)"
 
        json_load "${tmp:-{}}"
        json_get_type tmp address
 
        if [ "$tmp" = array ]; then
-
                json_select address
-               json_get_type tmp 1
-
-               if [ "$tmp" = object ]; then
 
-                       json_select 1
-                       [ -n "$ipaddr" ] && json_get_var "$ipaddr" address
-                       [ -n "$prefix" ] && json_get_var "$prefix" mask
-
-               fi
+               while true; do
+                       json_get_type tmp $idx
+                       [ "$tmp" = object ] || break
+
+                       json_select $((idx++))
+                       json_get_var tmp address
+
+                       case "$tmp" in
+                               *:*) json_select .. ;;
+                               *)
+                                       [ -n "$ipaddr" ] && json_get_var $ipaddr address
+                                       [ -n "$prefix" ] && json_get_var $prefix mask
+                                       return 0 
+                               ;;
+                       esac
+               done
        fi
+
+       return 1
 }
 
 if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then