esac
+saved_bw_rx="$(tc qdisc show dev "${IFACE_RX}" | awk '{if($2 == "cake" && $7 == "bandwidth"){print $8; exit}} END{print "undef"}' | head -n1)"
+case "${saved_bw_rx}" in
+ [0-9]*)
+ :
+ ;;
+ undef)
+ printf 'FATAL: Could not determine current bw cap for cake SQM on "%s"\n' "${IFACE_RX}" >&2
+ exit 1
+ ;;
+ *)
+ printf 'FATAL: Unexpected value retrieved from `tc` for cake SQM RX bandwidth on "%s"\n' "${IFACE_RX}" >&2
+ exit 1
+ ;;
+esac
+
+
+saved_bw_tx="$(tc qdisc show dev "${IFACE_TX}" | awk '{if($2 == "cake" && $7 == "bandwidth"){print $8; exit}} END{print "undef"}' | head -n1)"
+case "${saved_bw_tx}" in
+ [0-9]*)
+ :
+ ;;
+ undef)
+ printf 'FATAL: Could not determine current bw cap for cake SQM on "%s"\n' "${IFACE_TX}" >&2
+ exit 1
+ ;;
+ *)
+ printf 'FATAL: Unexpected value retrieved from `tc` for cake SQM TX bandwidth on "%s"\n' "${IFACE_TX}" >&2
+ exit 1
+ ;;
+esac
+
+
+_restore_saved_bw() {
+ echo 'Restoring saved bandwith limits...' >&2
+ (
+ set -x
+ tc qdisc change root dev "${IFACE_RX}" cake bandwidth "${saved_bw_rx}"
+ tc qdisc change root dev "${IFACE_TX}" cake bandwidth "${saved_bw_tx}"
+ )
+}
+
+
set -u
trap ':' SIGINT SIGTERM
-v PING_PEERS="${PING_PEERS}" \
-f ./__sqm_lagthrottle.awk
-echo 'exiting - cleanup...' >&2
+echo 'Control loop exited - performing cleanup...' >&2
+_restore_saved_bw
+echo 'sqm_lagthrottle.sh has terminated.' >&2