mwan3: fix mwan3 route handling
authorAaron Goodman <redacted>
Sat, 24 Oct 2020 16:53:15 +0000 (12:53 -0400)
committerAaron Goodman <redacted>
Wed, 28 Oct 2020 01:40:06 +0000 (21:40 -0400)
- support trailing route space from iproute2
- add routes even when iface is down
- fix source_routing argument check
- add quotes in logging to better detect issues with trailing spaces

Signed-off-by: Aaron Goodman <redacted>
net/mwan3/files/usr/sbin/mwan3rtmon

index ee470837e40f54bb86fc0e1dbdb4068a3b01fc77..569b4d1729d5032c2b9fa6c5de8a4a66166bf76c 100755 (executable)
@@ -74,7 +74,7 @@ mwan3_rtmon_route_handle()
        route_line=${1##"Deleted "}
        route_family=$2
 
-       config_get_boolean source_routing globals source_routing 0
+       config_get_bool source_routing globals source_routing 0
        [ $source_routing -eq 0 ] && unset source_routing
 
        if [ "$route_line" = "$1" ]; then
@@ -107,22 +107,22 @@ mwan3_rtmon_route_handle()
                local iface=$1
                tbl=$($IP route list table $tid 2>/dev/null)$'\n'
 
-               if [ "$(cat /var/run/mwan3track/$iface/STATUS)" != "online" ]; then
-                       LOG debug "interface $iface is offline - skipping $route_line";
+               if [ -n "$iface" ] && [ "$(mwan3_get_mwan3track_status $iface)" != "active" ]; then
+                       LOG debug "interface $iface is disabled - skipping '$route_line'";
                        return
                fi
 
                # check that action needs to be performed. May not need to take action if we
                # got a delete event, but table was already flushed
                if [ $action = "del" ] && [ -n "${tbl##*$route_line$'\n'*}" ]; then
-                       LOG debug "skipping already deleted route table $tid - skipping $route_line"
+                       LOG debug "skipping already deleted route table $tid - skipping '$route_line'"
                        return
                fi
 
                network_get_device device "$iface"
-               LOG debug "adjusting route $device: $IP route $action table $tid $route_line"
+               LOG debug "adjusting route $device: '$IP route $action table $tid $route_line'"
                $IP route "$action" table $tid $route_line ||
-                       LOG warn "failed: $IP route $action table $tid $route_line"
+                       LOG warn "failed: '$IP route $action table $tid $route_line'"
        }
        handle_route_cb(){
                local iface=$1
@@ -163,9 +163,9 @@ main()
        sh -c "echo \$\$; exec $IP monitor route" | {
                read -r monitor_pid
                trap_with_arg func_trap "$monitor_pid" SIGINT SIGTERM SIGKILL
-               while read -r line; do
+               while IFS='' read -r line; do
                        [ -z "${line##*table*}" ] && continue
-                       LOG debug "handling route update $family $line"
+                       LOG debug "handling route update $family '$line'"
                        mwan3_lock "service" "mwan3rtmon"
                        mwan3_rtmon_route_handle "$line" "$family"
                        mwan3_unlock "service" "mwan3rtmon"
git clone https://git.99rst.org/PROJECT