From bcd13ba95cd5b96d04e490b576faab54404cbf69 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 16 Jul 2020 14:02:57 +0200 Subject: [PATCH 1/5] mwan3: fix rtmon routing table function generation If the uci option family is not set in the interface section, then there is no default value set as in the `config_load / config_get` API. The problem here is that if the family is not set, the default value ipv4 is normaly assumed. But the comparison fails here because the value is empty and therefore the dedicated routing table for this interface is not compared with the other routes from the main table and so not updated. To fix this set the default value for this config option which is`false` for enabled and `ipv4` for family. Signed-off-by: Florian Eckert --- net/mwan3/files/lib/mwan3/mwan3.sh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 3ce880fd2..652cbfd42 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -43,13 +43,20 @@ mwan3_rtmon_ipv4() local ret=1 local tbl="" - local tid + local tid family enabled mkdir -p /tmp/mwan3rtmon ($IP4 route list table main | grep -v "^default\|linkdown" | sort -n; echo empty fixup) >/tmp/mwan3rtmon/ipv4.main while uci get mwan3.@interface[$idx] >/dev/null 2>&1 ; do tid=$((idx+1)) - [ "$(uci get mwan3.@interface[$idx].family)" = "ipv4" ] && { + + family="$(uci -q get mwan3.@interface[$idx].family)" + [ -z "$family" ] && family="ipv4" + + enabled="$(uci -q get mwan3.@interface[$idx].enabled)" + [ -z "$enabled" ] && enabled="0" + + [ "$family" = "ipv4" ] && { tbl=$($IP4 route list table $tid 2>/dev/null) if echo "$tbl" | grep -q ^default; then (echo "$tbl" | grep -v "^default\|linkdown" | sort -n; echo empty fixup) >/tmp/mwan3rtmon/ipv4.$tid @@ -61,7 +68,7 @@ mwan3_rtmon_ipv4() done fi } - if [ "$(uci get mwan3.@interface[$idx].enabled)" = "1" ]; then + if [ "$enabled" = "1" ]; then ret=0 fi idx=$((idx+1)) @@ -78,13 +85,21 @@ mwan3_rtmon_ipv6() local ret=1 local tbl="" - local tid + local tid family enabled mkdir -p /tmp/mwan3rtmon ($IP6 route list table main | grep -v "^default\|^::/0\|^fe80::/64\|^unreachable" | sort -n; echo empty fixup) >/tmp/mwan3rtmon/ipv6.main while uci get mwan3.@interface[$idx] >/dev/null 2>&1 ; do tid=$((idx+1)) - [ "$(uci get mwan3.@interface[$idx].family)" = "ipv6" ] && { + + family="$(uci -q get mwan3.@interface[$idx].family)" + # Set default family to ipv4 that is no mistake + [ -z "$family" ] && family="ipv4" + + enabled="$(uci -q get mwan3.@interface[$idx].enabled)" + [ -z "$enabled" ] && enabled="0" + + [ "$family" = "ipv6" ] && { tbl=$($IP6 route list table $tid 2>/dev/null) if echo "$tbl" | grep -q "^default\|^::/0"; then (echo "$tbl" | grep -v "^default\|^::/0\|^unreachable" | sort -n; echo empty fixup) >/tmp/mwan3rtmon/ipv6.$tid @@ -96,7 +111,7 @@ mwan3_rtmon_ipv6() done fi } - if [ "$(uci get mwan3.@interface[$idx].enabled)" = "1" ]; then + if [ "$enabled" = "1" ]; then ret=0 fi idx=$((idx+1)) From cde2a77ed3b3b0df9e693e121dccdc97ef163156 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 17 Jul 2020 10:35:11 +0200 Subject: [PATCH 2/5] mwan3: also cleanup lock on mwan3 stop Signed-off-by: Florian Eckert --- net/mwan3/files/lib/mwan3/mwan3.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 652cbfd42..105aafa0c 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -202,6 +202,13 @@ mwan3_unlock() { } mwan3_lock_clean() { + for pid in $(pgrep -f "lock /var/run/mwan3.lock"); do + kill -TERM "$pid" > /dev/null 2>&1 + done + sleep 1 + for pid in $(pgrep -f "lock /var/run/mwan3.lock"); do + kill -KILL "$pid" > /dev/null 2>&1 + done rm -rf /var/run/mwan3.lock } From 058a2b6f3057d849cbe4f2c4fda258d32d6da2fd Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 17 Jul 2020 10:34:32 +0200 Subject: [PATCH 3/5] mwan3: add workaround for procd change Signed-off-by: Florian Eckert --- net/mwan3/files/etc/init.d/mwan3 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/net/mwan3/files/etc/init.d/mwan3 b/net/mwan3/files/etc/init.d/mwan3 index af750e55e..e0c65889a 100755 --- a/net/mwan3/files/etc/init.d/mwan3 +++ b/net/mwan3/files/etc/init.d/mwan3 @@ -10,17 +10,22 @@ boot() { rc_procd start_service } +# FIXME +# fd 1000 is an inherited lock file descriptor for preventing concurrent +# init script executions. Close it here to prevent the mwan3 daemon from +# inheriting it further to avoid holding the lock indefinitely. + reload_service() { - /usr/sbin/mwan3 restart + /usr/sbin/mwan3 restart 1000>&- } start_service() { [ -n "${mwan3_boot}" ] && return 0 - /usr/sbin/mwan3 start + /usr/sbin/mwan3 start 1000>&- } stop_service() { - /usr/sbin/mwan3 stop + /usr/sbin/mwan3 stop 1000>&- } service_triggers() { From b0acbf057e05bbfb165fd83a181c0d1607da5558 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 28 Jun 2019 13:55:29 +0200 Subject: [PATCH 4/5] mwan3: add online and uptime to detail output Add also online time value and uptime time value from netifd to the detail output view. Signed-off-by: Florian Eckert --- net/mwan3/files/lib/mwan3/mwan3.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 105aafa0c..2ec760f9a 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -1,5 +1,7 @@ #!/bin/sh +. /usr/share/libubox/jshn.sh + IP4="ip -4" IP6="ip -6" IPS="ipset" @@ -1066,7 +1068,18 @@ mwan3_report_iface_status() [ -n "$($IP rule | awk '$1 == "'$(($id+2000)):'"')" ] && \ [ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" ] && \ [ -n "$($IP route list table $id default dev $device 2> /dev/null)" ]; then - result="$(mwan3_get_iface_hotplug_state $1)" + 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="$(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 [ -n "$($IP rule | awk '$1 == "'$(($id+1000)):'"')" ] || \ [ -n "$($IP rule | awk '$1 == "'$(($id+2000)):'"')" ] || \ [ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" ] || \ From f601e6cfa4a93954336b740dffdad2464a2b2b45 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 20 Jul 2020 08:15:50 +0200 Subject: [PATCH 5/5] mwan3: update version to 2.8.11 Signed-off-by: Florian Eckert --- net/mwan3/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 6849617f2..ce4bfcec2 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.8.10 +PKG_VERSION:=2.8.11 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPL-2.0