Merge pull request #13881 from aaronjg/mwan3-owner-procd

mwan3: fixup ipset and install errors
This commit is contained in:
Florian Eckert 2020-11-11 15:08:09 +01:00 committed by GitHub
commit 4b2e33a7e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 99 additions and 94 deletions

View file

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=mwan3 PKG_NAME:=mwan3
PKG_VERSION:=2.10.2 PKG_VERSION:=2.10.3
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de> PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
PKG_LICENSE:=GPL-2.0 PKG_LICENSE:=GPL-2.0
@ -43,9 +43,6 @@ define Package/mwan3/conffiles
/etc/mwan3.user /etc/mwan3.user
endef endef
define Build/Compile
endef
define Package/mwan3/postinst define Package/mwan3/postinst
#!/bin/sh #!/bin/sh
if [ -z "$${IPKG_INSTROOT}" ]; then if [ -z "$${IPKG_INSTROOT}" ]; then

View file

@ -35,12 +35,8 @@ $IPT4 -S mwan3_hook &>/dev/null || {
} }
mwan3_init 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 mwan3_set_user_iface_rules $INTERFACE $DEVICE
fi fi
@ -69,7 +65,7 @@ case "$ACTION" in
mwan3_create_iface_iptables $INTERFACE $DEVICE mwan3_create_iface_iptables $INTERFACE $DEVICE
mwan3_create_iface_rules $INTERFACE $DEVICE mwan3_create_iface_rules $INTERFACE $DEVICE
mwan3_set_iface_hotplug_state $INTERFACE "$status" mwan3_set_iface_hotplug_state $INTERFACE "$status"
if [ "$MWAN3_STARTUP" = "cmd" ]; then if [ "$MWAN3_STARTUP" != "init" ]; then
mwan3_create_iface_route $INTERFACE $DEVICE mwan3_create_iface_route $INTERFACE $DEVICE
mwan3_set_general_rules mwan3_set_general_rules
[ "$status" = "online" ] && mwan3_set_policies_iptables [ "$status" = "online" ] && mwan3_set_policies_iptables

7
net/mwan3/files/etc/init.d/mwan3 Normal file → Executable file
View file

@ -1,9 +1,8 @@
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
. /lib/functions.sh . "${IPKG_INSTROOT}/lib/mwan3/common.sh"
. /lib/mwan3/common.sh . "${IPKG_INSTROOT}/lib/functions/network.sh"
. /lib/functions/network.sh . "${IPKG_INSTROOT}/lib/mwan3/mwan3.sh"
. /lib/mwan3/mwan3.sh
START=19 START=19
USE_PROCD=1 USE_PROCD=1

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
. /usr/share/libubox/jshn.sh . "${IPKG_INSTROOT}/usr/share/libubox/jshn.sh"
IPS="ipset" IPS="ipset"
IPT4="iptables -t mangle -w" IPT4="iptables -t mangle -w"
@ -153,7 +153,8 @@ mwan3_set_connected_ipv4()
{ {
local connected_network_v4 candidate_list cidr_list local connected_network_v4 candidate_list cidr_list
$IPS -! create mwan3_connected_v4 hash:net $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="" candidate_list=""
cidr_list="" cidr_list=""
@ -178,10 +179,13 @@ mwan3_set_connected_ipv4()
$IPS -! add mwan3_connected_v4_temp "$connected_network_v4" $IPS -! add mwan3_connected_v4_temp "$connected_network_v4"
done 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 swap mwan3_connected_v4_temp mwan3_connected_v4 ||
$IPS destroy mwan3_connected_v4_temp 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 $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 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 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
done done
} }
@ -1012,7 +1017,7 @@ mwan3_get_iface_hotplug_state() {
mwan3_report_iface_status() mwan3_report_iface_status()
{ {
local device result tracking IP IPT local device result tracking IP IPT error
mwan3_get_iface_id id "$1" mwan3_get_iface_id id "$1"
network_get_device device "$1" network_get_device device "$1"
@ -1031,11 +1036,23 @@ mwan3_report_iface_status()
if [ -z "$id" ] || [ -z "$device" ]; then if [ -z "$id" ] || [ -z "$device" ]; then
result="offline" result="offline"
elif [ -n "$($IP rule | awk '$1 == "'$((id+1000)):'"')" ] && \ else
[ -n "$($IP rule | awk '$1 == "'$((id+2000)):'"')" ] && \ error=0
[ -n "$($IP rule | awk '$1 == "'$((id+3000)):'"')" ] && \ [ -n "$($IP rule | awk '$1 == "'$((id+1000)):'"')" ] ||
[ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" ] && \ error=$((error+1))
[ -n "$($IP route list table $id default dev $device 2> /dev/null)" ]; then [ -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_init
json_add_string section interfaces json_add_string section interfaces
json_add_string interface "$1" 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)))" 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)))" uptime="$(printf '%02dh:%02dm:%02ds\n' $((uptime/3600)) $((uptime%3600/60)) $((uptime%60)))"
result="$(mwan3_get_iface_hotplug_state $1) $online, uptime $uptime" result="$(mwan3_get_iface_hotplug_state $1) $online, uptime $uptime"
elif [ -n "$($IP rule | awk '$1 == "'$((id+1000)):'"')" ] || \ elif [ $error -gt 0 ] && [ $error -ne 31 ]; then
[ -n "$($IP rule | awk '$1 == "'$((id+2000)):'"')" ] || \ result="error (${error})"
[ -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 [ "$enabled" = "1" ]; then elif [ "$enabled" = "1" ]; then
result="offline" result="offline"
else else

14
net/mwan3/files/usr/libexec/rpcd/mwan3 Normal file → Executable file
View file

@ -77,11 +77,12 @@ get_mwan3_status() {
local online=0 local online=0
local offline=0 local offline=0
local up="0" local up="0"
local enabled device time_p time_n time_u time_d status track_status local enabled time_p time_n time_u time_d status track_status
network_get_device device $1 if [ "${iface}" != "${iface_select}" ] && [ "${iface_select}" != "" ]; then
return
fi
if [ "${iface}" = "${iface_select}" ] || [ "${iface_select}" = "" ]; then
track_status="$(mwan3_get_mwan3track_status "$1")" track_status="$(mwan3_get_mwan3track_status "$1")"
[ "$track_status" = "active" ] && running="1" [ "$track_status" = "active" ] && running="1"
time_p="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME")" time_p="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME")"
@ -127,20 +128,19 @@ get_mwan3_status() {
json_add_boolean "running" "${running}" json_add_boolean "running" "${running}"
json_add_boolean "up" "${up}" json_add_boolean "up" "${up}"
json_add_array "track_ip" json_add_array "track_ip"
for file in $MWAN3TRACK_STATUS_DIR/${iface}/*; do for file in $MWAN3TRACK_STATUS_DIR/${iface}/TRACK_*; do
[ -z "${file#*/TRACK_OUTPUT}" ] && continue
[ -z "${file#*/TRACK_\*}" ] && continue
track="${file#*/TRACK_}" track="${file#*/TRACK_}"
if [ "${track}" != "${file}" ]; then
json_add_object json_add_object
json_add_string ip "${track}" json_add_string ip "${track}"
json_add_string status "$(cat "${file}")" json_add_string status "$(cat "${file}")"
json_add_int latency "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LATENCY_${track}")" json_add_int latency "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LATENCY_${track}")"
json_add_int packetloss "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOSS_${track}")" json_add_int packetloss "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOSS_${track}")"
json_close_object json_close_object
fi
done done
json_close_array json_close_array
json_close_object json_close_object
fi
} }
main () { main () {

0
net/mwan3/files/usr/sbin/mwan3 Normal file → Executable file
View file

0
net/mwan3/files/usr/sbin/mwan3rtmon Normal file → Executable file
View file

0
net/mwan3/files/usr/sbin/mwan3track Normal file → Executable file
View file