From 8c0ed00c397febfdcbb40e901f77a7a15bfc1d9e Mon Sep 17 00:00:00 2001 From: Kyson Lok Date: Wed, 6 Jun 2018 19:07:20 +0800 Subject: [PATCH 1/5] net/mwan3: fixup parse json_load an null message If a interface is down, call ubus will return an null message which is used to json_load, it causes json_get_vars gets value from last load and l3_device various is nonzero. Signed-off-by: Kyson Lok --- net/mwan3/files/usr/sbin/mwan3 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 index 406804b30..4ad3bc391 100755 --- a/net/mwan3/files/usr/sbin/mwan3 +++ b/net/mwan3/files/usr/sbin/mwan3 @@ -43,7 +43,7 @@ ifdown() ifup() { - local device enabled up l3_device + local device enabled up l3_device status config_load mwan3 config_get_bool enabled globals 'enabled' 0 @@ -67,13 +67,18 @@ ifup() exit 0 } - json_load $(ubus -S call network.interface.$1 status) - json_get_vars up l3_device + status=$(ubus -S call network.interface.$1 status) + [ -n "$status" ] && { + json_load $status + json_get_vars up l3_device + } + config_get enabled "$1" enabled 0 - if [ "$up" -eq 1 ] \ + + if [ "$up" = "1" ] \ && [ -n "$l3_device" ] \ - && [ "$enabled" -eq 1 ]; then + && [ "$enabled" = "1" ]; then ACTION=ifup INTERFACE=$1 DEVICE=$l3_device /sbin/hotplug-call iface fi } From 3a5c3e03e2b4eb08ce0a0bc2d1b5d7790ebc1705 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 24 Sep 2018 14:26:53 +0200 Subject: [PATCH 2/5] net/mwan3: also add the metric to the default interface routing table This is now the same route as in the main table. Signed-off-by: Florian Eckert --- net/mwan3/files/lib/mwan3/mwan3.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 2b92a1253..d0a47a523 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -346,7 +346,7 @@ mwan3_delete_iface_iptables() mwan3_create_iface_route() { - local id route_args + local id route_args metric config_get family $1 family ipv4 mwan3_get_iface_id id $1 @@ -366,6 +366,11 @@ mwan3_create_iface_route() route_args="" fi + network_get_metric metric $1 + if [ -n "$metric" -a "$metric" != "0" ]; then + route_args="$route_args metric $metric" + fi + $IP4 route flush table $id $IP4 route add table $id default $route_args dev $2 mwan3_rtmon_ipv4 @@ -384,6 +389,11 @@ mwan3_create_iface_route() route_args="" fi + network_get_metric metric $1 + if [ -n "$metric" -a "$metric" != "0" ]; then + route_args="$route_args metric $metric" + fi + $IP6 route flush table $id $IP6 route add table $id default $route_args dev $2 mwan3_rtmon_ipv6 From 12360037332176f9a286ec754d340a9721479abf Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 4 Oct 2018 09:36:50 +0200 Subject: [PATCH 3/5] net/mwan3: add uptime ubus information Get uptime information for the tracked mwan3 wan interfaces. The information shows how long this interface is in connected state. Signed-off-by: Florian Eckert --- net/mwan3/files/usr/libexec/rpcd/mwan3 | 10 +++++++++- net/mwan3/files/usr/sbin/mwan3track | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index eb5f98ce5..a4b33efd1 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -36,7 +36,8 @@ get_mwan3_status() { local iface_select="${2}" local running="0" local age=0 - local pid device time_p time_n + local uptime=0 + local pid device time_p time_n time_u network_get_device device $1 @@ -52,8 +53,15 @@ get_mwan3_status() { let age=time_n-time_p } + time_u="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/UPTIME")" + [ -z "${time_u}" ] || [ "${time_u}" = "0" ] || { + time_n="$(get_uptime)" + let uptime=time_n-time_u + } + json_add_object "${iface}" json_add_int age "$age" + json_add_int uptime "${uptime}" json_add_int "score" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/SCORE")" json_add_int "lost" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOST")" json_add_int "turn" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TURN")" diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index c2ebb3e9f..725e1086d 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -108,9 +108,11 @@ main() { if [ "$STATUS" = "unknown" ]; then echo "unknown" > /var/run/mwan3track/$1/STATUS + echo "0" > /var/run/mwan3track/$1/UPTIME score=0 else echo "online" > /var/run/mwan3track/$1/STATUS + echo "$(get_uptime)" > /var/run/mwan3track/$1/UPTIME env -i ACTION="connected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface fi while true; do @@ -199,6 +201,7 @@ main() { if [ $score -eq $up ]; then echo "offline" > /var/run/mwan3track/$1/STATUS + echo "0" > /var/run/mwan3track/$1/UPTIME $LOG notice "Interface $1 ($2) is offline" env -i ACTION=ifdown INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface env -i ACTION="disconnected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface @@ -240,6 +243,7 @@ main() { if [ "${IFDOWN_EVENT}" -eq 1 ]; then echo "offline" > /var/run/mwan3track/$1/STATUS + echo "0" > /var/run/mwan3track/$1/UPTIME $LOG notice "Interface $1 ($2) is offline" env -i ACTION="disconnected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface score=0 From 1ee9fb4aff3ee78ab015a32de0a3ab1e594210bf Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Tue, 9 Oct 2018 08:32:03 +0200 Subject: [PATCH 4/5] net/mwan3: add downtime ubus information Get downtime information for the tracked mwan3 wan interfaces. The information shows how long this interface is in disconnected state. Signed-off-by: Florian Eckert --- net/mwan3/files/usr/libexec/rpcd/mwan3 | 10 +++++++++- net/mwan3/files/usr/sbin/mwan3track | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index a4b33efd1..a9b31f222 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -37,7 +37,8 @@ get_mwan3_status() { local running="0" local age=0 local uptime=0 - local pid device time_p time_n time_u + local downtime=0 + local pid device time_p time_n time_u time_d network_get_device device $1 @@ -59,9 +60,16 @@ get_mwan3_status() { let uptime=time_n-time_u } + time_d="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/DOWNTIME")" + [ -z "${time_d}" ] || [ "${time_d}" = "0" ] || { + time_n="$(get_uptime)" + let downtime=time_n-time_d + } + json_add_object "${iface}" json_add_int age "$age" json_add_int uptime "${uptime}" + json_add_int downtime "${downtime}" json_add_int "score" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/SCORE")" json_add_int "lost" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOST")" json_add_int "turn" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TURN")" diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 725e1086d..420878472 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -109,9 +109,11 @@ main() { if [ "$STATUS" = "unknown" ]; then echo "unknown" > /var/run/mwan3track/$1/STATUS echo "0" > /var/run/mwan3track/$1/UPTIME + echo "$(get_uptime)" > /var/run/mwan3track/$1/DOWNTIME score=0 else echo "online" > /var/run/mwan3track/$1/STATUS + echo "0" > /var/run/mwan3track/$1/DOWNTIME echo "$(get_uptime)" > /var/run/mwan3track/$1/UPTIME env -i ACTION="connected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface fi @@ -202,6 +204,7 @@ main() { if [ $score -eq $up ]; then echo "offline" > /var/run/mwan3track/$1/STATUS echo "0" > /var/run/mwan3track/$1/UPTIME + echo "$(get_uptime)" > /var/run/mwan3track/$1/DOWNTIME $LOG notice "Interface $1 ($2) is offline" env -i ACTION=ifdown INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface env -i ACTION="disconnected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface @@ -243,6 +246,7 @@ main() { if [ "${IFDOWN_EVENT}" -eq 1 ]; then echo "offline" > /var/run/mwan3track/$1/STATUS + echo "$(get_uptime)" > /var/run/mwan3track/$1/DOWNTIME echo "0" > /var/run/mwan3track/$1/UPTIME $LOG notice "Interface $1 ($2) is offline" env -i ACTION="disconnected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface From eeef66cec249ce64c7db6e4c96bfa5d75e953ec5 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 12 Oct 2018 08:12:14 +0200 Subject: [PATCH 5/5] net/mwan3: update version to 2.7.4 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 6633765d8..d9a085a37 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.7.3 +PKG_VERSION:=2.7.4 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPLv2