#!/bin/sh #TOPRATE=872kbit #echo "Don't run this script now." #exit 1 TOPRATE=10Mbit case ${MODE:-$1} in start) echo Starting traffic control for ${IFACE:=$2} # Top-level queue for interface; hierarchical token bucket. # TBF doesn't support classes, so I can't put a full qdisc in it. tc qdisc add dev $IFACE root handle 1: htb default 10 # Root rate queue. This one defines our output capacity. tc class add dev $IFACE parent 1: classid 1:1 htb rate $TOPRATE # Default rate queue tc class add dev $IFACE parent 1:1 classid 1:10 htb rate 3Mbit ceil $TOPRATE burst 15k prio 2 # High-priority rate queue tc class add dev $IFACE parent 1:1 classid 1:20 htb rate 7Mbit ceil $TOPRATE burst 15k prio 1 # Stochastic fairness queuing, limited by above rates. tc qdisc add dev $IFACE parent 1:10 handle 10: sfq perturb 10 tc qdisc add dev $IFACE parent 1:20 handle 20: sfq perturb 10 # Filters to sort out high-priority packets ## match acks the hard way, ## IP protocol 6, ## IP header length 0x5(32 bit words), ## IP Total length 0x34 (ACK + 12 bytes of TCP options) ## TCP ack set (bit 5, offset 33) #tc filter add dev $IFACE parent 1: protocol ip u32 \ # match ip protocol 6 0xff \ # match u8 0x05 0x0f at 0 \ # match u16 0x0000 0xffc0 at 2 \ # match u8 0x10 0xff at 33 \ # flowid 1:20 # ICMP or UDP traffic #tc filter add dev $IFACE parent 1: protocol ip u32 \ # match ip protocol 1 0xef flowid 1:20 # Let iptables mark the packets for high priority. tc filter add dev $IFACE parent 1: protocol ip handle 1 fw classid 1:20 ;; stop) echo Stopping traffic control for ${IFACE:=$2} tc qdisc del dev $IFACE root ;; *) echo Usage: $0 {start,stop} interface ;; esac