From bab1ec490fea9ebd3712e4c9889ae1276d1e82db Mon Sep 17 00:00:00 2001 From: xanoxes <857063495@qq.com> Date: Wed, 25 Sep 2024 16:05:53 +0800 Subject: [PATCH] retry arping one more time in ifup-eth when sendto failed --- network-scripts/ifup-eth | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/network-scripts/ifup-eth b/network-scripts/ifup-eth index de6af876..f5c6af12 100755 --- a/network-scripts/ifup-eth +++ b/network-scripts/ifup-eth @@ -293,10 +293,18 @@ else if ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${ipaddr[$idx]}/${prefix[$idx]}" ; then if [ "${REALDEVICE}" != "lo" ] && ! is_false "${arpcheck[$idx]}"; then - ARPING=$(/sbin/arping -c 2 -w ${ARPING_WAIT:-3} -D -I ${REALDEVICE} ${ipaddr[$idx]}) - if [ $? = 1 ]; then + while [ "${tries}" -le "${ARPING_TRIES}" ]; do + ARPING=$(/sbin/arping -c 2 -w ${ARPING_WAIT:-3} -D -I ${REALDEVICE} ${ipaddr[$idx]}) + [ $? = 0 ] && break ARPINGMAC=$(echo $ARPING | sed -ne 's/.*\[\(.*\)\].*/\1/p') - net_log $"Error, some other host ($ARPINGMAC) already uses address ${ipaddr[$idx]}." + if [ -n "${ARPINGMAC}" ]; then + net_log $"Error, some other host ($ARPINGMAC) already uses address ${ipaddr[$idx]}." + break + fi + tries=$((tries+1)) + done + if [ "${tries}" -gt "${ARPING_TRIES}" ]; then + net_log $"arping failed after $tries tries" exit 1 fi fi