Browse Source

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

mwan3: fixup ipset and install errors
lilik-openwrt-22.03
Florian Eckert 4 years ago
committed by GitHub
parent
commit
4b2e33a7e0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 100 additions and 95 deletions
  1. +1
    -4
      net/mwan3/Makefile
  2. +2
    -6
      net/mwan3/files/etc/hotplug.d/iface/15-mwan3
  3. +3
    -4
      net/mwan3/files/etc/init.d/mwan3
  4. +31
    -18
      net/mwan3/files/lib/mwan3/mwan3.sh
  5. +63
    -63
      net/mwan3/files/usr/libexec/rpcd/mwan3
  6. +0
    -0
      net/mwan3/files/usr/sbin/mwan3
  7. +0
    -0
      net/mwan3/files/usr/sbin/mwan3rtmon
  8. +0
    -0
      net/mwan3/files/usr/sbin/mwan3track

+ 1
- 4
net/mwan3/Makefile 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


+ 2
- 6
net/mwan3/files/etc/hotplug.d/iface/15-mwan3 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


+ 3
- 4
net/mwan3/files/etc/init.d/mwan3 View File

@ -1,9 +1,8 @@
#!/bin/sh /etc/rc.common #!/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 START=19
USE_PROCD=1 USE_PROCD=1


+ 31
- 18
net/mwan3/files/lib/mwan3/mwan3.sh 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 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 $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)):'"')" ] && \
[ -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_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)):'"')" ] || \
[ -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 elif [ "$enabled" = "1" ]; then
result="offline" result="offline"
else else


+ 63
- 63
net/mwan3/files/usr/libexec/rpcd/mwan3 View File

@ -77,70 +77,70 @@ 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
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 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 () { main () {


+ 0
- 0
net/mwan3/files/usr/sbin/mwan3 View File


+ 0
- 0
net/mwan3/files/usr/sbin/mwan3rtmon View File


+ 0
- 0
net/mwan3/files/usr/sbin/mwan3track View File


Loading…
Cancel
Save