diff options
author | Aaron Goodman <aaronjg@stanford.edu> | 2020-11-05 20:37:37 -0500 |
---|---|---|
committer | Florian Eckert <fe@dev.tdt.de> | 2020-11-06 10:40:57 +0100 |
commit | 59d12598b50edbc5a7a1f178c3c291524bd85b13 (patch) | |
tree | 1dd9e076c1bdbc7f7d475406d1ab9f4ec8b977f0 /net/mwan3/files | |
parent | bec7a1086f3f94a88875e11e99d80009b58c58f2 (diff) |
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)
Diffstat (limited to 'net/mwan3/files')
-rw-r--r-- | net/mwan3/files/etc/hotplug.d/iface/15-mwan3 | 16 | ||||
-rw-r--r-- | net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user | 7 | ||||
-rw-r--r-- | net/mwan3/files/etc/init.d/mwan3 | 7 | ||||
-rw-r--r-- | net/mwan3/files/lib/mwan3/mwan3.sh | 10 | ||||
-rw-r--r-- | net/mwan3/files/usr/sbin/mwan3rtmon | 4 |
5 files changed, 9 insertions, 35 deletions
diff --git a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 index 5c60128d4..5fe3e33e0 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 @@ -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 diff --git a/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user b/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user index 698fe0909..be857e8ff 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user +++ b/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user @@ -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 } diff --git a/net/mwan3/files/etc/init.d/mwan3 b/net/mwan3/files/etc/init.d/mwan3 index b7cf91eb1..bd1ea7260 100644 --- a/net/mwan3/files/etc/init.d/mwan3 +++ b/net/mwan3/files/etc/init.d/mwan3 @@ -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() { diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index e6e43ebe8..8a5fe6f0d 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -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 diff --git a/net/mwan3/files/usr/sbin/mwan3rtmon b/net/mwan3/files/usr/sbin/mwan3rtmon index 569b4d172..6ece58125 100644 --- a/net/mwan3/files/usr/sbin/mwan3rtmon +++ b/net/mwan3/files/usr/sbin/mwan3rtmon @@ -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 $! } |