Based on this section of the Linux Advanced Routing & Traffic Control HOWTO, I can't get tc to limit the network speed in my computer.
The router is a Motorola SurfBoard modem with a few routing capabilities and firewall. The machine I want to limit the traffic is 192.168.0.5, and also the script is being run from 192.168.0.5.
Here is my adaption of the commands on the link above for /etc/NetworkManager/dispatcher.d/:
#!/bin/sh -eu
# clear any previous queuing disciplines (qdisc)
tc qdisc del dev wlan0 root 2>/dev/null ||:
# add a cbq qdisc; see `man tc-cbq' for details
if [ $2 = up ]; then
# set to a 3mbit interface for more precise calculations
tc qdisc add dev wlan0 root handle 1: cbq avpkt 1000 \
bandwidth 3mbit
# leave 30KB (240kbps) to other machines in the network
tc class add dev wlan0 parent 1: classid 1:1 cbq \
rate 2832kbit allot 1500 prio 5 bounded isolated
# redirect all traffic on 192.168.0.5 to the previous class
tc filter add dev wlan0 parent 1: protocol ip prio 16 \
u32 match ip dst 192.168.0.5 flowid 1:1
# change the hashing algorithm every 10s to avoid collisions
tc qdisc add dev wlan0 parent 1:1 sfq perturb 10
fi
The problem is that I have tried setting 2832kbit to very small values for testing (like 16kbit), but I still can browse the web at high speed. The problem is not in NetworkManager, because I'm testing the script manually.
EDIT: I have found that by changing dst 192.168.0.5 to src 192.168.0.5, the upload speed is reliably limited, but I still haven't figured how to get the download speed to work, which is the most important for me.