From bcd13ba95cd5b96d04e490b576faab54404cbf69 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 16 Jul 2020 14:02:57 +0200 Subject: [PATCH] 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))