#!/bin/bash #tc qdisc show #echo -------------------- #rate in hundreds of bits per second. 50 actually gives around 5K/sec. rate="50" #burst size (bytes transferred before rate is controlled in kbytes burst="1000" #find out if we are in ip-up.d. if not, assume ip-down.d path="`pwd`/$0" action='shutdown' if [[ "$path" =~ "ip-up.d" ]]; then action='start' fi interface=$1 #case "${1}" in case $action in ("start") tc qdisc add dev $interface handle ffff: ingress sleep 1 tc filter add dev $interface parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate "$rate"kbit burst "$burst"k drop flowid :1 tc qdisc add dev $interface root tbf rate "$rate"kbit latency 50ms burst "$burst"k ;; ("shutdown") tc qdisc del dev $interface ingress tc qdisc del dev $interface root ;; (*) tc qdisc del dev $interface ingress tc qdisc del dev $interface root sleep 1 tc qdisc add dev $interface handle ffff: ingress sleep 1 tc filter add dev $interface parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate "$rate"kbit burst "$burst"k drop flowid :1 tc qdisc add dev $interface root tbf rate "$rate"kbit latency 50ms burst "$burst"k ;; esac