For the purposes of managing my bandwidth usage due to network restrictions, I made some software that dynamically ‘rate-limits’ to ensure that the bandwidth I used in a day could not exceed the limit I was allowed on the network.
It’s a combination of a kernel module and two userspace programs. The kernel module looks at every packet, determines whether it is local or not, and if it isn’t adds it to the total bandwidth usage (and destroys it if it is in excess of the limit). The userspace programs are a command line interface and a graphical user interface (you only use one), which manage the state over multiple boots of the machine (the kernel module resets at each boot) and set the total bandwidth limit appropriately.
Code is available at the repository.