network: wait for interfaces to come up, before proceeding

master
Harald Hoyer 2009-10-06 15:07:52 +02:00
parent 8f397a9be7
commit bf87d252f3
3 changed files with 15 additions and 2 deletions

View File

@ -17,6 +17,7 @@ setup_interface() {
echo ip link set $netif down echo ip link set $netif down
echo ip link set $netif mtu $mtu echo ip link set $netif mtu $mtu
echo ip link set $netif up echo ip link set $netif up
echo wait_for_if_up $netif
fi > /tmp/net.$netif.up fi > /tmp/net.$netif.up


echo ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif >> /tmp/net.$netif.up echo ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif >> /tmp/net.$netif.up
@ -52,6 +53,7 @@ netif=$interface
case $reason in case $reason in
PREINIT) PREINIT)
ip link set $netif up ip link set $netif up
wait_for_if_up $netif
;; ;;
BOUND) BOUND)
setup_interface setup_interface

View File

@ -32,8 +32,9 @@ do_dhcp() {


# Handle static ip configuration # Handle static ip configuration
do_static() { do_static() {
{ {
echo ip link set $netif up echo ip link set $netif up
echo wait_for_if_up $netif
echo ip addr flush dev $netif echo ip addr flush dev $netif
echo ip addr add $ip/$mask dev $netif echo ip addr add $ip/$mask dev $netif
} > /tmp/net.$netif.up } > /tmp/net.$netif.up
@ -89,6 +90,7 @@ fi
# start bridge if necessary # start bridge if necessary
if [ "$netif" = "$bridgename" ] && [ ! -e /tmp/net.$bridgename.up ]; then if [ "$netif" = "$bridgename" ] && [ ! -e /tmp/net.$bridgename.up ]; then
ip link set $ethname up ip link set $ethname up
wait_for_if_up $ethname
# Create bridge and add eth to bridge # Create bridge and add eth to bridge
brctl addbr $bridgename brctl addbr $bridgename
brctl setfd $bridgename 0 brctl setfd $bridgename 0

View File

@ -152,4 +152,13 @@ udevproperty() {
fi fi
} }



wait_for_if_up() {
local cnt=0
while [ $cnt -lt 20 ]; do
li=$(ip link show $1)
[ -z "${li##*state UP*}" ] && return 0
sleep 0.1
cnt=$[cnt+1]
done
return 1
}