mwan3: fix rtmon routing table function generation
authorFlorian Eckert <fe@dev.tdt.de>
Thu, 16 Jul 2020 12:02:57 +0000 (14:02 +0200)
committerFlorian Eckert <fe@dev.tdt.de>
Mon, 20 Jul 2020 06:11:20 +0000 (08:11 +0200)
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 <fe@dev.tdt.de>
net/mwan3/files/lib/mwan3/mwan3.sh

index 3ce880fd25702b7d7fd9aa62ac8d86d8974a98f4..652cbfd422e41250edd29574eebbcaeb5b6cba29 100644 (file)
@@ -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))