Skip to content

Commit 37690d4

Browse files
Workaround for crashes when called from hotplug
1 parent ac65f28 commit 37690d4

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,8 @@ If it's working the output from tc should look something like this:
7878
* ECN marking is not supported
7979
* The script does not does anything with the Link Layer Adaptation fields.
8080
* On kernel 5.10 the script does not remove the nssifb interface if it's stopped, because removing or even bringing down the interface frequently crashed my router. This could cause problems if you're switching to a script which set up regular ifb4ethX interfaces. You probably need to reboot if you want to switch to another SQM script. On kernel 5.15 this problem has been resolved.
81+
* In some cases, the router crashes on ip link up of nssifb, *especially* when called from hotplug. Because of this, there's workaround in the script that prevents the script from executing when it's called from hotplug.
82+
83+
84+
8185

files/usr/lib/sqm/nss-rk.qos

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
################################################################################
22
# nss-rk.qos (HW Accelerated Simple Traffic Shaper)
3-
# version 20230313a
3+
# version 20230314a
44
#
55
# sqm script to use the NSS accelerated nssfq_codel qdisc
66
#
77
# Based on simple.qos and nss.qos by ricsc.
88
# Modified by rickk to allow configuration via (l)uci and play nicely with
99
# the standard sqm scripts without throwing all kinds of errors.
10-
#
10+
#
1111
# This script should be placed in your /usr/lib/sqm directory together with
1212
# nss-rk.qos.help.
1313
#
1414
# To use it, select fq_codel as a queue discipline in (l)uci and nss.qos
1515
# for the script.
1616
#
17-
# Works on my machine (R7800 with OpenWRT 22.03.3) certified.
17+
# Works on my machine (R7800 with OpenWRT master kernel 5.15) certified.
1818
#
1919
# Original can be found at https://github.com/rickkdotnet/sqm-scripts-nss
2020
#
@@ -24,6 +24,20 @@
2424

2525
################################################################################
2626

27+
# BAILOUT WHEN CALLED FROM HOTPLUG
28+
#
29+
# Restarting SQM from hotplug tends to crash the router on boot, probably because it quickly brings up, down and up again
30+
# the nssifb interface (it crashes on the last ip link up). Even worse when you have alias interfaces. Workaround that problem here.
31+
#
32+
# /etc/hotplug.d/iface/11-sqm reloads SQM whenever an interface (i.e: wan) associated with the device (i.e.: eth0)
33+
# changes state. This might be useful for dynamic interfaces, but with NSS you're always using a hardware interface
34+
# and it's no problem if the NSS SQM config remains in place during ifup/downs.
35+
36+
if [ ! -z ${ACTION} ] && [ ! -z ${INTERFACE} ] && [ ! -z ${DEVICE} ]; then
37+
sqm_warn "By the looks of the ENV vars it looks like hotplug has triggered us. This is not necessary, quitting script to prevent crashes."
38+
exit 0
39+
fi
40+
2741
# this is needed here for sqm_stop to find and delete the correct ifb interface
2842
CUR_IFB=nssifb
2943

@@ -48,6 +62,7 @@ else
4862
sqm_debug "Kernel version 5.10 found, will not delete nssifb on reload/stop"
4963
fi
5064

65+
5166
ipt_setup() {
5267

5368
# unfortunately, mangle doesn't work well with NSS, nor are tc filters implemented
@@ -78,8 +93,8 @@ egress() {
7893
sqm_debug "Uplink speed is below 100Mb, setting codel quantum to 300"
7994
EQUANTUM=300
8095
else
81-
# use the interface mtu, this seems to work well in almost all cases
82-
EQUANTUM=1514
96+
# use the interface mtu, this seems to work well in almost all cases
97+
EQUANTUM=1514
8398
fi
8499

85100
# this allows you to set the codel interval via (l)uci eqdisc_opts
@@ -161,6 +176,7 @@ sqm_prepare_script() {
161176
return 1
162177
fi
163178

179+
# nssifb does not like me doing this
164180
printf ${IFACE} > /sys/module/nss_ifb/parameters/nss_dev_name
165181

166182
# the default sqm-stop script deletes the nssifb interface
@@ -218,6 +234,7 @@ sqm_start() {
218234
# custom sqm_stop, because the standard function deletes the ifb which
219235
# causes nssifb to crash if the interface is recreated and enabled
220236
sqm_stop() {
237+
221238
if [ "${DOWNLINK}" -ne 0 ]; then
222239
$TC qdisc del dev $IFACE ingress
223240
$TC qdisc del dev $IFACE root
@@ -239,9 +256,9 @@ sqm_stop() {
239256
sqm_debug "${0}: Not deleting $CUR_IFB because variable DELETENSSIFB is not set"
240257
fi
241258

242-
# Under high load and reloading SQM nssifb tends to crash
243-
# sleep a little, hopefully this helps
244-
sleep 2
259+
# sleep a little, hopefully this prevents the system from crashing on restart of sqm
260+
sqm_debug "Sleeping for a second.. "
261+
sleep 1
245262

246263
return 0
247264
}

0 commit comments

Comments
 (0)