diff options
Diffstat (limited to 'core/rootfs/rootfs-stage31/data')
-rw-r--r-- | core/rootfs/rootfs-stage31/data/inc/network.functions | 45 | ||||
-rw-r--r-- | core/rootfs/rootfs-stage31/data/inc/setup_network | 27 | ||||
-rw-r--r-- | core/rootfs/rootfs-stage31/data/inc/setup_network_retry | 41 |
3 files changed, 79 insertions, 34 deletions
diff --git a/core/rootfs/rootfs-stage31/data/inc/network.functions b/core/rootfs/rootfs-stage31/data/inc/network.functions index 9ec3eafb..a9edb5bc 100644 --- a/core/rootfs/rootfs-stage31/data/inc/network.functions +++ b/core/rootfs/rootfs-stage31/data/inc/network.functions @@ -1,15 +1,42 @@ +#!/bin/ash + wait_for_iface() { local DEVICE=$1 - local TIMEOUT=20 - echo -n "Waiting for interface $DEVICE: " + local TIMEOUT=10 + local state laststate current relax + local want= + local ret=1 # error + [ -n "$2" ] && TIMEOUT="$2" + echo -n "Waiting ${TIMEOUT}s for interface $DEVICE: " + TIMEOUT="$(( TIMEOUT * 2 ))" # Some systems don't have operstate. Seems to be hardware dependent - [ ! -e "/sys/class/net/${DEVICE}/operstate" ] && usleep 10000 - if [ -e "/sys/class/net/${DEVICE}/operstate" ]; then + [ -e "/sys/class/net/${DEVICE}/operstate" ] || sleep 1 + [ -e "/sys/class/net/${DEVICE}/operstate" ] && want="up" + [ -e "/sys/class/net/${DEVICE}/carrier" ] && want="${want}1" + if [ -n "$want" ]; then + relax=$(( TIMEOUT / 3 )) + [ "$relax" -lt 8 ] && relax=8 + current=0 while true; do # check linkstate - [ "x$(cat "/sys/class/net/${DEVICE}/operstate")" == "xup" ] && break - TIMEOUT=$(( TIMEOUT - 1 )) # don't wait forever, the pcnet iface of vmware will never be "up" although it's working - [ "$TIMEOUT" -le 0 ] && break + state="$( cat "/sys/class/net/${DEVICE}/operstate" 2> /dev/null )" + state="${state}$( cat "/sys/class/net/${DEVICE}/carrier" 2> /dev/null )" + [ "$state" != "$laststate" ] && echo -n "[$state]" + laststate="$state" + if [ "$state" = "$want" ]; then + ret=0 + break + fi + if [ "$current" -gt "$relax" ] && [ "$state" = "unknown1" ]; then + echo -n "better than nothing" + ret=0 + break + fi + current=$(( current + 1 )) # don't wait forever, the pcnet iface of vmware will never be "up" although it's working + if [ "$current" -ge "$TIMEOUT" ];then + echo -n "TIMEOUT" + break + fi # else echo -n "." usleep 500000 @@ -17,7 +44,9 @@ wait_for_iface() { else # we really don't have a operstate .. then just wait a sec and hope for the best. sleep 1 + echo -n "... no operstate or carrier, let's hope for the best..." fi - echo ".$(cat "/sys/class/net/${DEVICE}/operstate" 2>/dev/null)" + echo + return "$ret" } true diff --git a/core/rootfs/rootfs-stage31/data/inc/setup_network b/core/rootfs/rootfs-stage31/data/inc/setup_network index 3e17cf85..4f4c8a02 100644 --- a/core/rootfs/rootfs-stage31/data/inc/setup_network +++ b/core/rootfs/rootfs-stage31/data/inc/setup_network @@ -22,15 +22,14 @@ BRIDGE="br0" mkdir -p "${FUTURE_ROOT}/etc/udev/rules.d" -for i in 1 1 1 END; do - IP_OUT=$(ip a | grep -B 1 "/ether" | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-Z:]+) .*$#\1==\2#') - [ "x$i" == "xEND" ] && break - if ! echo "$IP_OUT" | grep -q -- "$MAC"; then - sleep "$i" - fi +for i in 1 1 END; do + IP_OUT="$( ip a | grep -B 1 "/ether" | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-Z:]+) .*$#\1==\2#' )" + echo "$IP_OUT" | grep -q -F -- "$MAC" && break + [ "x$i" = "xEND" ] && break + sleep "$i" done -if ! echo "$IP_OUT" | grep -q -- "$MAC"; then +if ! echo "$IP_OUT" | grep -q -F -- "$MAC"; then drop_shell "--- $(ip a) --- @@ -44,8 +43,8 @@ fi ADD_NIC=1 for LINE in $IP_OUT; do - IFACE=$(echo "$LINE" | awk -F '==' '{printf $1}') - IFMAC=$(echo "$LINE" | awk -F '==' '{printf $2}' | tr '[A-Z]' '[a-z]') # udev requires mac addesses to be lowercase (a-f), see http://www.debianhelp.co.uk/udev.htm + IFACE="${LINE%==*}" + IFMAC="$( echo "${LINE#*==}" | tr 'A-Z' 'a-z' )" # udev requires mac addesses to be lowercase (a-f), see http://www.debianhelp.co.uk/udev.htm echo "${IFACE} = ${IFMAC}" if [ "x$IFMAC" == "x$MAC" ]; then @@ -54,7 +53,7 @@ for LINE in $IP_OUT; do brctl setfd "$BRIDGE" 0.000000000001 ip link set addr "$IFMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE" ip link set dev "$IFACE" up - wait_for_iface "$IFACE" + wait_for_iface "$IFACE" 8 brctl addif "$BRIDGE" "$IFACE" || drop_shell "Could not add $IFACE to $BRIDGE" # save our variables for retry on fail @@ -69,7 +68,6 @@ for LINE in $IP_OUT; do [ -n "$GATEWAY" ] && ip route add default via "$GATEWAY" dev "$BRIDGE" else ip link set dev "$BRIDGE" up - NOIPYET="yes" fi # Ignore this device later on when systemd handles network interfaces (see hacked 99-systemd.rules in systemd data dir) echo "SUBSYSTEM==\"net\", ACTION==\"add\", KERNEL==\"eth*\", ATTR{address}==\"$IFMAC\", TAG+=\"openslxignore\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/01-ignore-boot-interface.rules" @@ -90,7 +88,7 @@ for LINE in $IP_OUT; do IFACE="" done -wait_for_iface "$BRIDGE" +wait_for_iface "$BRIDGE" 5 # udhcpc PARAM= @@ -116,9 +114,10 @@ echo "GATEWAY=$GATEWAY" >> /run/network.conf echo "BRIDGE=$BRIDGE" >> /run/network.conf echo "UID=$UID" >> /run/network.conf -udhcpc $PARAM -O ntpsrv -O domain -O wpad -O search -t 4 -T 3 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" +udhcpc $PARAM -O ntpsrv -O domain -O search -t 5 -T 3 -A 4 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" URET=$? -# udhcpc return value will be return value of this script +# if these were empty before, udhcpc might have filled them in [ -z "$CLIENTIP" ] && CLIENTIP=$(cat /run/firstip) [ -z "$GATEWAY" ] && GATEWAY=$(cat /run/firstgw) +# udhcpc return value will be return value of this script return $URET diff --git a/core/rootfs/rootfs-stage31/data/inc/setup_network_retry b/core/rootfs/rootfs-stage31/data/inc/setup_network_retry index 5ac28a57..76923703 100644 --- a/core/rootfs/rootfs-stage31/data/inc/setup_network_retry +++ b/core/rootfs/rootfs-stage31/data/inc/setup_network_retry @@ -1,34 +1,51 @@ #!/bin/ash -source /inc/network.functions source /run/network.conf for i in 1 2 3 4 5 6 7 8; do echo "<$i> Try to fix broken network" echo -n "Take interface $IFACE down .. " - ip link set dev $IFACE down - usleep 10000 + ip link set dev "$BRIDGE" down + ip link set dev "$IFACE" down + usleep 100000 echo "and up again.." - ip link set dev $IFACE up - ip link set dev $BRIDGE up + ip link set dev "$IFACE" up usleep 100000 - wait_for_iface "$IFACE" + wait_for_iface "$IFACE" "$(( 15 + i * 2 ))" + retval=$? + ip link set dev "$BRIDGE" up + if [ "$retval" -eq 0 ] && [ "$i" -ge 4 ] && [ -n "$CLIENTIP" ] && [ -n "$GATEWAY" ]; then + echo "....." + usleep 100000 + echo "Checking if static IP config works...." + if ping -c1 -w2 "$GATEWAY" &> /dev/null || ping -c1 -w2 "$SERVERIP" &> /dev/null; then + echo "apparently so." + echo "Trying to boot without DHCP config (DNS, Hostname, ...), YMMV!" + sleep 3 + RET=0 + break + fi + echo "...nope..." + fi + wait_for_iface "$BRIDGE" 10 + usleep 100000 - udhcpc $PARAM -O domain -O nissrv -O nisdomain -O wpad -O search -t 5 -T 2 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" + udhcpc $PARAM -O ntpsrv -O domain -O search -t "$(( 2 + i / 2 ))" -T "$(( 4 + i ))" -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" \ + || udhcpc $PARAM -O ntpsrv -O domain -O search -t "$(( 2 + i / 2 ))" -T "$(( 4 + i ))" -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" + RET="$?" - if [ $? -eq 0 ]; then + if [ "$RET" -eq 0 ]; then echo "Finally fixed IP config. Continue boot." - RET=0 break - else - RET=1 fi done -[ $RET -gt 0 ] && drop_shell "Something is really broken.. Please check your network cable and reset your computer." +[ $RET -gt 0 ] && drop_shell "Something is really broken.. Please check your network cable and reset your computer. +$(ip a) +$(ip r s)" # create correct return value [ $RET -eq 0 ] |