From 98877fe432adc85d54608c85b9efbc8531fcda29 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 10 Sep 2019 11:35:08 +0200 Subject: [rootfs-stage31] More brain damage trying to get stubborn NICs to work --- .../rootfs-stage31/data/inc/network.functions | 8 ++++- .../rootfs-stage31/data/inc/setup_network_retry | 36 ++++++++++++++++------ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/core/rootfs/rootfs-stage31/data/inc/network.functions b/core/rootfs/rootfs-stage31/data/inc/network.functions index a027ea63..a9edb5bc 100644 --- a/core/rootfs/rootfs-stage31/data/inc/network.functions +++ b/core/rootfs/rootfs-stage31/data/inc/network.functions @@ -5,6 +5,7 @@ wait_for_iface() { 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 ))" @@ -22,9 +23,13 @@ wait_for_iface() { state="${state}$( cat "/sys/class/net/${DEVICE}/carrier" 2> /dev/null )" [ "$state" != "$laststate" ] && echo -n "[$state]" laststate="$state" - [ "$state" = "$want" ] && break + 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 @@ -42,5 +47,6 @@ wait_for_iface() { echo -n "... no operstate or carrier, let's hope for the best..." fi echo + return "$ret" } true diff --git a/core/rootfs/rootfs-stage31/data/inc/setup_network_retry b/core/rootfs/rootfs-stage31/data/inc/setup_network_retry index f2a53783..98701e91 100644 --- a/core/rootfs/rootfs-stage31/data/inc/setup_network_retry +++ b/core/rootfs/rootfs-stage31/data/inc/setup_network_retry @@ -6,28 +6,46 @@ 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 "$BRIDGE" down ip link set dev "$IFACE" down - usleep 10000 + usleep 100000 echo "and up again.." ip link set dev "$IFACE" up - ip link set dev "$BRIDGE" up usleep 100000 - wait_for_iface "$IFACE" 20 + wait_for_iface "$IFACE" "$(( 15 + i * 2 ))" + retval=$? + ip link set dev "$BRIDGE" up + if [ "$retval" -eq 0 ] && [ "$i" -gt 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, YMMV!" + sleep 3 + RET=0 + break + fi + echo "...nope..." + fi + wait_for_iface "$BRIDGE" 10 + usleep 100000 - udhcpc $PARAM -O ntpsrv -O domain -O search -t 6 -T 4 -A 5 -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 ] -- cgit v1.2.3-55-g7522