From 4f59c248e03af19bca6246b78a4031928b2fa97a Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 13 Sep 2023 16:14:26 +0200 Subject: [PATCH 1/4] mwan3: remove notracking in mwan3track ubus status The function 'get_mwan3_status' is reading the internal state from the tracker via the status file. Do not use the state 'notracking' status anymore. If the mwan3track is not running always return 'unknown' and not 'notracking'. There is already an other function that evaluates the external state of the tracker. We have now the following states of the tracker: internal (mwan3track): - offline - online - diconnecting - connecting - disabled - unknown external (via pgrep and config): - paused - active - down - not enabled Signed-off-by: Florian Eckert --- net/mwan3/Makefile | 2 +- net/mwan3/files/usr/libexec/rpcd/mwan3 | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index b31f4ce34..324218969 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.11.8 +PKG_VERSION:=2.11.9 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert , \ Aaron Goodman diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index 3fce9b0d4..eccd10196 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -106,14 +106,10 @@ get_mwan3_status() { config_get enabled "$iface" enabled 0 - if [ -d "${MWAN3_STATUS_DIR}" ]; then + if [ -f "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS" ]; then network_get_uptime uptime "$iface" network_is_up "$iface" && up="1" - if [ -f "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS" ]; then - status="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS")" - else - status="notracking" - fi + status="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS")" else uptime=0 up=0 From 28e058e92f603ceabe32f86627fc32aba468e762 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 15 Sep 2023 11:27:01 +0200 Subject: [PATCH 2/4] mwan3: rename tracking state from 'not enabled' to 'disabled' The expression 'disabled' is more meaningful than 'not enabled' and can therefore be better processed in the ubus output, since it is only one word. Signed-off-by: Florian Eckert --- net/mwan3/Makefile | 2 +- net/mwan3/files/lib/mwan3/common.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 324218969..606992b61 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.11.9 +PKG_VERSION:=2.11.10 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert , \ Aaron Goodman diff --git a/net/mwan3/files/lib/mwan3/common.sh b/net/mwan3/files/lib/mwan3/common.sh index 29ace6050..ecd45026e 100644 --- a/net/mwan3/files/lib/mwan3/common.sh +++ b/net/mwan3/files/lib/mwan3/common.sh @@ -107,7 +107,7 @@ mwan3_get_mwan3track_status() tracking="down" fi else - tracking="not enabled" + tracking="disabled" fi echo "$tracking" } From 002439594c6c207c34337ad3c8868d4ec9a46fa4 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 15 Sep 2023 11:44:41 +0200 Subject: [PATCH 3/4] mwan3: also show tracker state via ubus The tracker state is not shown via ubus. Only if the tracker was in active state, then the boolean running was set or not. By adding the tracking state to the ubus information we could also evaluate the state of the tracker. To remain compatible, the runnig flag of the tracker is not removed, which in fact displays the same information, but only if the tracker is in state 'active' or not. Signed-off-by: Florian Eckert --- net/mwan3/Makefile | 2 +- net/mwan3/files/usr/libexec/rpcd/mwan3 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 606992b61..d6d2075aa 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.11.10 +PKG_VERSION:=2.11.11 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert , \ Aaron Goodman diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index eccd10196..4bd2b631f 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -127,6 +127,7 @@ get_mwan3_status() { json_add_string "status" "${status}" json_add_boolean "enabled" "${enabled}" json_add_boolean "running" "${running}" + json_add_string "tracking" "${track_status}" json_add_boolean "up" "${up}" json_add_array "track_ip" for file in $MWAN3TRACK_STATUS_DIR/${iface}/TRACK_*; do From f021b9416b794e5ffacb9f190bbb56b5f5b11bf2 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 15 Sep 2023 12:21:57 +0200 Subject: [PATCH 4/4] mwan3: refactoring mwan3_report_iface_status output The tracking and interface status was mixed up in the report. To fix this, the interface status and the tracking status are now used directly. The online, uptime and error information are appended to the status line if needed. If certain routing tables and routing rules are missing, the error number is also given. Signed-off-by: Florian Eckert --- net/mwan3/Makefile | 2 +- net/mwan3/files/lib/mwan3/mwan3.sh | 46 +++++++++++++++--------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index d6d2075aa..9bfc24dbd 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.11.11 +PKG_VERSION:=2.11.12 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert , \ Aaron Goodman diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index a3e7c0098..c69f381ea 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -1082,7 +1082,8 @@ mwan3_get_iface_hotplug_state() { mwan3_report_iface_status() { - local device result tracking IP IPT error + local device result tracking IP IPT + local status online uptime result mwan3_get_iface_id id "$1" network_get_device device "$1" @@ -1099,40 +1100,39 @@ mwan3_report_iface_status() IPT="$IPT6" fi - if [ -z "$id" ] || [ -z "$device" ]; then - result="offline" + if [ -f "$MWAN3TRACK_STATUS_DIR/${1}/STATUS" ]; then + status="$(cat "$MWAN3TRACK_STATUS_DIR/${1}/STATUS")" else - error=0 - [ -n "$($IP rule | awk '$1 == "'$((id+1000)):'"')" ] || - error=$((error+1)) - [ -n "$($IP rule | awk '$1 == "'$((id+2000)):'"')" ] || - error=$((error+2)) - [ -n "$($IP rule | awk '$1 == "'$((id+3000)):'"')" ] || - error=$((error+4)) - [ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" ] || - error=$((error+8)) - [ -n "$($IP route list table $id default dev $device 2> /dev/null)" ] || - error=$((error+16)) + status="unknown" fi - if [ "$result" = "offline" ]; then - : - elif [ $error -eq 0 ]; then + if [ "$status" = "online" ]; then online=$(get_online_time "$1") network_get_uptime uptime "$1" online="$(printf '%02dh:%02dm:%02ds\n' $((online/3600)) $((online%3600/60)) $((online%60)))" uptime="$(printf '%02dh:%02dm:%02ds\n' $((uptime/3600)) $((uptime%3600/60)) $((uptime%60)))" result="$(mwan3_get_iface_hotplug_state $1) $online, uptime $uptime" - elif [ $error -gt 0 ] && [ $error -ne 31 ]; then - result="error (${error})" - elif [ "$enabled" = "1" ]; then - result="offline" else - result="disabled" + result=0 + [ -n "$($IP rule | awk '$1 == "'$((id+1000)):'"')" ] || + result=$((result+1)) + [ -n "$($IP rule | awk '$1 == "'$((id+2000)):'"')" ] || + result=$((result+2)) + [ -n "$($IP rule | awk '$1 == "'$((id+3000)):'"')" ] || + result=$((result+4)) + [ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" ] || + result=$((result+8)) + [ -n "$($IP route list table $id default dev $device 2> /dev/null)" ] || + result=$((result+16)) + [ "$result" = "0" ] && result="" fi tracking="$(mwan3_get_mwan3track_status $1)" - echo " interface $1 is $result and tracking is $tracking" + if [ -n "$result" ]; then + echo " interface $1 is $status and tracking is $tracking ($result)" + else + echo " interface $1 is $status and tracking is $tracking" + fi } mwan3_report_policies()