| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# This file is part of the FreeWRT project. FreeWRT is copyrighted |
| 4 |
# material, please see the LICENCE file in the top-level directory |
| 5 |
# or at http://www.freewrt.org/licence for details. |
| 6 |
# |
| 7 |
# Christian Fischer <spaetzle@freewrt.org> |
| 8 |
# Thorsten Glaser <tg@freewrt.org> |
| 9 |
# |
| 10 |
|
| 11 |
config() { |
| 12 |
[[ $1 = 1 ]] |
| 13 |
} |
| 14 |
|
| 15 |
what=${0##*/} |
| 16 |
case $what in |
| 17 |
ifup) |
| 18 |
;; |
| 19 |
ifdown) |
| 20 |
;; |
| 21 |
*) |
| 22 |
echo "Usage: ifup|ifdown [options]" |
| 23 |
echo "For options see man busybox" |
| 24 |
exit 1 |
| 25 |
;; |
| 26 |
esac |
| 27 |
|
| 28 |
. /etc/rc.conf |
| 29 |
. /etc/network/mfunctions.sh |
| 30 |
redirect="2>&-" |
| 31 |
|
| 32 |
if config $FWIFUPDOWN_DEBUG; then |
| 33 |
set -x |
| 34 |
redirect= |
| 35 |
fi |
| 36 |
[[ -e /tmp/.booting ]] && redirect="$redirect >/dev/console" |
| 37 |
|
| 38 |
# cleanup ifstate files |
| 39 |
rm -rf /tmp/ifupdown/ifstate |
| 40 |
mkdir -p /tmp/ifupdown/ifstate |
| 41 |
|
| 42 |
eval IFUPDOWN_ENV= $(grep '^FWIFUPDOWN_' /etc/rc.conf |sed "s/#.*//g") \ |
| 43 |
busybox $what $@ $redirect |
| 44 |
|
| 45 |
i=0 # did we print the initialisation message? |
| 46 |
j=0 # timeout in seconds |
| 47 |
rv=0 # exit status of this script |
| 48 |
while sleep 1; do |
| 49 |
if test $j -gt 30; then |
| 50 |
mstate 1 |
| 51 |
merr "bridge initialisation timed out" |
| 52 |
rv=1 |
| 53 |
break |
| 54 |
fi |
| 55 |
for x in /tmp/ifupdown/ifstate/bridge/*; do |
| 56 |
# any bridges to check? |
| 57 |
test -e "$x" || break 2 # no -> out of both loops |
| 58 |
# print initialisation message, but once only |
| 59 |
test $i = 1 || mprint -n \ |
| 60 |
"Waiting for bridge initialisation to finish" |
| 61 |
i=1 |
| 62 |
# check this bridge for its states |
| 63 |
s=ok |
| 64 |
for state in $(brctl showstp ${x##*/} | \ |
| 65 |
fgrep state | sed "s/^.*state//"); do |
| 66 |
test x"$state" = x"forwarding" && continue |
| 67 |
# if only one is not forwarding, wait |
| 68 |
s=no |
| 69 |
break |
| 70 |
done |
| 71 |
test $s = ok || break # not ok? wait one second |
| 72 |
rm -f $x # this bridge done, check next ones |
| 73 |
done |
| 74 |
j=$(expr $j + 1) |
| 75 |
done |
| 76 |
test $i = 0 || { |
| 77 |
mstate $rv |
| 78 |
minfo "took $j seconds" |
| 79 |
} |
| 80 |
|
| 81 |
# vim:ts=4 |