diff options
author | Aaron Goodman <aaronjg@stanford.edu> | 2020-08-31 19:15:09 -0400 |
---|---|---|
committer | Aaron Goodman <aaronjg@stanford.edu> | 2020-10-16 09:54:48 -0400 |
commit | b7e26dd431a35a28b64c82ad3bde1fd996af6d39 (patch) | |
tree | 642eba1973683edde939a893732d74986a19db14 /net/mwan3 | |
parent | 386f18a7e59d47fbc4ae053a0957fafc7ce7ded6 (diff) |
mwan3: fixup some extra spaces and shellcheck warnings
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
Diffstat (limited to 'net/mwan3')
-rw-r--r-- | net/mwan3/files/etc/hotplug.d/iface/15-mwan3 | 6 | ||||
-rw-r--r-- | net/mwan3/files/lib/mwan3/common.sh | 2 | ||||
-rw-r--r-- | net/mwan3/files/lib/mwan3/mwan3.sh | 112 | ||||
-rwxr-xr-x | net/mwan3/files/usr/sbin/mwan3 | 21 | ||||
-rwxr-xr-x | net/mwan3/files/usr/sbin/mwan3rtmon | 9 | ||||
-rwxr-xr-x | net/mwan3/files/usr/sbin/mwan3track | 34 |
6 files changed, 92 insertions, 92 deletions
diff --git a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 index 6a7e95ac4..803d3ea27 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 @@ -7,9 +7,9 @@ . /lib/mwan3/common.sh SCRIPTNAME="mwan3-hotplug" -[ "$ACTION" = "ifup" ] || [ "$ACTION" = "ifdown" ] || [ "$ACTION" = "connected" ] || [ "$ACTION" = "disconnected" ] || exit 1 +[ "$ACTION" = "ifup" ] || [ "$ACTION" = "ifdown" ] || [ "$ACTION" = "connected" ] || [ "$ACTION" = "disconnected" ] || exit 1 [ -n "$INTERFACE" ] || exit 2 -if ( [ "$ACTION" = "ifup" ] || [ "$ACTION" = "connected" ] ) && [ -z "$DEVICE" ]; then +if { [ "$ACTION" = "ifup" ] || [ "$ACTION" = "connected" ] ; } && [ -z "$DEVICE" ]; then LOG notice "$ACTION called on $INTERFACE with no device set" exit 3 fi @@ -62,7 +62,7 @@ fi binary_status=$status [ "$binary_status" = "online" ] || binary_status=offline -LOG notice "Execute "$ACTION" event on interface $INTERFACE (${DEVICE:-unknown})" +LOG notice "Execute $ACTION event on interface $INTERFACE (${DEVICE:-unknown})" case "$ACTION" in ifup|connected) diff --git a/net/mwan3/files/lib/mwan3/common.sh b/net/mwan3/files/lib/mwan3/common.sh index bb26327d5..62a736b37 100644 --- a/net/mwan3/files/lib/mwan3/common.sh +++ b/net/mwan3/files/lib/mwan3/common.sh @@ -13,5 +13,5 @@ LOG() # when this release is out of beta, the comment in the line below # should be removed [ "$facility" = "debug" ] && return - logger -t "$SCRIPTNAME[$$]" -p $facility "$*" + logger -t "${SCRIPTNAME}[$$]" -p $facility "$*" } diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 14af3ded2..e9b3feda8 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -50,7 +50,9 @@ $*"; mwan3_update_dev_to_table() { local _tid + # shellcheck disable=SC2034 mwan3_dev_tbl_ipv4=" " + # shellcheck disable=SC2034 mwan3_dev_tbl_ipv6=" " update_table() @@ -99,7 +101,7 @@ mwan3_route_line_dev() { # must have mwan3 config already loaded # arg 1 is route device - local _tid route_line route_device route_family entry curr_table + local _tid route_line route_device route_family entry curr_table route_line=$2 route_family=$3 route_device=$(echo "$route_line" | sed -ne "s/.*dev \([^ ]*\).*/\1/p") @@ -170,7 +172,7 @@ mwan3_init() bitcnt=$(mwan3_count_one_bits MMX_MASK) mmdefault=$(((1<<bitcnt)-1)) - MWAN3_INTERFACE_MAX=$(($mmdefault-3)) + MWAN3_INTERFACE_MAX=$((mmdefault-3)) uci_toggle_state mwan3 globals iface_max "$MWAN3_INTERFACE_MAX" LOG debug "Max interface count is ${MWAN3_INTERFACE_MAX}" fi @@ -178,8 +180,8 @@ mwan3_init() # mark mask constants bitcnt=$(mwan3_count_one_bits MMX_MASK) mmdefault=$(((1<<bitcnt)-1)) - MM_BLACKHOLE=$(($mmdefault-2)) - MM_UNREACHABLE=$(($mmdefault-1)) + MM_BLACKHOLE=$((mmdefault-2)) + MM_UNREACHABLE=$((mmdefault-1)) # MMX_DEFAULT should equal MMX_MASK MMX_DEFAULT=$(mwan3_id2mask mmdefault MMX_MASK) @@ -220,14 +222,13 @@ mwan3_get_iface_id() _tmp="${mwan3_iface_tbl##* ${2}=}" _tmp=${_tmp%% *} export "$1=$_tmp" - new_val=$_tmp } mwan3_set_custom_ipset_v4() { local custom_network_v4 - for custom_network_v4 in $($IP4 route list table "$1" | awk '{print $1}' | egrep '[0-9]{1,3}(\.[0-9]{1,3}){3}'); do + for custom_network_v4 in $($IP4 route list table "$1" | awk '{print $1}' | grep -E '[0-9]{1,3}(\.[0-9]{1,3}){3}'); do LOG notice "Adding network $custom_network_v4 from table $1 to mwan3_custom_v4 ipset" mwan3_push_update -! add mwan3_custom_v4 "$custom_network_v4" done @@ -237,7 +238,7 @@ mwan3_set_custom_ipset_v6() { local custom_network_v6 - for custom_network_v6 in $($IP6 route list table "$1" | awk '{print $1}' | egrep "$IPv6_REGEX"); do + for custom_network_v6 in $($IP6 route list table "$1" | awk '{print $1}' | grep -E "$IPv6_REGEX"); do LOG notice "Adding network $custom_network_v6 from table $1 to mwan3_custom_v6 ipset" mwan3_push_update -! add mwan3_custom_v6 "$custom_network_v6" done @@ -274,7 +275,7 @@ mwan3_set_connected_ipv4() $IP4 route | awk '{print $1}' $IP4 route list table 0 | awk '{print $2}' } - for connected_network_v4 in $(route_lists | egrep "$ipv4regex"); do + for connected_network_v4 in $(route_lists | grep -E "$ipv4regex"); do if [ -z "${connected_network_v4##*/*}" ]; then cidr_list="$cidr_list $connected_network_v4" else @@ -307,7 +308,7 @@ mwan3_set_connected_iptables() mwan3_push_update -! create mwan3_connected_v6 hash:net family inet6 mwan3_push_update flush mwan3_connected_v6 - for connected_network_v6 in $($IP6 route | awk '{print $1}' | egrep "$IPv6_REGEX"); do + for connected_network_v6 in $($IP6 route | awk '{print $1}' | grep -E "$IPv6_REGEX"); do mwan3_push_update -! add mwan3_connected_v6 "$connected_network_v6" done @@ -336,12 +337,12 @@ mwan3_set_general_rules() for IP in "$IP4" "$IP6"; do [ "$IP" = "$IP6" ] && [ $NO_IPV6 -ne 0 ] && continue - RULE_NO=$(($MM_BLACKHOLE+2000)) + RULE_NO=$((MM_BLACKHOLE+2000)) if [ -z "$($IP rule list | awk -v var="$RULE_NO:" '$1 == var')" ]; then $IP rule add pref $RULE_NO fwmark $MMX_BLACKHOLE/$MMX_MASK blackhole fi - RULE_NO=$(($MM_UNREACHABLE+2000)) + RULE_NO=$((MM_UNREACHABLE+2000)) if [ -z "$($IP rule list | awk -v var="$RULE_NO:" '$1 == var')" ]; then $IP rule add pref $RULE_NO fwmark $MMX_UNREACHABLE/$MMX_MASK unreachable fi @@ -466,7 +467,7 @@ mwan3_create_iface_iptables() mwan3_push_update -N mwan3_ifaces_in fi - if [ -n "${current##*-N mwan3_iface_in_$1*}" ]; then + if [ -n "${current##*-N mwan3_iface_in_$1*}" ]; then mwan3_push_update -N "mwan3_iface_in_$1" else mwan3_push_update -F "mwan3_iface_in_$1" @@ -475,22 +476,22 @@ mwan3_create_iface_iptables() mwan3_push_update -A "mwan3_iface_in_$1" \ -i "$2" \ -m set --match-set $connected_name src \ - -m mark --mark 0x0/$MMX_MASK \ + -m mark --mark "0x0/$MMX_MASK" \ -m comment --comment "default" \ - -j MARK --set-xmark $MMX_DEFAULT/$MMX_MASK + -j MARK --set-xmark "$MMX_DEFAULT/$MMX_MASK" mwan3_push_update -A "mwan3_iface_in_$1" \ -i "$2" \ - -m mark --mark 0x0/$MMX_MASK \ + -m mark --mark "0x0/$MMX_MASK" \ -m comment --comment "$1" \ - -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK + -j MARK --set-xmark "$(mwan3_id2mask id MMX_MASK)/$MMX_MASK" - if [ -n "${current##*-A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_${1}*}" ]; then + if [ -n "${current##*-A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_${1}*}" ]; then mwan3_push_update -A mwan3_ifaces_in \ -m mark --mark 0x0/$MMX_MASK \ -j "mwan3_iface_in_$1" - LOG debug "create_iface_iptables: mwan3_iface_in_$1 not in iptables, adding" + LOG debug "create_iface_iptables: mwan3_iface_in_$1 not in iptables, adding" else - LOG debug "create_iface_iptables: mwan3_iface_in_$1 already in iptables, skip" + LOG debug "create_iface_iptables: mwan3_iface_in_$1 already in iptables, skip" fi mwan3_push_update COMMIT @@ -572,7 +573,7 @@ mwan3_add_non_default_iface_route() fi mwan3_update_dev_to_table - $IP route list table main | grep -v "^default\|linkdown\|^::/0\|^fe80::/64\|^unreachable" | while read route_line; do + $IP route list table main | grep -v "^default\|linkdown\|^::/0\|^fe80::/64\|^unreachable" | while read -r route_line; do mwan3_route_line_dev "tid" "$route_line" "$family" if [ -z "$tid" ] || [ "$tid" = "$id" ]; then $IP route add table $id $route_line || @@ -615,7 +616,7 @@ mwan3_add_all_nondefault_routes() tid=0 active_tbls=" " config_foreach add_active_tbls interface - $IP route list table main | grep -v "^default\|linkdown\|^::/0\|^fe80::/64\|^unreachable" | while read route_line; do + $IP route list table main | grep -v "^default\|linkdown\|^::/0\|^fe80::/64\|^unreachable" | while read -r route_line; do mwan3_route_line_dev "tid" "$route_line" "$ipv" if [ -n "$tid" ]; then $IP route add table $tid $route_line @@ -660,21 +661,21 @@ mwan3_create_iface_rules() return fi - while [ -n "$($IP rule list | awk '$1 == "'$(($id+1000)):'"')" ]; do - $IP rule del pref $(($id+1000)) + while [ -n "$($IP rule list | awk '$1 == "'$((id+1000)):'"')" ]; do + $IP rule del pref $((id+1000)) done - while [ -n "$($IP rule list | awk '$1 == "'$(($id+2000)):'"')" ]; do - $IP rule del pref $(($id+2000)) + while [ -n "$($IP rule list | awk '$1 == "'$((id+2000)):'"')" ]; do + $IP rule del pref $((id+2000)) done - $IP rule add pref $(($id+1000)) iif "$2" lookup "$id" - $IP rule add pref $(($id+2000)) fwmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK lookup "$id" + $IP rule add pref $((id+1000)) iif "$2" lookup "$id" + $IP rule add pref $((id+2000)) fwmark "$(mwan3_id2mask id MMX_MASK)/$MMX_MASK" lookup "$id" } mwan3_delete_iface_rules() { - local id family + local id family IP config_get family "$1" family ipv4 mwan3_get_iface_id id "$1" @@ -689,12 +690,12 @@ mwan3_delete_iface_rules() return fi - while [ -n "$($IP rule list | awk '$1 == "'$(($id+1000)):'"')" ]; do - $IP rule del pref $(($id+1000)) + while [ -n "$($IP rule list | awk '$1 == "'$((id+1000)):'"')" ]; do + $IP rule del pref $((id+1000)) done - while [ -n "$($IP rule list | awk '$1 == "'$(($id+2000)):'"')" ]; do - $IP rule del pref $(($id+2000)) + while [ -n "$($IP rule list | awk '$1 == "'$((id+2000)):'"')" ]; do + $IP rule del pref $((id+2000)) done } @@ -785,7 +786,7 @@ mwan3_set_policy() total_weight_v4=$weight lowest_metric_v4=$metric elif [ "$metric" -eq "$lowest_metric_v4" ]; then - total_weight_v4=$(($total_weight_v4+$weight)) + total_weight_v4=$((total_weight_v4+weight)) total_weight=$total_weight_v4 else return @@ -796,7 +797,7 @@ mwan3_set_policy() total_weight_v6=$weight lowest_metric_v6=$metric elif [ "$metric" -eq "$lowest_metric_v6" ]; then - total_weight_v6=$(($total_weight_v6+$weight)) + total_weight_v6=$((total_weight_v6+weight)) total_weight=$total_weight_v6 else return @@ -807,9 +808,9 @@ mwan3_set_policy() mwan3_push_update -A "mwan3_policy_$policy" \ -m mark --mark 0x0/$MMX_MASK \ -m comment --comment \"$iface $weight $weight\" \ - -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK + -j MARK --set-xmark "$(mwan3_id2mask id MMX_MASK)/$MMX_MASK" elif [ $is_offline -eq 0 ]; then - probability=$(($weight*1000/$total_weight)) + probability=$((weight*1000/total_weight)) if [ "$probability" -lt 10 ]; then probability="0.00$probability" elif [ $probability -lt 100 ]; then @@ -826,7 +827,7 @@ mwan3_set_policy() --mode random \ --probability "$probability" \ -m comment --comment \"$iface $weight $total_weight\" \ - -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK + -j MARK --set-xmark "$(mwan3_id2mask id MMX_MASK)/$MMX_MASK" elif [ -n "$device" ]; then echo "$current" | grep -q "^-A mwan3_policy_$policy.*--comment .* [0-9]* [0-9]*" || mwan3_push_update -I "mwan3_policy_$policy" \ @@ -858,7 +859,7 @@ mwan3_create_policies_iptables() current="$($IPT -S)" update="*mangle" if [ -n "${current##*-N mwan3_policy_$1*}" ]; then - mwan3_push_update -N "mwan3_policy_$1" + mwan3_push_update -N "mwan3_policy_$1" fi mwan3_push_update -F "mwan3_policy_$1" @@ -917,12 +918,12 @@ mwan3_set_sticky_iptables() [ -n "$id" ] || return 0 if [ -z "${current##*-N mwan3_iface_in_$1*}" ]; then mwan3_push_update -I "mwan3_rule_$rule" \ - -m mark --mark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK \ + -m mark --mark "$(mwan3_id2mask id MMX_MASK)/$MMX_MASK" \ -m set ! --match-set "mwan3_sticky_$rule" src,src \ - -j MARK --set-xmark 0x0/$MMX_MASK + -j MARK --set-xmark "0x0/$MMX_MASK" mwan3_push_update -I "mwan3_rule_$rule" \ - -m mark --mark 0/$MMX_MASK \ - -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK + -m mark --mark "0/$MMX_MASK" \ + -j MARK --set-xmark "$(mwan3_id2mask id MMX_MASK)/$MMX_MASK" fi fi done @@ -932,7 +933,7 @@ mwan3_set_user_iptables_rule() { local ipset family proto policy src_ip src_port src_iface src_dev local sticky dest_ip dest_port use_policy timeout policy - local global_logging rule_logging loglevel rule_policy rule ipv + local global_logging rule_logging loglevel rule_policy rule ipv rule="$1" ipv="$2" @@ -963,9 +964,9 @@ mwan3_set_user_iptables_rule() [ -z "$dest_ip" ] && unset dest_ip [ -z "$src_ip" ] && unset src_ip [ -z "$ipset" ] && unset ipset - [ -z "$src_port" ] && unset src_port - [ -z "$dest_port" ] && unset dest_port - if [ "$proto" != 'tcp' ] && [ "$proto" != 'udp' ]; then + [ -z "$src_port" ] && unset src_port + [ -z "$dest_port" ] && unset dest_port + if [ "$proto" != 'tcp' ] && [ "$proto" != 'udp' ]; then [ -n "$src_port" ] && { LOG warn "src_port set to '$src_port' but proto set to '$proto' not tcp or udp. src_port will be ignored" } @@ -1170,8 +1171,8 @@ mwan3_report_iface_status() if [ -z "$id" ] || [ -z "$device" ]; then result="offline" - elif [ -n "$($IP rule | awk '$1 == "'$(($id+1000)):'"')" ] && \ - [ -n "$($IP rule | awk '$1 == "'$(($id+2000)):'"')" ] && \ + elif [ -n "$($IP rule | awk '$1 == "'$((id+1000)):'"')" ] && \ + [ -n "$($IP rule | awk '$1 == "'$((id+2000)):'"')" ] && \ [ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" ] && \ [ -n "$($IP route list table $id default dev $device 2> /dev/null)" ]; then json_init @@ -1183,11 +1184,12 @@ mwan3_report_iface_status() json_get_vars online uptime json_select .. json_select .. - online="$(printf '%02dh:%02dm:%02ds\n' $(($online/3600)) $(($online%3600/60)) $(($online%60)))" - uptime="$(printf '%02dh:%02dm:%02ds\n' $(($uptime/3600)) $(($uptime%3600/60)) $(($uptime%60)))" + online="$(printf '%02dh:%02dm:%02ds\n' $((online/3600)) $((online%3600/60)) $((online%60)))" + uptime="$(printf '%02dh:%02dm:%02ds\n' $((uptime/3600)) $((uptime%3600/60)) $((uptime%60)))" result="$(mwan3_get_iface_hotplug_state $1) $online, uptime $uptime" - elif [ -n "$($IP rule | awk '$1 == "'$(($id+1000)):'"')" ] || \ - [ -n "$($IP rule | awk '$1 == "'$(($id+2000)):'"')" ] || \ + elif [ -n "$($IP rule | awk '$1 == "'$((id+1000)):'"')" ] || \ + [ -n "$($IP rule | awk '$1 == "'$((id+2000)):'"')" ] || \ + [ -n "$($IP rule | awk '$1 == "'$((id+3000)):'"')" ] || \ [ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" ] || \ [ -n "$($IP route list table $id default dev $device 2> /dev/null)" ]; then result="error" @@ -1225,10 +1227,10 @@ mwan3_report_policies() total_weight=$($ipt -S "$policy" | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | head -1 | awk '{print $3}') - if [ ! -z "${total_weight##*[!0-9]*}" ]; then + if [ -n "${total_weight##*[!0-9]*}" ]; then for iface in $($ipt -S "$policy" | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | awk '{print $1}'); do weight=$($ipt -S "$policy" | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | awk '$1 == "'$iface'"' | awk '{print $2}') - percent=$(($weight*100/$total_weight)) + percent=$((weight*100/total_weight)) echo " $iface ($percent%)" done else @@ -1306,6 +1308,6 @@ mwan3_flush_conntrack() mwan3_track_clean() { - rm -rf "$MWAN3_STATUS_DIR/${1}" &> /dev/null + rm -rf "${MWAN3_STATUS_DIR:?}/${1}" &> /dev/null rmdir --ignore-fail-on-non-empty "$MWAN3_STATUS_DIR" } diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 index fd6b5204f..af66a70e1 100755 --- a/net/mwan3/files/usr/sbin/mwan3 +++ b/net/mwan3/files/usr/sbin/mwan3 @@ -44,7 +44,7 @@ ifdown() ifup() { - local device enabled up l3_device status interface true_iface + local enabled up l3_device status interface true_iface if [ -z "$1" ]; then echo "Expecting interface. Usage: mwan3 ifup <interface>" @@ -104,40 +104,40 @@ interfaces() echo "Interface status:" config_foreach mwan3_report_iface_status interface - echo -e + echo } policies() { echo "Current ipv4 policies:" mwan3_report_policies_v4 - echo -e + echo [ $NO_IPV6 -ne 0 ] && return echo "Current ipv6 policies:" mwan3_report_policies_v6 - echo -e + echo } connected() { echo "Directly connected ipv4 networks:" mwan3_report_connected_v4 - echo -e + echo [ $NO_IPV6 -ne 0 ] && return echo "Directly connected ipv6 networks:" mwan3_report_connected_v6 - echo -e + echo } rules() { echo "Active ipv4 user rules:" mwan3_report_rules_v4 - echo -e + echo [ $NO_IPV6 -ne 0 ] && return echo "Active ipv6 user rules:" mwan3_report_rules_v6 - echo -e + echo } status() @@ -205,12 +205,12 @@ stop() IP="$IP6" fi - for tid in $(ip route list table all | sed -ne 's/.*table \([0-9]\+\).*/\1/p'|sort -u); do + for tid in $(ip route list table all | sed -ne 's/.*table \([0-9]\+\).*/\1/p' | sort -u); do [ $tid -gt $MWAN3_INTERFACE_MAX ] && continue $IP route flush table $tid &> /dev/null done - for rule in $($IP rule list | egrep '^[1-2][0-9]{3}\:' | cut -d ':' -f 1); do + for rule in $($IP rule list | grep -E '^[1-3][0-9]{3}\:' | cut -d ':' -f 1); do $IP rule del pref $rule &> /dev/null done table="$($IPT -S)" @@ -255,6 +255,7 @@ restart() { case "$1" in ifup|ifdown|interfaces|policies|connected|rules|status|start|stop|restart) mwan3_init + # shellcheck disable=SC2048 $* ;; *) diff --git a/net/mwan3/files/usr/sbin/mwan3rtmon b/net/mwan3/files/usr/sbin/mwan3rtmon index 98a5c4b89..8a7da7a8f 100755 --- a/net/mwan3/files/usr/sbin/mwan3rtmon +++ b/net/mwan3/files/usr/sbin/mwan3rtmon @@ -8,8 +8,7 @@ mwan3_rtmon_route_handle() { config_load mwan3 - local section action route_line family tbl device metric tos dst line - local route_device tid + local section action route_line family tbl device metric tos dst line tid route_line=${1##"Deleted "} route_family=$2 @@ -48,7 +47,7 @@ mwan3_rtmon_route_handle() [ $action = "add" ] && [ -z "${tbl##*$route_line*}" ] && return [ $action = "del" ] && [ -n "${tbl##*$route_line*}" ] && return network_get_device device "$section" - 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" } @@ -69,7 +68,7 @@ mwan3_rtmon_route_handle() dst=${route_line%% *} grep_line="$dst ${tos:+tos $tos}.*table [0-9].*${metric:+metric $metric}" - $IP route list table all | grep "$grep_line" | while read line; do + $IP route list table all | grep "$grep_line" | while read -r line; do tbl=${line##*table } tbl=${tbl%% *} [ $tbl -gt $MWAN3_INTERFACE_MAX ] && continue @@ -99,7 +98,7 @@ main() fi mwan3_init - $IP monitor route | while read line; do + $IP monitor route | while read -r line; do [ -z "${line##*table*}" ] && continue LOG debug "handling route update $family $line" mwan3_lock "service" "mwan3rtmon" diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 5cbf5f75d..a48df72b5 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -44,7 +44,7 @@ validate_track_method() { LOG warn "Missing httping. Please install httping package." return 1 } - [ -n "$2" -a "$2" != "0.0.0.0" -a "$2" != "::" ] || { + [ -n "$2" ] && { [ "$2" = "0.0.0.0" ] || [ "$2" = "::" ]; } && { LOG warn "Cannot determine source IP for the interface which is required by httping." return 1 } @@ -64,10 +64,10 @@ validate_track_method() { disconnected() { echo "offline" > /var/run/mwan3track/$INTERFACE/STATUS - echo "$(get_uptime)" > /var/run/mwan3track/$INTERFACE/OFFLINE + get_uptime > /var/run/mwan3track/$INTERFACE/OFFLINE echo "0" > /var/run/mwan3track/$INTERFACE/ONLINE score=0 - [ "$1" == 1 ] && return + [ "$1" = 1 ] && return LOG notice "Interface $INTERFACE ($DEVICE) is offline" env -i ACTION="disconnected" INTERFACE="$INTERFACE" DEVICE="$DEVICE" /sbin/hotplug-call iface } @@ -75,12 +75,12 @@ disconnected() { connected() { echo "online" > /var/run/mwan3track/$INTERFACE/STATUS echo "0" > /var/run/mwan3track/$INTERFACE/OFFLINE - echo "$(get_uptime)" > /var/run/mwan3track/$INTERFACE/ONLINE + get_uptime > /var/run/mwan3track/$INTERFACE/ONLINE host_up_count=0 lost=0 turn=0 loss=0 - [ "$1" == 1 ] && return + [ "$1" = 1 ] && return LOG notice "Interface $INTERFACE ($DEVICE) is online" env -i ACTION="connected" INTERFACE="$INTERFACE" DEVICE="$DEVICE" /sbin/hotplug-call iface } @@ -94,11 +94,9 @@ firstconnect() { } update_status() { - local status track_ip - track_ip=$1 - status=$2 + local track_ip=$1 - echo "$1" > /var/run/mwan3track/$INTERFACE/TRACK_${track_ip} + echo "$2" > /var/run/mwan3track/$INTERFACE/TRACK_${track_ip} [ -z "$3" ] && return echo "$3" > /var/run/mwan3track/$INTERFACE/LATENCY_${track_ip} echo "$4" > /var/run/mwan3track/$INTERFACE/LOSS_${track_ip} @@ -151,13 +149,13 @@ main() { config_get failure_loss $INTERFACE failure_loss 40 config_get recovery_loss $INTERFACE recovery_loss 10 - local score=$(($down+$up)) + local score=$((down+up)) local track_ips=$(echo $* | cut -d ' ' -f 5-99) local host_up_count=0 local lost=0 local turn=0 local ping_protocol=4 - local sleep_time result ping_result ping_result_raw ping_status loss latency + local sleep_time result ping_result ping_result_raw ping_status loss latency firstconnect while true; do @@ -183,7 +181,7 @@ main() { ping_result_raw="$($PING -$ping_protocol -I ${SRC_IP:-$DEVICE} -c $count -W $timeout -s $size -t $max_ttl -q $track_ip 2>/dev/null)" ping_status=$? ping_result=$(echo "$ping_result_raw" | tail -n2) - loss="$(echo "$ping_result" | grep "packet loss" | cut -d "," -f3 | awk '{print $1}' | sed -e 's/%//')" + loss="$(echo "$ping_result" | grep "packet loss" | cut -d "," -f3 | awk '{print $1}' | sed -e 's/%//')" if [ "$ping_status" -ne 0 ] || [ "$loss" -eq 100 ]; then latency=999999 loss=100 @@ -234,14 +232,14 @@ main() { fi fi else - if [ "$loss" -ge "$failure_loss" -o "$latency" -ge "$failure_latency" ]; then + if [ "$loss" -ge "$failure_loss" ] || [ "$latency" -ge "$failure_latency" ]; then let lost++ update_status "$track_ip" "down" $latency $loss if [ $score -gt $up ]; then LOG info "Check (${track_method}: latency=${latency}ms loss=${loss}%) failed for target \"$track_ip\" on interface $INTERFACE ($DEVICE). Current score: $score" fi - elif [ "$loss" -le "$recovery_loss" -a "$latency" -le "$recovery_latency" ]; then + elif [ "$loss" -le "$recovery_loss" ] && [ "$latency" -le "$recovery_latency" ]; then let host_up_count++ update_status "$track_ip" "up" $latency $loss @@ -274,8 +272,8 @@ main() { score=0 fi else - if [ $score -lt $(($down+$up)) ] && [ $lost -gt 0 ]; then - LOG info "Lost $(($lost*$count)) ping(s) on interface $INTERFACE ($DEVICE). Current score: $score" + if [ $score -lt $((down+up)) ] && [ $lost -gt 0 ]; then + LOG info "Lost $((lost*count)) ping(s) on interface $INTERFACE ($DEVICE). Current score: $score" fi let score++ @@ -283,7 +281,7 @@ main() { if [ $score -gt $up ]; then echo "online" > /var/run/mwan3track/$INTERFACE/STATUS - score=$(($down+$up)) + score=$((down+up)) elif [ $score -le $up ]; then sleep_time=$recovery_interval fi @@ -298,7 +296,7 @@ main() { echo "${lost}" > /var/run/mwan3track/$INTERFACE/LOST echo "${score}" > /var/run/mwan3track/$INTERFACE/SCORE echo "${turn}" > /var/run/mwan3track/$INTERFACE/TURN - echo "$(get_uptime)" > /var/run/mwan3track/$INTERFACE/TIME + get_uptime > /var/run/mwan3track/$INTERFACE/TIME host_up_count=0 sleep "${sleep_time}" & |