From 99bb12d07fe4c2e7b6b4425aabc03f3b6ff2a372 Mon Sep 17 00:00:00 2001 From: Johannes Truschnigg Date: Sat, 3 Sep 2022 19:14:44 +0200 Subject: [PATCH] Restore previously set bandwidth limits upon exit --- sqm_lagthrottle.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/sqm_lagthrottle.sh b/sqm_lagthrottle.sh index 4ee6558..2c756e7 100755 --- a/sqm_lagthrottle.sh +++ b/sqm_lagthrottle.sh @@ -222,6 +222,48 @@ case "${TREND_DECISION}" in 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 @@ -242,4 +284,6 @@ fping --loop --retry=1 --size=1280 --period="${PING_INTERVAL}" --random ${PING_P -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 -- 2.39.5