Browse Source

mwan3: use procd for locking everywhere

Replace locks on /var/run/mwan3.lock with locks via procd.

This fixes a deadlock issue where mwan3 stop would have a procd
lock, but a hotplug script would have the /var/run/mwan3.lock

Locking can be removed from mwan3rtmon since:
1) procd will have sent the KILL signal to the process during
shutdown, so it will not add routes to already removed interfaces on
mwan3 shutdown and
2) mwan3rtmon checks if an interface is active based on the
mwan3_iface_in_<IFACE> entry in iptables, and the hotplug script
always adds this before creating the route table and removes it
before deleting the route table

Fixes github issue #13704
(https://github.com/openwrt/packages/issues/13704)
lilik-openwrt-22.03
Aaron Goodman 4 years ago
committed by Florian Eckert
parent
commit
59d12598b5
5 changed files with 9 additions and 35 deletions
  1. +6
    -10
      net/mwan3/files/etc/hotplug.d/iface/15-mwan3
  2. +3
    -4
      net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user
  3. +0
    -7
      net/mwan3/files/etc/init.d/mwan3
  4. +0
    -10
      net/mwan3/files/lib/mwan3/mwan3.sh
  5. +0
    -4
      net/mwan3/files/usr/sbin/mwan3rtmon

+ 6
- 10
net/mwan3/files/etc/hotplug.d/iface/15-mwan3 View File

@ -5,6 +5,10 @@
. /lib/mwan3/mwan3.sh
. /lib/mwan3/common.sh
initscript=/etc/init.d/mwan3
. /lib/functions/procd.sh
SCRIPTNAME="mwan3-hotplug"
[ "$ACTION" = "ifup" ] || [ "$ACTION" = "ifdown" ] || [ "$ACTION" = "connected" ] || [ "$ACTION" = "disconnected" ] || exit 1
[ -n "$INTERFACE" ] || exit 2
@ -15,18 +19,17 @@ if { [ "$ACTION" = "ifup" ] || [ "$ACTION" = "connected" ] ; } && [ -z "$DEVICE"
exit 3
fi
[ "$MWAN3_STARTUP" = 1 ] || mwan3_lock "$ACTION" "$INTERFACE"
[ "$MWAN3_STARTUP" = 1 ] || procd_lock
config_load mwan3
/etc/init.d/mwan3 running || {
[ "$MWAN3_STARTUP" = 1 ] || mwan3_unlock "$ACTION" "$INTERFACE"
[ "$MWAN3_STARTUP" = 1 ] || procd_lock
LOG notice "mwan3 hotplug $ACTION on $INTERFACE not called because globally disabled"
mwan3_flush_conntrack "$INTERFACE" "$ACTION"
exit 0
}
$IPT4 -S mwan3_hook &>/dev/null || {
mwan3_unlock "$ACTION" "$INTERFACE"
LOG warn "hotplug called on $INTERFACE before mwan3 has been set up"
exit 0
}
@ -43,7 +46,6 @@ fi
config_get_bool enabled $INTERFACE 'enabled' '0'
[ "${enabled}" -eq 1 ] || {
[ "$MWAN3_STARTUP" = 1 ] || mwan3_unlock "$ACTION" "$INTERFACE"
LOG notice "mwan3 hotplug on $INTERFACE not called because interface disabled"
exit 0
}
@ -56,11 +58,6 @@ else
status=online
fi
if [ "$ACTION" = ifup ] || [ "$ACTION" = ifdown ]; then
initscript=/etc/init.d/mwan3
. /lib/functions/procd.sh
fi
LOG notice "Execute $ACTION event on interface $INTERFACE (${DEVICE:-unknown})"
case "$ACTION" in
@ -93,5 +90,4 @@ case "$ACTION" in
mwan3_set_policies_iptables
;;
esac
[ "$MWAN3_STARTUP" = 1 ] || mwan3_unlock "$ACTION" "$INTERFACE"
exit 0

+ 3
- 4
net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user View File

@ -3,11 +3,12 @@
[ -f "/etc/mwan3.user" ] && {
. /lib/functions.sh
. /lib/mwan3/mwan3.sh
initscript=/etc/init.d/mwan3
. /lib/functions/procd.sh
[ "$MWAN3_SHUTDOWN" != 1 ] && mwan3_lock "$ACTION" "$DEVICE-user"
[ "$MWAN3_SHUTDOWN" != 1 ] && procd_lock
[ "$MWAN3_SHUTDOWN" != 1 ] && ! /etc/init.d/mwan3 running && {
mwan3_unlock "$ACTION" "$DEVICE-user"
exit 0
}
@ -19,8 +20,6 @@
exit 0
}
[ "$MWAN3_SHUTDOWN" != 1 ] && mwan3_unlock "$ACTION" "$DEVICE-user"
env -i ACTION="$ACTION" INTERFACE="$INTERFACE" DEVICE="$DEVICE" \
/bin/sh /etc/mwan3.user
}


+ 0
- 7
net/mwan3/files/etc/init.d/mwan3 View File

@ -31,8 +31,6 @@ start_service() {
mwan3_init
config_foreach start_tracker interface
mwan3_lock "command" "mwan3"
mwan3_update_iface_to_table
mwan3_set_connected_ipset
mwan3_set_custom_ipset
@ -43,8 +41,6 @@ start_service() {
mwan3_set_policies_iptables
mwan3_set_user_rules
mwan3_unlock "command" "mwan3"
procd_open_instance rtmon_ipv4
procd_set_param command /usr/sbin/mwan3rtmon ipv4
procd_set_param respawn
@ -61,8 +57,6 @@ start_service() {
stop_service() {
local ipset rule IP IPTR IPT family table tid
mwan3_lock "command" "mwan3"
config_load mwan3
mwan3_init
config_foreach mwan3_interface_shutdown interface
@ -108,7 +102,6 @@ stop_service() {
rm -rf $MWAN3_STATUS_DIR $MWAN3TRACK_STATUS_DIR
mwan3_unlock "command" "mwan3"
}
reload_service() {


+ 0
- 10
net/mwan3/files/lib/mwan3/mwan3.sh View File

@ -103,16 +103,6 @@ mwan3_count_one_bits()
echo $count
}
mwan3_lock() {
lock /var/run/mwan3.lock
#LOG debug "$1 $2 (lock)"
}
mwan3_unlock() {
#LOG debug "$1 $2 (unlock)"
lock -u /var/run/mwan3.lock
}
mwan3_get_iface_id()
{
local _tmp


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

@ -159,16 +159,13 @@ main()
IP="$IP4"
fi
mwan3_init
mwan3_lock "mwan3rtmon" "start"
sh -c "echo \$\$; exec $IP monitor route" | {
read -r monitor_pid
trap_with_arg func_trap "$monitor_pid" SIGINT SIGTERM SIGKILL
while IFS='' read -r line; do
[ -z "${line##*table*}" ] && continue
LOG debug "handling route update $family '$line'"
mwan3_lock "service" "mwan3rtmon"
mwan3_rtmon_route_handle "$line" "$family"
mwan3_unlock "service" "mwan3rtmon"
done
} &
child=$!
@ -176,7 +173,6 @@ main()
trap_with_arg func_trap "$child" SIGINT SIGTERM SIGKILL
mwan3_set_connected_${family}
mwan3_add_all_routes ${family}
mwan3_unlock "mwan3rtmon" "start"
kill -SIGCONT $child
wait $!
}


Loading…
Cancel
Save