From 5374316c989e17cf9aac2b22034dd15c94682c1e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 3 Sep 2019 11:15:14 +0200 Subject: [rootfs-stage31] Clean up network config, increase delay on retry --- .../rootfs-stage31/data/inc/network.functions | 20 ++++++++++++---- core/rootfs/rootfs-stage31/data/inc/setup_network | 27 +++++++++++----------- .../rootfs-stage31/data/inc/setup_network_retry | 11 ++++----- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/core/rootfs/rootfs-stage31/data/inc/network.functions b/core/rootfs/rootfs-stage31/data/inc/network.functions index 9ec3eafb..94957be2 100644 --- a/core/rootfs/rootfs-stage31/data/inc/network.functions +++ b/core/rootfs/rootfs-stage31/data/inc/network.functions @@ -1,15 +1,24 @@ +#!/bin/ash + wait_for_iface() { local DEVICE=$1 - local TIMEOUT=20 + local TIMEOUT="$(( "$2" * 2 ))" + local state laststate echo -n "Waiting for interface $DEVICE: " # Some systems don't have operstate. Seems to be hardware dependent - [ ! -e "/sys/class/net/${DEVICE}/operstate" ] && usleep 10000 + [ -e "/sys/class/net/${DEVICE}/operstate" ] || sleep 1 if [ -e "/sys/class/net/${DEVICE}/operstate" ]; then while true; do # check linkstate - [ "x$(cat "/sys/class/net/${DEVICE}/operstate")" == "xup" ] && break + state="$(cat "/sys/class/net/${DEVICE}/operstate")" + [ "$state" != "$laststate" ] && echo -n "[$state]" + laststate="$state" + [ "$state" = "up" ] && 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 + if [ "$TIMEOUT" -le 0 ];then + echo -n "TIMEOUT" + break + fi # else echo -n "." usleep 500000 @@ -17,7 +26,8 @@ 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, let's hope for the best..." fi - echo ".$(cat "/sys/class/net/${DEVICE}/operstate" 2>/dev/null)" + echo } 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..f2a53783 100644 --- a/core/rootfs/rootfs-stage31/data/inc/setup_network_retry +++ b/core/rootfs/rootfs-stage31/data/inc/setup_network_retry @@ -1,23 +1,22 @@ #!/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 + ip link set dev "$IFACE" down usleep 10000 echo "and up again.." - ip link set dev $IFACE up - ip link set dev $BRIDGE up + ip link set dev "$IFACE" up + ip link set dev "$BRIDGE" up usleep 100000 - wait_for_iface "$IFACE" + wait_for_iface "$IFACE" 20 - 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 6 -T 4 -A 5 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" if [ $? -eq 0 ]; then echo "Finally fixed IP config. Continue boot." -- cgit v1.2.3-55-g7522