diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 3b853e6ea..b8a05b624 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.10.2 +PKG_VERSION:=2.10.3 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPL-2.0 @@ -43,9 +43,6 @@ define Package/mwan3/conffiles /etc/mwan3.user endef -define Build/Compile -endef - define Package/mwan3/postinst #!/bin/sh if [ -z "$${IPKG_INSTROOT}" ]; then diff --git a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 index f1755d26f..f9212a3a6 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 @@ -35,12 +35,8 @@ $IPT4 -S mwan3_hook &>/dev/null || { } mwan3_init -[ "$MWAN3_STARTUP" = 1 ] || { - config_get family $INTERFACE family ipv4 - mwan3_set_connected_${family} -} -if [ "$MWAN3_STARTUP" != 1 ] && [ "$ACTION" = "ifup" ]; then +if [ "$MWAN3_STARTUP" != "init" ] && [ "$ACTION" = "ifup" ]; then mwan3_set_user_iface_rules $INTERFACE $DEVICE fi @@ -69,7 +65,7 @@ case "$ACTION" in mwan3_create_iface_iptables $INTERFACE $DEVICE mwan3_create_iface_rules $INTERFACE $DEVICE mwan3_set_iface_hotplug_state $INTERFACE "$status" - if [ "$MWAN3_STARTUP" = "cmd" ]; then + if [ "$MWAN3_STARTUP" != "init" ]; then mwan3_create_iface_route $INTERFACE $DEVICE mwan3_set_general_rules [ "$status" = "online" ] && mwan3_set_policies_iptables diff --git a/net/mwan3/files/etc/init.d/mwan3 b/net/mwan3/files/etc/init.d/mwan3 old mode 100644 new mode 100755 index 23c21ab5d..743beb152 --- a/net/mwan3/files/etc/init.d/mwan3 +++ b/net/mwan3/files/etc/init.d/mwan3 @@ -1,9 +1,8 @@ #!/bin/sh /etc/rc.common -. /lib/functions.sh -. /lib/mwan3/common.sh -. /lib/functions/network.sh -. /lib/mwan3/mwan3.sh +. "${IPKG_INSTROOT}/lib/mwan3/common.sh" +. "${IPKG_INSTROOT}/lib/functions/network.sh" +. "${IPKG_INSTROOT}/lib/mwan3/mwan3.sh" START=19 USE_PROCD=1 diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 43740e2de..fcfda5b89 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -1,6 +1,6 @@ #!/bin/sh -. /usr/share/libubox/jshn.sh +. "${IPKG_INSTROOT}/usr/share/libubox/jshn.sh" IPS="ipset" IPT4="iptables -t mangle -w" @@ -153,7 +153,8 @@ mwan3_set_connected_ipv4() { local connected_network_v4 candidate_list cidr_list $IPS -! create mwan3_connected_v4 hash:net - $IPS create mwan3_connected_v4_temp hash:net + $IPS create mwan3_connected_v4_temp hash:net || + LOG notice "failed to create ipset mwan3_connected_v4_temp" candidate_list="" cidr_list="" @@ -178,10 +179,13 @@ mwan3_set_connected_ipv4() $IPS -! add mwan3_connected_v4_temp "$connected_network_v4" done - $IPS add mwan3_connected_v4_temp 224.0.0.0/3 + $IPS add mwan3_connected_v4_temp 224.0.0.0/3 || + LOG notice "failed to add 224.0.0.0/3 to mwan3_connected_v4_temp" - $IPS swap mwan3_connected_v4_temp mwan3_connected_v4 - $IPS destroy mwan3_connected_v4_temp + $IPS swap mwan3_connected_v4_temp mwan3_connected_v4 || + LOG notice "failed to swap mwan3_connected_v4_temp and mwan3_connected_v4" + $IPS destroy mwan3_connected_v4_temp || + LOG notice "failed to destroy ipset mwan3_connected_v4_temp" $IPS -! add mwan3_connected mwan3_connected_v4 } @@ -517,7 +521,8 @@ mwan3_delete_iface_ipset_entries() for setname in $(ipset -n list | grep ^mwan3_sticky_); do for entry in $(ipset list "$setname" | grep "$(mwan3_id2mask id MMX_MASK | awk '{ printf "0x%08x", $1; }')" | cut -d ' ' -f 1); do - $IPS del "$setname" $entry + $IPS del "$setname" $entry || + LOG notice "failed to delete $entry from $setname" done done } @@ -1012,7 +1017,7 @@ mwan3_get_iface_hotplug_state() { mwan3_report_iface_status() { - local device result tracking IP IPT + local device result tracking IP IPT error mwan3_get_iface_id id "$1" network_get_device device "$1" @@ -1031,11 +1036,23 @@ 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)):'"')" ] && \ - [ -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 + else + error=0 + [ -n "$($IP rule | awk '$1 == "'$((id+1000)):'"')" ] || + error=$((error+1)) + [ -n "$($IP rule | awk '$1 == "'$((id+2000)):'"')" ] || + error=$((error+2)) + [ -n "$($IP rule | awk '$1 == "'$((id+3000)):'"')" ] || + error=$((error+4)) + [ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" ] || + error=$((error+8)) + [ -n "$($IP route list table $id default dev $device 2> /dev/null)" ] || + error=$((error+16)) + fi + + if [ "$result" = "offline" ]; then + : + elif [ $error -eq 0 ]; then json_init json_add_string section interfaces json_add_string interface "$1" @@ -1048,12 +1065,8 @@ mwan3_report_iface_status() 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)):'"')" ] || \ - [ -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" + elif [ $error -gt 0 ] && [ $error -ne 31 ]; then + result="error (${error})" elif [ "$enabled" = "1" ]; then result="offline" else diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 old mode 100644 new mode 100755 index a97b33d5c..0d8693e64 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -77,70 +77,70 @@ get_mwan3_status() { local online=0 local offline=0 local up="0" - local enabled device time_p time_n time_u time_d status track_status - - network_get_device device $1 - - if [ "${iface}" = "${iface_select}" ] || [ "${iface_select}" = "" ]; then - track_status="$(mwan3_get_mwan3track_status "$1")" - [ "$track_status" = "active" ] && running="1" - time_p="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME")" - [ -z "${time_p}" ] || { - time_n="$(get_uptime)" - let age=time_n-time_p - } - - time_u="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/ONLINE")" - [ -z "${time_u}" ] || [ "${time_u}" = "0" ] || { - time_n="$(get_uptime)" - let online=time_n-time_u - } - - time_d="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/OFFLINE")" - [ -z "${time_d}" ] || [ "${time_d}" = "0" ] || { - time_n="$(get_uptime)" - let offline=time_n-time_d - } - - local uptime="0" - - config_get enabled "$iface" enabled 0 - network_get_uptime uptime "$iface" - network_is_up "$iface" && up="1" - - if [ -f "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS" ]; then - status="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS")" - else - status="unknown" - fi - - json_add_object "${iface}" - json_add_int age "$age" - json_add_int online "${online}" - json_add_int offline "${offline}" - json_add_int uptime "${uptime}" - json_add_int "score" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/SCORE")" - json_add_int "lost" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOST")" - json_add_int "turn" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TURN")" - json_add_string "status" "${status}" - json_add_boolean "enabled" "${enabled}" - json_add_boolean "running" "${running}" - json_add_boolean "up" "${up}" - json_add_array "track_ip" - for file in $MWAN3TRACK_STATUS_DIR/${iface}/*; do - track="${file#*/TRACK_}" - if [ "${track}" != "${file}" ]; then - json_add_object - json_add_string ip "${track}" - json_add_string status "$(cat "${file}")" - json_add_int latency "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LATENCY_${track}")" - json_add_int packetloss "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOSS_${track}")" - json_close_object - fi - done - json_close_array - json_close_object + local enabled time_p time_n time_u time_d status track_status + + if [ "${iface}" != "${iface_select}" ] && [ "${iface_select}" != "" ]; then + return + fi + + track_status="$(mwan3_get_mwan3track_status "$1")" + [ "$track_status" = "active" ] && running="1" + time_p="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME")" + [ -z "${time_p}" ] || { + time_n="$(get_uptime)" + let age=time_n-time_p + } + + time_u="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/ONLINE")" + [ -z "${time_u}" ] || [ "${time_u}" = "0" ] || { + time_n="$(get_uptime)" + let online=time_n-time_u + } + + time_d="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/OFFLINE")" + [ -z "${time_d}" ] || [ "${time_d}" = "0" ] || { + time_n="$(get_uptime)" + let offline=time_n-time_d + } + + local uptime="0" + + config_get enabled "$iface" enabled 0 + network_get_uptime uptime "$iface" + network_is_up "$iface" && up="1" + + if [ -f "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS" ]; then + status="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS")" + else + status="unknown" fi + + json_add_object "${iface}" + json_add_int age "$age" + json_add_int online "${online}" + json_add_int offline "${offline}" + json_add_int uptime "${uptime}" + json_add_int "score" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/SCORE")" + json_add_int "lost" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOST")" + json_add_int "turn" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TURN")" + json_add_string "status" "${status}" + json_add_boolean "enabled" "${enabled}" + json_add_boolean "running" "${running}" + json_add_boolean "up" "${up}" + json_add_array "track_ip" + for file in $MWAN3TRACK_STATUS_DIR/${iface}/TRACK_*; do + [ -z "${file#*/TRACK_OUTPUT}" ] && continue + [ -z "${file#*/TRACK_\*}" ] && continue + track="${file#*/TRACK_}" + json_add_object + json_add_string ip "${track}" + json_add_string status "$(cat "${file}")" + json_add_int latency "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LATENCY_${track}")" + json_add_int packetloss "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOSS_${track}")" + json_close_object + done + json_close_array + json_close_object } main () { diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 old mode 100644 new mode 100755 diff --git a/net/mwan3/files/usr/sbin/mwan3rtmon b/net/mwan3/files/usr/sbin/mwan3rtmon old mode 100644 new mode 100755 diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track old mode 100644 new mode 100755