#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=40

# Set up a default mangement IP in case something goes wrong
setup_management() {
        local ifn="$1"

        ifconfig "$ifn:1" 127.1.6.8 up # use an invalid address as source for arping

        local ip=169.254.255.1
        while :; do
                if arping -c 1 -I "$ifn" -s 127.1.6.8 "$ip" >/dev/null 2>/dev/null; then
                        # already taken
                        ip="169.254.255.$((${ip##*\.} + 1))"
                else
                        break;
                fi

                # this should never happen:
                [ "${ip##*\.}" = "254" ] && {
                        ifconfig "$ifn:1" 0.0.0.0 down
                        return 1
                }
        done
        ifconfig "$ifn:1" "$ip" netmask 255.255.0.0
}

start() {
	. /lib/fon/config.sh
	setup_management "$mgmt_ifname"
}

