From 19bebd3d89b50837fe0bc23c51a729bd2a0c2476 Mon Sep 17 00:00:00 2001 From: Aaron Goodman Date: Wed, 20 May 2020 05:34:16 -0400 Subject: [PATCH] mwan3: force busybox ping openwrt 19.07 uses iputils 20101006-1 This ancient version of iputils has a bug where the -I option is not respected. https://github.com/iputils/iputils/issues/55 https://github.com/iputils/iputils/issues/56 https://bugs.openwrt.org/index.php?do=details&task_id=1486 Thus, we should force using busybox ping at "/bin/ping" until the iputils version gets an upgrade in the next major release Signed-off-by: Aaron Goodman (cherry picked from commit 35a86bdc119dda766801409a08e6d98dcf370c72) --- net/mwan3/files/usr/sbin/mwan3track | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 136b3249c..f42e0ba54 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -6,6 +6,7 @@ LOG="logger -t $(basename "$0")[$$] -p" INTERFACE="" DEVICE="" +PING="/bin/ping" IFDOWN_EVENT=0 @@ -109,7 +110,10 @@ main() { local sleep_time=0 local turn=0 local result + local ping_protocol=4 local ping_result + local ping_result_raw + local ping_status local loss=0 local latency=0 @@ -137,15 +141,19 @@ main() { # so get the IP address of the interface and use that instead if echo $track_ip | grep -q ':'; then ADDR=$(ip -6 addr ls dev "$DEVICE" | sed -ne '/\/128/d' -e 's/ *inet6 \([^ \/]*\).* scope global.*/\1/p') + ping_protocol=6 fi if [ $check_quality -eq 0 ]; then - ping -I ${ADDR:-$DEVICE} -c $count -W $timeout -s $size -t $max_ttl -q $track_ip &> /dev/null + $PING -$ping_protocol -I ${ADDR:-$DEVICE} -c $count -W $timeout -s $size -t $max_ttl -q $track_ip &> /dev/null result=$? else - ping_result="$(ping -I ${ADDR:-$DEVICE} -c $count -W $timeout -s $size -t $max_ttl -q $track_ip | tail -2)" + ping_result_raw="$($PING -$ping_protocol -I ${ADDR:-$DEVICE} -c $count -W $timeout -s $size -t $max_ttl -q $track_ip 2>/dev/null)" + ping_status=$? + ping_result=$(echo "$ping_result_raw" | tail -n2) loss="$(echo "$ping_result" | grep "packet loss" | cut -d "," -f3 | awk '{print $1}' | sed -e 's/%//')" - if [ "$loss" -eq 100 ]; then + if [ "$ping_status" -ne 0 ] || [ "$loss" -eq 100 ]; then latency=999999 + loss=100 else latency="$(echo "$ping_result" | grep -E 'rtt|round-trip' | cut -d "=" -f2 | cut -d "/" -f2 | cut -d "." -f1)" fi