diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 22a57824f..ff082cf75 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.6.14 +PKG_VERSION:=2.6.15 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPLv2 diff --git a/net/mwan3/files/etc/config/mwan3 b/net/mwan3/files/etc/config/mwan3 index 2fd16bb29..b7f6c2c11 100644 --- a/net/mwan3/files/etc/config/mwan3 +++ b/net/mwan3/files/etc/config/mwan3 @@ -13,6 +13,10 @@ config interface 'wan' option reliability '2' option count '1' option timeout '2' + option failure_latency '1000' + option recovery_latency '500' + option failure_loss '20' + option recovery_loss '5' option interval '5' option down '3' option up '8' diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index c30b6a1b9..eb5f98ce5 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -66,6 +66,8 @@ get_mwan3_status() { json_add_object json_add_string ip "${track}" json_add_string status "$(cat "${file}")" + json_add_int latency "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LATENCY_${track}")" + json_add_int packetloss "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOSS_${track}")" json_close_object fi done diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 3593d11a4..274a024cc 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -53,7 +53,8 @@ validate_track_method() { main() { local reliability count timeout interval failure_interval local recovery_interval down up size - local keep_failure_interval + local keep_failure_interval check_quality failure_latency + local recovery_latency failure_loss recovery_loss [ -z "$5" ] && echo "Error: should not be started manually" && exit 0 @@ -86,6 +87,11 @@ main() { config_get failure_interval $1 failure_interval $interval config_get_bool keep_failure_interval $1 keep_failure_interval 0 config_get recovery_interval $1 recovery_interval $interval + config_get_bool check_quality $1 check_quality 0 + config_get failure_latency $1 failure_latency 1000 + config_get recovery_latency $1 recovery_latency 500 + config_get failure_loss $1 failure_loss 40 + config_get recovery_loss $1 recovery_loss 10 local score=$(($down+$up)) local track_ips=$(echo $* | cut -d ' ' -f 5-99) @@ -93,6 +99,10 @@ main() { local lost=0 local sleep_time=0 local turn=0 + local result + local ping_result + local loss=0 + local latency=0 if [ "$STATUS" = "unknown" ]; then echo "unknown" > /var/run/mwan3track/$1/STATUS @@ -109,23 +119,63 @@ main() { if [ $host_up_count -lt $reliability ]; then case "$track_method" in ping) - ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip &> /dev/null ;; + if [ $check_quality -eq 0 ]; then + ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip &> /dev/null + result=$? + else + ping_result="$(ping -I $DEVICE -c $count -W $timeout -s $size -q $track_ip | tail -2)" + loss="$(echo "$ping_result" | grep "packet loss" | cut -d "," -f3 | awk '{print $1}' | sed -e 's/%//')" + if [ "$loss" -eq 100 ]; then + latency=999999 + else + latency="$(echo "$ping_result" | grep -E 'rtt|round-trip' | cut -d "=" -f2 | cut -d "/" -f2 | cut -d "." -f1)" + fi + fi + ;; arping) - arping -I $DEVICE -c $count -w $timeout -q $track_ip &> /dev/null ;; + arping -I $DEVICE -c $count -w $timeout -q $track_ip &> /dev/null + result=$? + ;; httping) - httping -y $SRC_IP -c $count -t $timeout -q $track_ip &> /dev/null ;; + httping -y $SRC_IP -c $count -t $timeout -q $track_ip &> /dev/null + result=$? + ;; esac - if [ $? -eq 0 ]; then - let host_up_count++ - echo "up" > /var/run/mwan3track/$1/TRACK_${track_ip} - if [ $score -le $up ]; then - $LOG info "Check ($track_method) success for target \"$track_ip\" on interface $1 ($2)" + if [ $check_quality -eq 0 ]; then + if [ $result -eq 0 ]; then + let host_up_count++ + echo "up" > /var/run/mwan3track/$1/TRACK_${track_ip} + if [ $score -le $up ]; then + $LOG info "Check ($track_method) success for target \"$track_ip\" on interface $1 ($2)" + fi + else + let lost++ + echo "down" > /var/run/mwan3track/$1/TRACK_${track_ip} + if [ $score -gt $up ]; then + $LOG info "Check ($track_method) failed for target \"$track_ip\" on interface $1 ($2)" + fi fi else - let lost++ - echo "down" > /var/run/mwan3track/$1/TRACK_${track_ip} - if [ $score -gt $up ]; then - $LOG info "Check ($track_method) failed for target \"$track_ip\" on interface $1 ($2)" + if [ "$loss" -ge "$failure_loss" -o "$latency" -ge "$failure_latency" ]; then + let lost++ + echo "down" > /var/run/mwan3track/$1/TRACK_${track_ip} + echo "$latency" > /var/run/mwan3track/$1/LATENCY_${track_ip} + echo "$loss" > /var/run/mwan3track/$1/LOSS_${track_ip} + + if [ $score -gt $up ]; then + $LOG info "Check (${track_method}: latency=${latency}ms loss=${loss}%) failed for target \"$track_ip\" on interface $1 ($2)" + fi + elif [ "$loss" -le "$recovery_loss" -a "$latency" -le "$recovery_latency" ]; then + let host_up_count++ + echo "up" > /var/run/mwan3track/$1/TRACK_${track_ip} + echo "$latency" > /var/run/mwan3track/$1/LATENCY_${track_ip} + echo "$loss" > /var/run/mwan3track/$1/LOSS_${track_ip} + + if [ $score -le $up ]; then + $LOG info "Check (${track_method}: latency=${latency}ms loss=${loss}%) success for target \"$track_ip\" on interface $1 ($2)" + fi + else + echo "skipped" > /var/run/mwan3track/$1/TRACK_${track_ip} fi fi else