From a5f3e6bb6be8e7c0e9dd5be0b7e2387d7354c96c Mon Sep 17 00:00:00 2001 From: Aaron Goodman Date: Thu, 12 Nov 2020 19:21:04 -0500 Subject: [PATCH 1/5] mwan3: don't call rpcd on 'mwan3 interfaces' Allow `mwan3 interfaces` to get uptime via an internal function and thus remove the dependency on rpcd for `mwan3 interface` calls. Signed-off-by: Aaron Goodman --- net/mwan3/files/lib/mwan3/common.sh | 20 +++++++++---- net/mwan3/files/lib/mwan3/mwan3.sh | 11 ++----- net/mwan3/files/usr/libexec/rpcd/mwan3 | 40 +++++++++++++++----------- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/net/mwan3/files/lib/mwan3/common.sh b/net/mwan3/files/lib/mwan3/common.sh index 5c9b2a805..3cb6f1a45 100644 --- a/net/mwan3/files/lib/mwan3/common.sh +++ b/net/mwan3/files/lib/mwan3/common.sh @@ -1,10 +1,5 @@ #!/bin/sh -get_uptime() { - local uptime=$(cat /proc/uptime) - echo "${uptime%%.*}" -} - IP4="ip -4" IP6="ip -6" SCRIPTNAME="$(basename "$0")" @@ -180,3 +175,18 @@ mwan3_count_one_bits() done echo $count } + +get_uptime() { + local uptime=$(cat /proc/uptime) + echo "${uptime%%.*}" +} + +get_online_time() { + local time_n time_u iface + iface="$1" + time_u="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/ONLINE" 2>/dev/null)" + [ -z "${time_u}" ] || [ "${time_u}" = "0" ] || { + time_n="$(get_uptime)" + echo $((time_n-time_u)) + } +} diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index fcfda5b89..26bdcbcd2 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -1053,15 +1053,8 @@ mwan3_report_iface_status() if [ "$result" = "offline" ]; then : elif [ $error -eq 0 ]; then - json_init - json_add_string section interfaces - json_add_string interface "$1" - json_load "$(ubus call mwan3 status "$(json_dump)")" - json_select "interfaces" - json_select "$1" - json_get_vars online uptime - json_select .. - json_select .. + 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" diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index 0d8693e64..d4e7adb6f 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -69,6 +69,26 @@ report_policies_v6() { done } +get_age() { + local time_p time_u + iface="$1" + time_p="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME")" + [ -z "${time_p}" ] || { + time_n="$(get_uptime)" + echo $((time_n-time_p)) + } +} + +get_offline_time() { + local time_n time_d iface + iface="$1" + time_d="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/OFFLINE")" + [ -z "${time_d}" ] || [ "${time_d}" = "0" ] || { + time_n="$(get_uptime)" + echo $((time_n-time_d)) + } +} + get_mwan3_status() { local iface="${1}" local iface_select="${2}" @@ -85,23 +105,9 @@ get_mwan3_status() { track_status="$(mwan3_get_mwan3track_status "$1")" [ "$track_status" = "active" ] && running="1" - time_p="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME")" - [ -z "${time_p}" ] || { - time_n="$(get_uptime)" - let age=time_n-time_p - } - - time_u="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/ONLINE")" - [ -z "${time_u}" ] || [ "${time_u}" = "0" ] || { - time_n="$(get_uptime)" - let online=time_n-time_u - } - - time_d="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/OFFLINE")" - [ -z "${time_d}" ] || [ "${time_d}" = "0" ] || { - time_n="$(get_uptime)" - let offline=time_n-time_d - } + age=$(get_age "$iface") + online=$(get_online_time "$iface") + offline=$(get_offline_time "$iface") local uptime="0" From f014a7f5420aaf706c046394f51200faad7fbd88 Mon Sep 17 00:00:00 2001 From: Aaron Goodman Date: Fri, 13 Nov 2020 13:08:14 -0500 Subject: [PATCH 2/5] mwan3: don't trigger rpcd install hooks if rpcd not installed Signed-off-by: Aaron Goodman --- net/mwan3/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index ec782a089..ecdd06f96 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -45,7 +45,7 @@ endef define Package/mwan3/postinst #!/bin/sh -if [ -z "$${IPKG_INSTROOT}" ]; then +if [ -z "$${IPKG_INSTROOT}" ] && [ -x /etc/init.d/rpcd ]; then /etc/init.d/rpcd restart fi exit 0 @@ -53,7 +53,7 @@ endef define Package/mwan3/postrm #!/bin/sh -if [ -z "$${IPKG_INSTROOT}" ]; then +if [ -z "$${IPKG_INSTROOT}" ] && [ -x /etc/init.d/rpcd ]; then /etc/init.d/rpcd restart fi exit 0 From 1bfb1a66cd3b5a09ac4abc7da5e3508a772318ac Mon Sep 17 00:00:00 2001 From: Aaron Goodman Date: Sun, 15 Nov 2020 11:35:28 -0500 Subject: [PATCH 3/5] mwan3: support latest iputils ping iputils upstream changed build params with version s20200821 Latest OpenWRT iputils ping now appears to report the openwrt version tag, rather than iputils date tag This commit sends a test ping to localhost to evaluate the capabilities of iputils ping. Signed-off-by: Aaron Goodman --- net/mwan3/files/usr/sbin/mwan3track | 36 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index d4a5f44ab..bd8954c07 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -40,19 +40,35 @@ if_up() { stop_subprocs } +ping_test_host() { + if [ "$FAMILY" = "ipv6" ]; then + echo "::1" + else + echo "127.0.0.1" + fi +} + +get_ping_command() { + if [ -x "/usr/bin/ping" ] && /usr/bin/ping -${FAMILY#ipv} -c1 -q $(ping_test_host) &>/dev/null; then + # -4 option added in iputils c3e68ac6 so need to check if we can use it + # or if we must use ping and ping6 + echo "/usr/bin/ping -${FAMILY#ipv}" + elif [ "$FAMILY" = "ipv6" ] && [ -x "/usr/bin/ping6" ]; then + echo "/usr/bin/ping6" + elif [ "$FAMILY" = "ipv4" ] && [ -x "/usr/bin/ping" ]; then + echo "/usr/bin/ping" + elif [ -x "/bin/ping" ]; then + echo "/bin/ping -${FAMILY#ipv}" + else + return 1 + fi +} + validate_track_method() { case "$1" in ping) - if [ -x "/usr/bin/ping" ] && [ "$(/usr/bin/ping -V | grep -o '[0-9]*$')" -gt 20150519 ]; then - # -4 option added in iputils c3e68ac6 - PING="/usr/bin/ping -${FAMILY#ipv}" - elif [ "$FAMILY" = "ipv6" ] && [ -x "/usr/bin/ping6" ]; then - PING="/usr/bin/ping6" - elif [ "$FAMILY" = "ipv4" ] && [ -x "/usr/bin/ping" ]; then - PING="/usr/bin/ping" - elif [ -x "/bin/ping" ]; then - PING="/bin/ping -${FAMILY#ipv}" - else + PING=$(get_ping_command) + if [ $? -ne 0 ]; then LOG warn "Missing ping. Please enable BUSYBOX_DEFAULT_PING and recompile busybox or install iputils-ping package." return 1 fi From 8cc38f933c21739b04b063af5e2ae1655ce5844c Mon Sep 17 00:00:00 2001 From: Aaron Goodman Date: Fri, 13 Nov 2020 13:13:31 -0500 Subject: [PATCH 4/5] mwan3: add maintainer add @aaronjg as maintener as per conversation with @feckert Signed-off-by: Aaron Goodman --- net/mwan3/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index ecdd06f96..7800f093b 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -10,7 +10,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 PKG_VERSION:=2.10.3 PKG_RELEASE:=2 -PKG_MAINTAINER:=Florian Eckert +PKG_MAINTAINER:=Florian Eckert , \ + Aaron Goodman PKG_LICENSE:=GPL-2.0 PKG_CONFIG_DEPENDS:=CONFIG_IPV6 From 8abd5781b939163fcb56a2f0a2110e6c308d67bb Mon Sep 17 00:00:00 2001 From: Aaron Goodman Date: Mon, 16 Nov 2020 11:21:20 -0500 Subject: [PATCH 5/5] mwan3: version bump to 2.10.3-3 Signed-off-by: Aaron Goodman --- net/mwan3/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 7800f093b..4463d3aa8 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 PKG_VERSION:=2.10.3 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_MAINTAINER:=Florian Eckert , \ Aaron Goodman PKG_LICENSE:=GPL-2.0