handle_file () {
    #index = array size
    local index=${#rt_array_routes[*]}
    . $1
    routenum=0
    while [ "x$(eval echo '$'ADDRESS$routenum)x" != "xx" ]; do
        #calc and output PREFIX=xx with ADDRESS0 and NETMASK0
        eval $(ipcalc -p $(eval echo '$'ADDRESS$routenum) $(eval echo '$'NETMASK$routenum))
        line="$(eval echo '$'ADDRESS$routenum)/$PREFIX"
        if [[ ! "${rt_array_routes[@]}" =~ "${line}" ]];then
            rt_array_routes[$index]=$line
        fi
        routenum=$(($routenum+1))
        index=$(($index+1))
        unset PREFIX
    done
}



handle_ip_file() {
    local MATCH='^[[:space:]]*(\#.*)?$'
    local f_name t type= file=$1 proto="-4"
    f_name=${file##*/}
    t=${f_name%%-*}
    type=${t%%6}

    if [ "$type" != "$t" ]; then
        proto="-6"
    fi
    # { cat "$file" ; echo ; } | while read line; do
    while read line; do
        #idx = array size
         local idx=${#rt_array_routes[*]}
        if [[ ! "$line" =~ $MATCH ]]; then
            tmp="$(eval echo $line |awk '{print $1}')"
            rt_array_routes[$idx]=${tmp}
        fi
    done < "$file"
}

get_route_from_route_files() {
    local FILES="/etc/sysconfig/network-scripts/route-$1 /etc/sysconfig/network-scripts/route6-$1"

    for file in $FILES; do
        if [ -f "$file" ]; then
            if grep -Eq '^[[:space:]]*ADDRESS[0-9]+=' $file ; then
                # new format like ADDRESS0=xxx NETMASK0=xxx
                handle_file $file ${1%:*}
            else
                # older format like 192.168.1.0/24 via 10.0.0.100
                handle_ip_file $file
            fi
        fi
    done
}