#! /bin/sh EXT_IFACE=eth0 modprobe imq numdevs=1 # del the qdisc already loaded (if there) tc qdisc del dev imq0 root tc qdisc add dev imq0 handle 1: root htb default 12 r2q 1 # [ HTB queue ] # | # | # [256] (class 1:1) # / | \ # / | \ # / | \ # / | \ # / | \ # [64] [64] [128] (note: these add up the the parent's 256) # (1:10) (1:11) (1:12) # | | | # | | | # [sfq] [sfq] [sfq] # (20:0) (21:0) (22:0) # The main link: 252kbit (less is better) tc class add dev imq0 parent 1: classid 1:1 htb rate 254kbit # For 10.0.0.9 - 64kbit all to itself - Paul tc class add dev imq0 parent 1:1 classid 1:10 htb rate 20kbit burst 1kbit prio 1 ceil 36kbit # For 10.0.0.2 - 64kbit all to itself - Mark tc class add dev imq0 parent 1:1 classid 1:11 htb rate 20kbit burst 1kbit prio 1 ceil 60kbit # For 10.0.0.3 and 10.0.0.8 - 128kbit between them - Ryan - Mike tc class add dev imq0 parent 1:1 classid 1:12 htb rate 200kbit burst 10kbit prio 1 ceil 252kb it # SFQ makes things a bit fairer (in theory) tc qdisc add dev imq0 parent 1:10 handle 20:0 sfq tc qdisc add dev imq0 parent 1:11 handle 21:0 sfq tc qdisc add dev imq0 parent 1:12 handle 22:0 sfq # Match iptables mark 1 and send to class 1:10 (64kbit A) tc filter add dev imq0 protocol ip pref 1 parent 1: handle 1 fw classid 1:10 # Match iptables mark 2 and send to class 1:11 (64kbit B) tc filter add dev imq0 protocol ip pref 2 parent 1: handle 2 fw classid 1:11 # Match iptables mark 3 and send to class 1:12 (128kbit) tc filter add dev imq0 protocol ip pref 3 parent 1: handle 3 fw classid 1:12 # The IMQ device must be up before this will work... # ip link set imq0 up (set below) iptables -t mangle -F iptables -t mangle -X iptables -t mangle -N incoming iptables -t mangle -A incoming -d 10.0.0.9 -j MARK --set-mark 1 iptables -t mangle -A incoming -d 10.0.0.2 -j MARK --set-mark 2 iptables -t mangle -A incoming -m mark --mark 1 -j RETURN iptables -t mangle -A incoming -m mark --mark 2 -j RETURN iptables -t mangle -A incoming -j MARK --set-mark 3 iptables -t mangle -A FORWARD -i $EXT_IFACE -j incoming iptables -t mangle -A FORWARD -i $EXT_IFACE -j IMQ ip link set imq0 up tc -s -d class show dev imq0