Skip to content

Commit 33a89d8

Browse files
committed
runners: Expose a 'cleanup' action for silent cleanup of an interface
If a network interface is removed before SQM is stopped on that interface, removing the qdisc from that interface will result in errors in the log. Whereas not running the 'stop' action will result in leftover state files (and possibly an IFB interface). While the right thing to do would be to stop SQM before removing the interface, this is not always possible; for instance, pppd doesn't have a 'pre-down' hook. So to accommodate this use case, add a new 'cleanup' action, which just unwinds the firewall rules, removes the IFB interface (but silently in case it does not exist), and deletes the state file. Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
1 parent 30f2cee commit 33a89d8

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

platform/linux/sqm-bin

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
. /etc/sqm/sqm.conf
44
ACTION="$1"
55
RUN_IFACE="$2"
6+
CLEANUP=0
7+
8+
if [ "$ACTION" = "cleanup" ]; then
9+
CLEANUP=1
10+
ACTION=stop
11+
fi
612

713
if [ "$(id -u)" -ne "0" ]; then
814
echo "This script must be run as root." >&2
915
exit 1
1016
fi
1117

1218
if [ "$ACTION" != "start" -a "$ACTION" != "stop" -a "$ACTION" != "reload" ]; then
13-
echo "Usage: $0 <start|stop|reload> [iface]." >&2
19+
echo "Usage: $0 <start|stop|reload|cleanup> [iface]." >&2
1420
exit 1
1521
fi
1622

@@ -20,7 +26,7 @@ if [ "$ACTION" = "stop" -a -z "$RUN_IFACE" ]; then
2026
for f in ${SQM_STATE_DIR}/*.state; do
2127
# Source the state file prior to stopping; we need the $IFACE and
2228
# $SCRIPT variables saved in there.
23-
[ -f "$f" ] && ( . $f; IFACE=$IFACE SCRIPT=$SCRIPT SQM_DEBUG=$SQM_DEBUG SQM_DEBUG_LOG=$SQM_DEBUG_LOG OUTPUT_TARGET=$OUTPUT_TARGET ${SQM_LIB_DIR}/stop-sqm )
29+
[ -f "$f" ] && ( . $f; IFACE=$IFACE SCRIPT=$SCRIPT CLEANUP=$CLEANUP SQM_DEBUG=$SQM_DEBUG SQM_DEBUG_LOG=$SQM_DEBUG_LOG OUTPUT_TARGET=$OUTPUT_TARGET ${SQM_LIB_DIR}/stop-sqm )
2430
done
2531
exit 0
2632
fi

src/defaults.sh

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ fi
104104
# particular command
105105
SILENT=0
106106

107+
# If set to 1, stop-sqm will run the (silent) cleanup function instead of a full
108+
# stop operation
109+
[ -z "$CLEANUP" ] && CLEANUP=0
110+
107111
# Transaction log for unwinding ipt rules
108112
IPT_TRANS_LOG="${SQM_STATE_DIR}/${IFACE}.iptables.log"
109113

src/run-openwrt.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ ACTION="${1:-start}"
1616
RUN_IFACE="$2"
1717
LOCKDIR="${SQM_STATE_DIR}/sqm-run.lock"
1818

19+
CLEANUP=0
20+
if [ "$ACTION" = "cleanup" ]; then
21+
CLEANUP=1
22+
ACTION=stop
23+
fi
24+
1925
check_state_dir
2026
[ -d "${SQM_QDISC_STATE_DIR}" ] || ${SQM_LIB_DIR}/update-available-qdiscs
2127

@@ -26,7 +32,7 @@ stop_statefile() {
2632
# there.
2733
[ -f "$f" ] && ( . "$f";
2834
IFACE=$IFACE SCRIPT=$SCRIPT SQM_DEBUG=$SQM_DEBUG \
29-
SQM_DEBUG_LOG=$SQM_DEBUG_LOG \
35+
SQM_DEBUG_LOG=$SQM_DEBUG_LOG CLEANUP=$CLEANUP \
3036
SQM_VERBOSITY_MAX=$SQM_VERBOSITY_MAX \
3137
SQM_VERBOSITY_MIN=$SQM_VERBOSITY_MIN \
3238
OUTPUT_TARGET=$OUTPUT_TARGET ${SQM_LIB_DIR}/stop-sqm )

src/stop-sqm

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ if [ -z "${SCRIPT}" ] ; then
3535
fi
3636

3737
sqm_trace; sqm_trace "$(date): Stopping." # Add some space and a date stamp to verbose log output and log files to separate runs
38-
sqm_log "Stopping SQM on ${IFACE}"
3938

4039
# make sure to only delete the ifb associated with the current interface
4140
CUR_IFB=$( get_ifb_associated_with_if ${IFACE} )
@@ -48,7 +47,13 @@ fi
4847

4948
. "${SQM_LIB_DIR}/$SCRIPT"
5049

51-
sqm_stop
50+
if [ "$CLEANUP" -eq "1" ]; then
51+
sqm_log "Cleaning up SQM state on ${IFACE}"
52+
sqm_cleanup 1
53+
else
54+
sqm_log "Stopping SQM on ${IFACE}"
55+
sqm_stop
56+
fi
5257
rm -f "${STATE_FILE}"
5358

5459
exit 0

0 commit comments

Comments
 (0)