mwan3: fix linkdown routes not being added
authorAaron Goodman <aaronjg@stanford.edu>
Sat, 12 Dec 2020 13:45:53 +0000 (08:45 -0500)
committerFlorian Eckert <fe@dev.tdt.de>
Wed, 16 Dec 2020 08:32:02 +0000 (09:32 +0100)
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
net/mwan3/files/lib/mwan3/common.sh
net/mwan3/files/lib/mwan3/mwan3.sh
net/mwan3/files/usr/sbin/mwan3rtmon

index 3cb6f1a45b85f78d48df127466e9a2a4b1498ad3..bb55a466cbffa6d3c92a0dbef7a1c16e56f9891d 100644 (file)
@@ -129,6 +129,9 @@ mwan3_init()
                LOG debug "Max interface count is ${MWAN3_INTERFACE_MAX}"
        fi
 
+       # remove "linkdown", expiry and source based routing modifiers from route lines
+       MWAN3_ROUTE_LINE_EXP="s/linkdown //; s/expires [0-9]\+sec//;s/error [0-9]\+//; ${source_routing:+s/default\(.*\) from [^ ]*/default\1/;} p"
+
        # mark mask constants
        bitcnt=$(mwan3_count_one_bits MMX_MASK)
        mmdefault=$(((1<<bitcnt)-1))
index 26bdcbcd2f0338b4aa92baeab2db58e71dc32e2b..6821b850322711d05fadd935e9b396c7cf419b47 100644 (file)
@@ -413,7 +413,7 @@ mwan3_get_routes()
        local source_routing
        config_get_bool source_routing globals source_routing 0
        [ $source_routing -eq 0 ] && unset source_routing
-       $IP route list table main | sed -ne "/^linkdown/T; s/expires \([0-9]\+\)sec//;s/error [0-9]\+//; ${source_routing:+s/default\(.*\) from [^ ]*/default\1/;} p" | uniq
+       $IP route list table main | sed -ne "$MWAN3_ROUTE_LINE_EXP" | uniq
 }
 
 mwan3_create_iface_route()
index 6ece58125675b81a649a31e03fa3a79de8b59034..e460615edc60449a5a82179bb8a4e6da119c2100 100755 (executable)
@@ -69,7 +69,7 @@ mwan3_add_all_routes()
 
 mwan3_rtmon_route_handle()
 {
-       local action route_line family tbl device line route_line_exp tid source_routing
+       local action route_line family tbl device line tid source_routing
 
        route_line=${1##"Deleted "}
        route_family=$2
@@ -79,29 +79,25 @@ mwan3_rtmon_route_handle()
 
        if [ "$route_line" = "$1" ]; then
                action="replace"
-               route_line_exp="s/expires \([0-9]\+\)sec//;s/error [0-9]\+//; ${source_routing:+s/default\(.*\) from [^ ]*/default\1/}"
                $IPS -! add mwan3_connected_${route_family##ip} ${route_line%% *}
        else
                action="del"
-               route_line_exp="s/expires [0-9]\+sec//;s/error [0-9]\+//; ${source_routing:+s/default\(.*\) from [^ ]*/default\1/}"
                mwan3_set_connected_${route_family}
        fi
 
+       if [ -z "${route_line##*linkdown*}" ]; then
+               LOG debug "attempting to add link on down interface - $route_line"
+       fi
+
        if [ "$route_family" = "ipv4" ]; then
                IP="$IP4"
        elif [ "$route_family" = "ipv6" ] && [ $NO_IPV6 -eq 0 ]; then
                IP="$IP6"
-               route_line=$(echo "$route_line" | sed "$route_line_exp")
        else
                LOG warn "route update called with invalid family - $route_family"
                return
        fi
-
-       # don't try to add routes when link has gone down
-       if [ -z "${route_line##linkdown*}" ]; then
-               LOG debug "not adding route due to linkdown - skipping $route_line"
-               return
-       fi
+       route_line=$(echo "$route_line" | sed -ne "$MWAN3_ROUTE_LINE_EXP")
 
        handle_route() {
                local iface=$1