mwan3: force busybox ping
authorAaron Goodman <redacted>
Wed, 20 May 2020 09:34:16 +0000 (05:34 -0400)
committerAaron Goodman <redacted>
Sat, 23 May 2020 00:01:45 +0000 (20:01 -0400)
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 <redacted>
net/mwan3/files/usr/sbin/mwan3track

index 136b3249c56d1b124fd194985ecc443f354e8c24..f42e0ba544805afc4c2bba6d32073306c1312b8a 100755 (executable)
@@ -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
git clone https://git.99rst.org/PROJECT