#!/bin/bash # Keeps voice smooth on the Chromebook's slow upload (about 0.9 Mbit/s). # Without this, one picture upload fills the router's queue and voice packets wait behind it: latency to Discord went # from 39 ms to 450-785 ms while a 664 KB GIF uploaded. This caps internet-bound traffic just under the line's speed so # the queue stays here, where fq_codel lets small flows like voice go first. Traffic to the home network isn't capped. # # shape-upload.sh turn it on # shape-upload.sh off turn it off # shape-upload.sh install turn it on now and at every boot # # It turns itself off again after 2 minutes unless `keep` is the second word, so a mistake can't lock anyone out. set -eu DEV=wlan0 RATE=800kbit off() { tc qdisc del dev "$DEV" root 2>/dev/null || true; } on() { off tc qdisc add dev "$DEV" root handle 1: htb default 20 tc class add dev "$DEV" parent 1: classid 1:1 htb rate 100mbit tc class add dev "$DEV" parent 1:1 classid 1:10 htb rate 90mbit ceil 100mbit tc class add dev "$DEV" parent 1:1 classid 1:20 htb rate "$RATE" ceil "$RATE" tc qdisc add dev "$DEV" parent 1:10 fq_codel tc qdisc add dev "$DEV" parent 1:20 fq_codel tc filter add dev "$DEV" parent 1: protocol ip prio 1 u32 match ip dst 192.168.0.0/16 flowid 1:10 tc filter add dev "$DEV" parent 1: protocol ipv6 prio 2 u32 match ip6 dst fe80::/10 flowid 1:10 } case "${1:-on}" in stop) off # what the service runs at shutdown: it must stay enabled for the next boot ;; off) off systemctl disable --now dezio-shape.service 2>/dev/null || true echo "Upload shaping is off" ;; install) install -m 755 "$0" /usr/local/bin/dezio-shape cat > /etc/systemd/system/dezio-shape.service </dev/null 2>&1 & echo "Upload shaping is on for 2 minutes as a test" fi ;; esac