47 lines
1.2 KiB
Bash
Executable file
47 lines
1.2 KiB
Bash
Executable file
#!/bin/sh
|
|
# left4me — apply or clear CAKE egress shaper on the configured uplink.
|
|
# Driven by left4me-cake.service. See spec
|
|
# docs/superpowers/specs/2026-05-10-l4d2-network-shaping-design.md.
|
|
set -eu
|
|
|
|
mode=${1:-apply}
|
|
|
|
if [ -r /etc/left4me/cake.env ]; then
|
|
. /etc/left4me/cake.env
|
|
fi
|
|
|
|
resolve_iface() {
|
|
if [ -n "${LEFT4ME_UPLINK_IFACE:-}" ]; then
|
|
printf '%s' "$LEFT4ME_UPLINK_IFACE"
|
|
return
|
|
fi
|
|
ip -4 route show default | awk '/default/ {print $5; exit}'
|
|
}
|
|
|
|
case "$mode" in
|
|
apply)
|
|
if [ -z "${LEFT4ME_UPLINK_MBIT:-}" ]; then
|
|
echo "left4me-cake: LEFT4ME_UPLINK_MBIT unset; skipping shaper" >&2
|
|
exit 0
|
|
fi
|
|
iface=$(resolve_iface)
|
|
if [ -z "$iface" ]; then
|
|
echo "left4me-cake: cannot determine egress iface; skipping" >&2
|
|
exit 0
|
|
fi
|
|
exec tc qdisc replace dev "$iface" root cake \
|
|
bandwidth "${LEFT4ME_UPLINK_MBIT}mbit" \
|
|
internet diffserv4 dual-dsthost
|
|
;;
|
|
clear)
|
|
iface=$(resolve_iface)
|
|
if [ -z "$iface" ]; then
|
|
exit 0
|
|
fi
|
|
tc qdisc del dev "$iface" root 2>/dev/null || true
|
|
;;
|
|
*)
|
|
echo "usage: $0 [apply|clear]" >&2
|
|
exit 2
|
|
;;
|
|
esac
|